forked from freakchick/DBApi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39c9e45
commit fdbf585
Showing
5 changed files
with
146 additions
and
99 deletions.
There are no files selected for viewing
83 changes: 48 additions & 35 deletions
83
...er-apiServer/src/main/java/com/gitee/freakchicken/dbapi/apiserver/conf/ServletConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,48 @@ | ||
package com.gitee.freakchicken.dbapi.apiserver.conf; | ||
|
||
import com.gitee.freakchicken.dbapi.basic.servlet.APIServlet; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @description: | ||
* @program: dbApi | ||
* @author: kensan | ||
* @create: 2022-04-16 12:45 | ||
*/ | ||
@Slf4j | ||
@Configuration | ||
public class ServletConfig { | ||
@Value("${dbapi.api.context}") | ||
String apiContext; | ||
|
||
@Autowired | ||
private APIServlet apiServlet; | ||
|
||
@Bean | ||
public ServletRegistrationBean getServletRegistrationBean() { | ||
String format = String.format("/%s/*", apiContext); | ||
ServletRegistrationBean bean = new ServletRegistrationBean(apiServlet); | ||
bean.addUrlMappings(format); | ||
log.info("regist APIServlet servelet for {} urlMappings",format); | ||
return bean; | ||
} | ||
} | ||
package com.gitee.freakchicken.dbapi.apiserver.conf; | ||
|
||
import com.gitee.freakchicken.dbapi.basic.servlet.APIServlet; | ||
import com.gitee.freakchicken.dbapi.basic.servlet.TokenServlet; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @description: | ||
* @program: dbApi | ||
* @author: kensan | ||
* @create: 2022-04-16 12:45 | ||
*/ | ||
@Slf4j | ||
@Configuration | ||
public class ServletConfig { | ||
@Value("${dbapi.api.context}") | ||
String apiContext; | ||
|
||
@Autowired | ||
private APIServlet apiServlet; | ||
|
||
@Autowired | ||
private TokenServlet tokenServlet; | ||
|
||
|
||
@Bean | ||
public ServletRegistrationBean getServletRegistrationBean() { | ||
String format = String.format("/%s/*", apiContext); | ||
ServletRegistrationBean bean = new ServletRegistrationBean(apiServlet); | ||
bean.addUrlMappings(format); | ||
log.info("regist APIServlet servelet for {} urlMappings",format); | ||
return bean; | ||
} | ||
|
||
@Bean | ||
public ServletRegistrationBean tokenServletRegistrationBean() { | ||
ServletRegistrationBean bean = new ServletRegistrationBean(tokenServlet); | ||
bean.addUrlMappings("/token/generate"); | ||
log.info("regist tokenServlet servelet"); | ||
return bean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
...oller/src/main/java/com/gitee/freakchicken/dbapi/basic/controller/AppTokenController.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
dbapi-service/src/main/java/com/gitee/freakchicken/dbapi/basic/servlet/TokenServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.gitee.freakchicken.dbapi.basic.servlet; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.gitee.freakchicken.dbapi.basic.domain.AppToken; | ||
import com.gitee.freakchicken.dbapi.basic.service.AppTokenService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.PrintWriter; | ||
|
||
@Slf4j | ||
@Component | ||
public class TokenServlet extends HttpServlet { | ||
|
||
@Autowired | ||
private AppTokenService tokenService; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) { | ||
String appid = request.getParameter("appid"); | ||
String secret = request.getParameter("secret"); | ||
|
||
AppToken token = tokenService.generateToken(appid, secret); | ||
PrintWriter out = null; | ||
try { | ||
out = response.getWriter(); | ||
out.append(JSON.toJSONString(token)); | ||
|
||
} catch (Exception e) { | ||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | ||
// out.append(JSON.toJSONString(ResponseDto.fail(e.toString()))); | ||
log.error(e.toString(), e); | ||
} finally { | ||
if (out != null) | ||
out.close(); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) { | ||
doGet(req, resp); | ||
} | ||
} |
80 changes: 46 additions & 34 deletions
80
dbapi-standalone/src/main/java/com/gitee/freakchicken/dbapi/conf/ServletConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,46 @@ | ||
package com.gitee.freakchicken.dbapi.conf; | ||
|
||
import com.gitee.freakchicken.dbapi.basic.servlet.APIServlet; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @description: | ||
* @program: dbApi | ||
* @author: kensan | ||
* @create: 2022-04-16 12:45 | ||
*/ | ||
@Slf4j | ||
@Configuration | ||
public class ServletConfig { | ||
@Value("${dbapi.api.context}") | ||
private String apiContext; | ||
|
||
@Autowired | ||
private APIServlet apiServlet; | ||
|
||
@Bean | ||
public ServletRegistrationBean getServletRegistrationBean() { | ||
String format = String.format("/%s/*", apiContext); | ||
ServletRegistrationBean bean = new ServletRegistrationBean(apiServlet); | ||
bean.addUrlMappings(format); | ||
log.info("regist APIServlet servelet for {} urlMappings",format); | ||
return bean; | ||
} | ||
} | ||
package com.gitee.freakchicken.dbapi.conf; | ||
|
||
import com.gitee.freakchicken.dbapi.basic.servlet.APIServlet; | ||
import com.gitee.freakchicken.dbapi.basic.servlet.TokenServlet; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @description: | ||
* @program: dbApi | ||
* @author: kensan | ||
* @create: 2022-04-16 12:45 | ||
*/ | ||
@Slf4j | ||
@Configuration | ||
public class ServletConfig { | ||
@Value("${dbapi.api.context}") | ||
private String apiContext; | ||
|
||
@Autowired | ||
private APIServlet apiServlet; | ||
|
||
@Autowired | ||
private TokenServlet tokenServlet; | ||
|
||
@Bean | ||
public ServletRegistrationBean getServletRegistrationBean() { | ||
String format = String.format("/%s/*", apiContext); | ||
ServletRegistrationBean bean = new ServletRegistrationBean(apiServlet); | ||
bean.addUrlMappings(format); | ||
log.info("regist APIServlet servelet for {} urlMappings",format); | ||
return bean; | ||
} | ||
|
||
@Bean | ||
public ServletRegistrationBean tokenServletRegistrationBean() { | ||
ServletRegistrationBean bean = new ServletRegistrationBean(tokenServlet); | ||
bean.addUrlMappings("/token/generate"); | ||
log.info("regist tokenServlet servelet "); | ||
return bean; | ||
} | ||
} |