use of info.xiancloud.gateway.controller.BaseController in project xian by happyyangyuan.
the class AbstractAsyncForwarder method forward.
@Override
public void forward(String uri, String ip, String msgId, Map<String, String> header, String body) {
LOG.debug("this method is running in the netty http server's io thread.");
UnitRequest controllerRequest;
try {
controllerRequest = bodyParams(body, header);
} catch (BadRequestException badRequestException) {
LOG.warn(badRequestException);
ServerResponseBean responseBean = new ServerResponseBean();
responseBean.setMsgId(msgId);
responseBean.setHttpContentType(HttpContentType.APPLICATION_JSON);
responseBean.setResponseBody(UnitResponse.createError(Group.CODE_BAD_REQUEST, null, badRequestException.getLocalizedMessage()).toVoJSONString());
IServerResponder.singleton.response(responseBean);
return;
}
RequestContext context = controllerRequest.getContext();
URIBean uriBean = URIBean.create(uri);
context.setUri(uri).setIp(ip).setHeader(header).setUnit(uriBean.getUnit()).setGroup(uriBean.getGroup()).setUriExtension(uriBean.getUriExtension()).setMsgId(msgId).setUriParameters(uriBean.getUriParameters());
// uri parameters overwrite body parameters.
controllerRequest.getArgMap().putAll(uriBean.getUriParameters());
BaseController controller = IControllerMapper.getController(controllerRequest, new TransactionalNotifyHandler() {
@Override
protected void handle(UnitResponse unitResponse) {
if (unitResponse == null) {
Throwable emptyOutputException = new RuntimeException("UnitResponse is not allowed to be null.");
LOG.error(emptyOutputException);
unitResponse = UnitResponse.createException(emptyOutputException);
} else if (StringUtil.isEmpty(unitResponse.getCode())) {
Throwable emptyOutputException = new RuntimeException("UnitResponse's code is not allowed to be empty: " + unitResponse);
LOG.error(emptyOutputException);
unitResponse = UnitResponse.createException(emptyOutputException);
}
ServerResponseBean responseBean = new ServerResponseBean();
responseBean.setResponseBody(extractContext(unitResponse));
responseBean.setMsgId(msgId);
responseBean.setHttpContentType(unitResponse.getContext().getHttpContentType());
IServerResponder.singleton.response(responseBean);
}
});
ThreadPoolManager.execute(controller, msgId);
}
Aggregations