Search in sources :

Example 6 with OpenApiHttpRequestBean

use of com.z.gateway.common.OpenApiHttpRequestBean in project gateway-dubbox by zhuzhong.

the class OpenApiExceptionHandler method resolveException.

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
    OpenApiHttpRequestBean reqBean = (OpenApiHttpRequestBean) request.getAttribute(CommonCodeConstants.REQ_BEAN_KEY);
    reqBean.setPrintStr(JSON.toJSONString(ex));
    OpenApiResponseUtils.writeRsp(response, reqBean);
    return null;
}
Also used : OpenApiHttpRequestBean(com.z.gateway.common.OpenApiHttpRequestBean)

Example 7 with OpenApiHttpRequestBean

use of com.z.gateway.common.OpenApiHttpRequestBean in project gateway-dubbox by zhuzhong.

the class OpenApiAcceptHandlerImpl method acceptRequest.

@Override
public void acceptRequest(HttpServletRequest request, HttpServletResponse response) {
    OpenApiHttpRequestBean reqBean = (OpenApiHttpRequestBean) request.getAttribute(CommonCodeConstants.REQ_BEAN_KEY);
    String traceId = idService.genInnerRequestId();
    reqBean.setTraceId(traceId);
    // 重新设置bean
    request.setAttribute(CommonCodeConstants.REQ_BEAN_KEY, reqBean);
    if (logger.isInfoEnabled()) {
        logger.info(String.format("requestId=%s request begin,reqeust=%s", traceId, JSON.toJSONString(reqBean)));
    }
    // 将当前请求放入线程池处理,若超过线程池最大处理数则抛出reach queue max deepth 异常
    addTask2Pool(response, new OpenApiHttpSessionBean(reqBean));
}
Also used : OpenApiHttpSessionBean(com.z.gateway.protocol.OpenApiHttpSessionBean) OpenApiHttpRequestBean(com.z.gateway.common.OpenApiHttpRequestBean)

Example 8 with OpenApiHttpRequestBean

use of com.z.gateway.common.OpenApiHttpRequestBean in project gateway-dubbox by zhuzhong.

the class AbstractOpenApiValidateInterceptor method preHandle.

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
    String requestMethod = request.getMethod();
    if (!requestMethod.equals(CommonCodeConstants.REQUEST_METHOD.GET.name()) && !requestMethod.equals(CommonCodeConstants.REQUEST_METHOD.POST.name())) {
        throw new RuntimeException("请求方法不对,请求方法必须是 GET 或POST");
    }
    // 初始化请求bean
    OpenApiHttpRequestBean reqBean = iniOpenApiHttpRequestBean(request);
    request.setAttribute(CommonCodeConstants.REQ_BEAN_KEY, reqBean);
    return true;
}
Also used : OpenApiHttpRequestBean(com.z.gateway.common.OpenApiHttpRequestBean)

Aggregations

OpenApiHttpRequestBean (com.z.gateway.common.OpenApiHttpRequestBean)8 OpenApiHttpSessionBean (com.z.gateway.protocol.OpenApiHttpSessionBean)5 OpenApiContext (com.z.gateway.protocol.OpenApiContext)4 OpenApiRouteBean (com.z.gateway.core.OpenApiRouteBean)1 OpenApiHandlerExecuteTemplate (com.z.gateway.handler.OpenApiHandlerExecuteTemplate)1 IOException (java.io.IOException)1 AsyncContext (javax.servlet.AsyncContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 BeansException (org.springframework.beans.BeansException)1