Search in sources :

Example 1 with OpenApiRouteBean

use of com.z.gateway.core.OpenApiRouteBean 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;
}
Also used : OpenApiRouteBean(com.z.gateway.core.OpenApiRouteBean) OpenApiHttpSessionBean(com.z.gateway.protocol.OpenApiHttpSessionBean) OpenApiHttpRequestBean(com.z.gateway.common.OpenApiHttpRequestBean) OpenApiContext(com.z.gateway.protocol.OpenApiContext)

Example 2 with OpenApiRouteBean

use of com.z.gateway.core.OpenApiRouteBean in project gateway-dubbox by zhuzhong.

the class OpenApiReqAdapter method initRouteBean.

private OpenApiRouteBean initRouteBean(OpenApiHttpRequestBean request) {
    OpenApiRouteBean routeBean = null;
    logger.info("iniApiRouteBean,这一步可以校验token,当然这个根据我们的实际情况去实现");
    /* String accessToken = request.getAppToken();
        if (StringUtils.isBlank(accessToken)) {
            throw new OpenApiException(OauthErrorEnum.ACCESSTOKEN.getErrCode(), OauthErrorEnum.ACCESSTOKEN.getErrMsg());
        }*/
    logger.info("init 路由bean ");
    routeBean = new OpenApiRouteBean();
    // 内部请求id,利于跟踪
    routeBean.setTraceId(request.getTraceId());
    // 请求api_id
    routeBean.setApiId(request.getApiId());
    // api_version
    routeBean.setVersion(request.getVersion());
    // 请求头
    routeBean.setReqHeader(request.getReqHeader());
    // 请求时间
    routeBean.setTimeStamp(request.getTimeStamp());
    // 请求操作类型
    routeBean.setOperationType(request.getOperationType());
    // 请求方法
    routeBean.setRequestMethod(request.getRequestMethod());
    // post请求参数
    routeBean.setServiceReqData(request.getServiceReqData());
    // routeBean.setQueryString(request.getQueryString());// get请求参数
    // get请求参数
    routeBean.setServiceGetReqData(request.getServiceGetReqData());
    routeBean.setRequestUrl(request.getRequestUrl());
    if (request.getThdApiUrlParams() != null) {
        for (Map.Entry<String, String> maps : request.getThdApiUrlParams().entrySet()) {
            routeBean.addThdApiUrlParams(maps.getKey(), maps.getValue());
        }
    }
    // 计算apiid
    setRouteBeanApiId(request, routeBean);
    cacheService.put(request.getRouteBeanKey(), routeBean);
    return routeBean;
}
Also used : OpenApiRouteBean(com.z.gateway.core.OpenApiRouteBean) Map(java.util.Map)

Example 3 with OpenApiRouteBean

use of com.z.gateway.core.OpenApiRouteBean in project gateway-dubbox by zhuzhong.

the class OpenApiRspHandler method getResponseBody.

private String getResponseBody(OpenApiHttpRequestBean bean) {
    logger.info("step4....");
    String routeBeanKey = bean.getRouteBeanKey();
    OpenApiRouteBean routeBean = (OpenApiRouteBean) cacheService.get(routeBeanKey);
    Object body = (Object) routeBean.getServiceRsp();
    if (body instanceof String) {
        return body.toString();
    } else {
        throw new RuntimeException("返回内容格式不对...");
    }
}
Also used : OpenApiRouteBean(com.z.gateway.core.OpenApiRouteBean)

Aggregations

OpenApiRouteBean (com.z.gateway.core.OpenApiRouteBean)3 OpenApiHttpRequestBean (com.z.gateway.common.OpenApiHttpRequestBean)1 OpenApiContext (com.z.gateway.protocol.OpenApiContext)1 OpenApiHttpSessionBean (com.z.gateway.protocol.OpenApiHttpSessionBean)1 Map (java.util.Map)1