use of com.z.gateway.common.OpenApiHttpRequestBean in project gateway-dubbox by zhuzhong.
the class OpenApiReqHandler method doExcuteBiz.
// step2
@Override
public boolean doExcuteBiz(Context context) {
OpenApiContext openApiContext = (OpenApiContext) context;
OpenApiHttpSessionBean httpSessionBean = (OpenApiHttpSessionBean) openApiContext.getOpenApiHttpSessionBean();
OpenApiHttpRequestBean request = httpSessionBean.getRequest();
long currentTime = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.info(String.format("begin run doExecuteBiz,currentTime=%d,httpSessonBean=%s", currentTime, httpSessionBean));
}
String routeBeanKey = request.getRouteBeanKey();
OpenApiRouteBean routeBean = (OpenApiRouteBean) cacheService.get(routeBeanKey);
// 返回值
routeBean.setServiceRsp(doInvokeBackService(routeBean));
if (logger.isDebugEnabled()) {
logger.info(String.format("end run doExecuteBiz,currentTime=%d,elapase_time=%d milseconds,httpSessonBean=%s", System.currentTimeMillis(), (System.currentTimeMillis() - currentTime), httpSessionBean));
}
return false;
}
use of com.z.gateway.common.OpenApiHttpRequestBean in project gateway-dubbox by zhuzhong.
the class AsynOpenApiAcceptHandlerImpl method acceptRequest.
@Override
public void acceptRequest(HttpServletRequest request, HttpServletResponse response) {
final AsyncContext context = request.startAsync(request, response);
taskExecutor.submit(new Runnable() {
@Override
public void run() {
try {
HttpServletRequest asynRequest = (HttpServletRequest) context.getRequest();
OpenApiHttpRequestBean reqBean = (OpenApiHttpRequestBean) asynRequest.getAttribute(CommonCodeConstants.REQ_BEAN_KEY);
String traceId = idService.genInnerRequestId();
reqBean.setTraceId(traceId);
// 重新设置bean
asynRequest.setAttribute(CommonCodeConstants.REQ_BEAN_KEY, reqBean);
if (logger.isInfoEnabled()) {
logger.info(String.format("requestId=%s request begin,reqeust=%s", traceId, JSON.toJSONString(reqBean)));
}
OpenApiHttpSessionBean sessionBean = new OpenApiHttpSessionBean(reqBean);
String operationType = sessionBean.getRequest().getOperationType();
OpenApiHandlerExecuteTemplate handlerExecuteTemplate = applicationContext.getBean(operationType, OpenApiHandlerExecuteTemplate.class);
OpenApiContext openApiContext = new OpenApiContext();
openApiContext.setOpenApiHttpSessionBean(sessionBean);
try {
handlerExecuteTemplate.execute(openApiContext);
} catch (Exception e) {
e.printStackTrace();
}
// 写入响应
OpenApiResponseUtils.writeRsp((HttpServletResponse) context.getResponse(), sessionBean.getRequest());
} finally {
context.complete();
}
}
});
}
use of com.z.gateway.common.OpenApiHttpRequestBean in project gateway-dubbox by zhuzhong.
the class OpenApiServiceParamValidateInterceptor method iniOpenApiHttpRequestBean.
/**
* 根据请求的协议进行解析
*/
@Override
protected OpenApiHttpRequestBean iniOpenApiHttpRequestBean(HttpServletRequest request) {
String requestMethod = request.getMethod();
OpenApiHttpRequestBean bean = new OpenApiHttpRequestBean();
if (requestMethod.equalsIgnoreCase(CommonCodeConstants.REQUEST_METHOD.POST.name())) {
try {
parsePostMethod(request, bean);
} catch (IOException e) {
log.error("这个请求格式不是application/json的,我处理不了...");
e.printStackTrace();
throw new RuntimeException(e);
}
} else if (requestMethod.equalsIgnoreCase(CommonCodeConstants.REQUEST_METHOD.GET.name())) {
parseGetMethod(request, bean);
bean.setQueryString(request.getQueryString());
}
bean.setThdApiUrlParams(extractThdUrlParams(request));
bean.setLocalAddr(request.getLocalAddr());
bean.setLocalPort(request.getLocalPort());
bean.setClientAddr(NetworkUtil.getClientIpAddr(request));
// 获取请求头
bean.setReqHeader(getHeadersInfo(request));
if (request.getContentType() != null)
bean.getReqHeader().put("content-type", request.getContentType());
bean.setOperationType(CommonCodeConstants.API_SERVICE_KEY);
bean.setRequestMethod(requestMethod);
if (bean.getSignMethod() == null)
bean.setSignMethod("MD5");
if (bean.getFormat() == null)
bean.setFormat("json");
return bean;
}
use of com.z.gateway.common.OpenApiHttpRequestBean in project gateway-dubbox by zhuzhong.
the class OpenApiReqAdapter method doExcuteBiz.
@Override
public boolean doExcuteBiz(Context context) {
OpenApiContext openApiContext = (OpenApiContext) context;
OpenApiHttpSessionBean httpSessionBean = (OpenApiHttpSessionBean) openApiContext.getOpenApiHttpSessionBean();
OpenApiHttpRequestBean request = httpSessionBean.getRequest();
long currentTime = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.info(String.format("begin run doExecuteBiz,currentTime=%d,httpSessonBean=%s", currentTime, httpSessionBean));
}
// 参数校验
validateParam(request);
// 权限校验
authRequestBean(request);
// 初始化路由bean
initRouteBean(httpSessionBean.getRequest());
if (logger.isDebugEnabled()) {
logger.info(String.format("end run doExecuteBiz,currentTime=%d,elapase_time=%d milseconds,httpSessonBean=%s", System.currentTimeMillis(), (System.currentTimeMillis() - currentTime), httpSessionBean));
}
if (StringUtils.isNotBlank(request.getPrintStr())) {
return true;
}
return false;
}
use of com.z.gateway.common.OpenApiHttpRequestBean in project gateway-dubbox by zhuzhong.
the class OpenApiRspHandler method doExcuteBiz.
/*
* @Override public boolean execute(Context context) {
* logger.info("step1----"); return doExcuteBiz(context); }
*/
@Override
public boolean doExcuteBiz(Context context) {
logger.info("step2----");
OpenApiContext blCtx = (OpenApiContext) context;
OpenApiHttpSessionBean httpSessionBean = (OpenApiHttpSessionBean) blCtx.getOpenApiHttpSessionBean();
OpenApiHttpRequestBean request = httpSessionBean.getRequest();
long currentTime = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.info(String.format("begin run doExecuteBiz,currentTime=%d,httpSessonBean=%s", currentTime, httpSessionBean));
}
String printStr = this.executePrint(request);
request.setPrintStr(printStr);
if (logger.isDebugEnabled()) {
logger.info(String.format("end run doExecuteBiz,currentTime=%d,elapase_time=%d milseconds,httpSessonBean=%s", System.currentTimeMillis(), (System.currentTimeMillis() - currentTime), httpSessionBean));
}
return false;
}
Aggregations