use of com.z.gateway.protocol.OpenApiHttpSessionBean 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.protocol.OpenApiHttpSessionBean 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.protocol.OpenApiHttpSessionBean 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.protocol.OpenApiHttpSessionBean 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;
}
use of com.z.gateway.protocol.OpenApiHttpSessionBean in project gateway-dubbox by zhuzhong.
the class ThreadPoolHandlerImpl method addTask.
@Override
public Object addTask(AbstractTask task) {
try {
FutureTask<OpenApiHttpSessionBean> tsFutre = new FutureTask<OpenApiHttpSessionBean>(task);
taskExecutor.execute(tsFutre);
while (!tsFutre.isDone()) {
/*
* try { // logger.debug("waitting for result");
* TimeUnit.MICROSECONDS.sleep(200); } catch
* (InterruptedException e) { logger.error(String.format(
* "exception happend on executing task with ",
* e.getMessage())); }
*/
}
return tsFutre.get();
} catch (TaskRejectedException e) {
logger.error("the queue reached max deepth");
throw new OpenApiException(OpenApiServiceErrorEnum.SYSTEM_QUEUE_DEEPTH);
} catch (Throwable e) {
Throwable throwable = e.getCause();
if (throwable instanceof OpenApiException) {
throw (OpenApiException) throwable;
}
logger.error(String.format("exception happend on executing task with %s", e.getMessage()));
OpenApiException ex = new OpenApiException(OpenApiServiceErrorEnum.SYSTEM_BUSY, throwable);
throw ex;
}
}
Aggregations