|
|
@@ -13,14 +13,17 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* rest api
|
|
|
* Created by wuxw on 2018/10/16.
|
|
|
*/
|
|
|
@@ -29,167 +32,174 @@ import java.util.Map;
|
|
|
@Api(value = "对外统一提供服务接口服务")
|
|
|
public class RestApi extends BaseController {
|
|
|
|
|
|
- private final static Logger logger = LoggerFactory.getLogger(RestApi.class);
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(RestApi.class);
|
|
|
@Autowired
|
|
|
private IApiServiceSMO apiServiceSMOImpl;
|
|
|
|
|
|
@Autowired
|
|
|
private IUserInnerServiceSMO userInnerServiceSMOImpl;
|
|
|
+
|
|
|
/**
|
|
|
* 健康检查 服务
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- @RequestMapping(path = "/health",method = RequestMethod.GET)
|
|
|
- @ApiOperation(value="服务健康检查", notes="test: 返回 2XX 表示服务正常")
|
|
|
- public String health(){
|
|
|
+ @RequestMapping(path = "/health", method = RequestMethod.GET)
|
|
|
+ @ApiOperation(value = "服务健康检查", notes = "test: 返回 2XX 表示服务正常")
|
|
|
+ public String health() {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 健康检查 服务
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- @RequestMapping(path = "/checkUserServiceVersion",method = RequestMethod.GET)
|
|
|
- @ApiOperation(value="检查用服务版本", notes="test: 返回 2XX 表示服务正常")
|
|
|
- public String checkUserServiceVersion(){
|
|
|
+ @RequestMapping(path = "/checkUserServiceVersion", method = RequestMethod.GET)
|
|
|
+ @ApiOperation(value = "检查用服务版本", notes = "test: 返回 2XX 表示服务正常")
|
|
|
+ public String checkUserServiceVersion() {
|
|
|
return userInnerServiceSMOImpl.getUserServiceVersion("test");
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 资源请求 post方式
|
|
|
- * @param service 请求接口方式
|
|
|
+ *
|
|
|
+ * @param service 请求接口方式
|
|
|
* @param postInfo post内容
|
|
|
- * @param request 请求对象 查询头信息 url等信息
|
|
|
+ * @param request 请求对象 查询头信息 url等信息
|
|
|
* @return http status 200 成功 其他失败
|
|
|
*/
|
|
|
|
|
|
- @RequestMapping(path = "/{service:.+}",method = RequestMethod.POST )
|
|
|
- @ApiOperation(value="资源post请求", notes="test: 返回 2XX 表示服务正常")
|
|
|
- @ApiImplicitParam(paramType="query", name = "service", value = "用户编号", required = true, dataType = "String")
|
|
|
+ @RequestMapping(path = "/{service:.+}", method = RequestMethod.POST)
|
|
|
+ @ApiOperation(value = "资源post请求", notes = "test: 返回 2XX 表示服务正常")
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "service", value = "用户编号", required = true, dataType = "String")
|
|
|
public ResponseEntity<String> servicePost(@PathVariable String service,
|
|
|
@RequestBody String postInfo,
|
|
|
- HttpServletRequest request){
|
|
|
+ HttpServletRequest request) {
|
|
|
ResponseEntity<String> responseEntity = null;
|
|
|
try {
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
this.getRequestInfo(request, headers);
|
|
|
- headers.put(CommonConstant.HTTP_SERVICE,service);
|
|
|
- headers.put(CommonConstant.HTTP_METHOD,CommonConstant.HTTP_METHOD_POST);
|
|
|
- logger.debug("api:{} 请求报文为:{},header信息为:{}",service,postInfo,headers);
|
|
|
- responseEntity = apiServiceSMOImpl.service(postInfo,headers);
|
|
|
- }catch (Throwable e){
|
|
|
- logger.error("请求post 方法["+service+"]失败:"+postInfo,e);
|
|
|
- responseEntity = new ResponseEntity<String>("请求发生异常,"+e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ headers.put(CommonConstant.HTTP_SERVICE, service);
|
|
|
+ headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_POST);
|
|
|
+ logger.debug("api:{} 请求报文为:{},header信息为:{}", service, postInfo, headers);
|
|
|
+ responseEntity = apiServiceSMOImpl.service(postInfo, headers);
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.error("请求post 方法[" + service + "]失败:" + postInfo, e);
|
|
|
+ responseEntity = new ResponseEntity<String>("请求发生异常," + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
}
|
|
|
- logger.debug("api:{} 返回信息为:{}",service,responseEntity);
|
|
|
+ logger.debug("api:{} 返回信息为:{}", service, responseEntity);
|
|
|
|
|
|
return responseEntity;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 资源请求 get方式
|
|
|
+ *
|
|
|
* @param service 请求接口方式
|
|
|
* @param request 请求对象 查询头信息 url等信息
|
|
|
* @return http status 200 成功 其他失败
|
|
|
*/
|
|
|
|
|
|
- @RequestMapping(path = "/{service:.+}",method = RequestMethod.GET )
|
|
|
- @ApiOperation(value="资源get请求", notes="test: 返回 2XX 表示服务正常")
|
|
|
- @ApiImplicitParam(paramType="query", name = "service", value = "用户编号", required = true, dataType = "String")
|
|
|
+ @RequestMapping(path = "/{service:.+}", method = RequestMethod.GET)
|
|
|
+ @ApiOperation(value = "资源get请求", notes = "test: 返回 2XX 表示服务正常")
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "service", value = "用户编号", required = true, dataType = "String")
|
|
|
public ResponseEntity<String> serviceGet(@PathVariable String service,
|
|
|
- HttpServletRequest request){
|
|
|
+ HttpServletRequest request) {
|
|
|
ResponseEntity<String> responseEntity = null;
|
|
|
try {
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
this.getRequestInfo(request, headers);
|
|
|
- headers.put(CommonConstant.HTTP_SERVICE,service);
|
|
|
- headers.put(CommonConstant.HTTP_METHOD,CommonConstant.HTTP_METHOD_GET);
|
|
|
- logger.debug("api:{} 请求报文为:{},header信息为:{}","",headers);
|
|
|
- responseEntity = apiServiceSMOImpl.service(JSONObject.toJSONString(getParameterStringMap(request)),headers);
|
|
|
- }catch (Throwable e){
|
|
|
- logger.error("请求get 方法["+service+"]失败:",e);
|
|
|
- responseEntity = new ResponseEntity<String>("请求发生异常,"+e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ headers.put(CommonConstant.HTTP_SERVICE, service);
|
|
|
+ headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_GET);
|
|
|
+ logger.debug("api:{} 请求报文为:{},header信息为:{}", "", headers);
|
|
|
+ responseEntity = apiServiceSMOImpl.service(JSONObject.toJSONString(getParameterStringMap(request)), headers);
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.error("请求get 方法[" + service + "]失败:", e);
|
|
|
+ responseEntity = new ResponseEntity<String>("请求发生异常," + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
}
|
|
|
- logger.debug("api:{} 返回信息为:{}",service,responseEntity);
|
|
|
+ logger.debug("api:{} 返回信息为:{}", service, responseEntity);
|
|
|
|
|
|
return responseEntity;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 资源请求 put方式
|
|
|
- * @param service 请求接口方式
|
|
|
+ *
|
|
|
+ * @param service 请求接口方式
|
|
|
* @param postInfo 修改内容
|
|
|
- * @param request 请求对象 查询头信息 url等信息
|
|
|
+ * @param request 请求对象 查询头信息 url等信息
|
|
|
* @return http status 200 成功 其他失败
|
|
|
*/
|
|
|
|
|
|
- @RequestMapping(path = "/{service:.+}",method = RequestMethod.PUT )
|
|
|
- @ApiOperation(value="资源put请求", notes="test: 返回 2XX 表示服务正常")
|
|
|
- @ApiImplicitParam(paramType="query", name = "service", value = "用户编号", required = true, dataType = "String")
|
|
|
+ @RequestMapping(path = "/{service:.+}", method = RequestMethod.PUT)
|
|
|
+ @ApiOperation(value = "资源put请求", notes = "test: 返回 2XX 表示服务正常")
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "service", value = "用户编号", required = true, dataType = "String")
|
|
|
public ResponseEntity<String> servicePut(@PathVariable String service,
|
|
|
@RequestBody String postInfo,
|
|
|
- HttpServletRequest request){
|
|
|
+ HttpServletRequest request) {
|
|
|
ResponseEntity<String> responseEntity = null;
|
|
|
try {
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
this.getRequestInfo(request, headers);
|
|
|
- headers.put(CommonConstant.HTTP_SERVICE,service);
|
|
|
- headers.put(CommonConstant.HTTP_METHOD,CommonConstant.HTTP_METHOD_PUT);
|
|
|
- logger.debug("api:{} 请求报文为:{},header信息为:{}",service,postInfo,headers);
|
|
|
- responseEntity = apiServiceSMOImpl.service(postInfo,headers);
|
|
|
- }catch (Throwable e){
|
|
|
- logger.error("请求put 方法["+service+"]失败:",e);
|
|
|
- responseEntity = new ResponseEntity<String>("请求发生异常,"+e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ headers.put(CommonConstant.HTTP_SERVICE, service);
|
|
|
+ headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_PUT);
|
|
|
+ logger.debug("api:{} 请求报文为:{},header信息为:{}", service, postInfo, headers);
|
|
|
+ responseEntity = apiServiceSMOImpl.service(postInfo, headers);
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.error("请求put 方法[" + service + "]失败:", e);
|
|
|
+ responseEntity = new ResponseEntity<String>("请求发生异常," + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
}
|
|
|
- logger.debug("api:{} 返回信息为:{}",service,responseEntity);
|
|
|
+ logger.debug("api:{} 返回信息为:{}", service, responseEntity);
|
|
|
return responseEntity;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 资源请求 delete方式
|
|
|
+ *
|
|
|
* @param service 请求接口方式
|
|
|
* @param request 请求对象 查询头信息 url等信息
|
|
|
* @return http status 200 成功 其他失败
|
|
|
*/
|
|
|
|
|
|
- @RequestMapping(path = "/{service:.+}",method = RequestMethod.DELETE )
|
|
|
- @ApiOperation(value="资源delete请求", notes="test: 返回 2XX 表示服务正常")
|
|
|
- @ApiImplicitParam(paramType="query", name = "service", value = "用户编号", required = true, dataType = "String")
|
|
|
+ @RequestMapping(path = "/{service:.+}", method = RequestMethod.DELETE)
|
|
|
+ @ApiOperation(value = "资源delete请求", notes = "test: 返回 2XX 表示服务正常")
|
|
|
+ @ApiImplicitParam(paramType = "query", name = "service", value = "用户编号", required = true, dataType = "String")
|
|
|
public ResponseEntity<String> serviceDelete(@PathVariable String service,
|
|
|
- HttpServletRequest request){
|
|
|
+ HttpServletRequest request) {
|
|
|
ResponseEntity<String> responseEntity = null;
|
|
|
try {
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
this.getRequestInfo(request, headers);
|
|
|
- headers.put(CommonConstant.HTTP_SERVICE,service);
|
|
|
- headers.put(CommonConstant.HTTP_METHOD,CommonConstant.HTTP_METHOD_DELETE);
|
|
|
- logger.debug("api:{} 请求报文为:{},header信息为:{}",service,"",headers);
|
|
|
-
|
|
|
- responseEntity = apiServiceSMOImpl.service(JSONObject.toJSONString(getParameterStringMap(request)),headers);
|
|
|
- }catch (Throwable e){
|
|
|
- logger.error("请求delete 方法["+service+"]失败:",e);
|
|
|
- responseEntity = new ResponseEntity<String>("请求发生异常,"+e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ headers.put(CommonConstant.HTTP_SERVICE, service);
|
|
|
+ headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_DELETE);
|
|
|
+ logger.debug("api:{} 请求报文为:{},header信息为:{}", service, "", headers);
|
|
|
+
|
|
|
+ responseEntity = apiServiceSMOImpl.service(JSONObject.toJSONString(getParameterStringMap(request)), headers);
|
|
|
+ } catch (Throwable e) {
|
|
|
+ logger.error("请求delete 方法[" + service + "]失败:", e);
|
|
|
+ responseEntity = new ResponseEntity<String>("请求发生异常," + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
}
|
|
|
|
|
|
- logger.debug("api:{} 返回信息为:{}",service,responseEntity);
|
|
|
+ logger.debug("api:{} 返回信息为:{}", service, responseEntity);
|
|
|
return responseEntity;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取请求信息
|
|
|
+ *
|
|
|
* @param request
|
|
|
* @param headers
|
|
|
* @throws RuntimeException
|
|
|
*/
|
|
|
- private void getRequestInfo(HttpServletRequest request,Map headers) throws Exception{
|
|
|
- try{
|
|
|
- super.initHeadParam(request,headers);
|
|
|
- super.initUrlParam(request,headers);
|
|
|
- }catch (Exception e){
|
|
|
- logger.error("加载头信息失败",e);
|
|
|
+ private void getRequestInfo(HttpServletRequest request, Map headers) throws Exception {
|
|
|
+ try {
|
|
|
+ super.initHeadParam(request, headers);
|
|
|
+ super.initUrlParam(request, headers);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("加载头信息失败", e);
|
|
|
throw e;
|
|
|
}
|
|
|
}
|