use of info.xiancloud.gateway.controller.URIBean in project xian by happyyangyuan.
the class URIBeanTest method uriBeanTest.
@Test
public void uriBeanTest() {
String uri = "/group/unit/extension-1/extension-2?a=1&a=1&a=2&c=&d=";
URIBean bean = URIBean.create(uri);
if (!"group".equals(bean.getGroup()))
throw new RuntimeException("group检测失败");
if (!"unit".equals(bean.getUnit()))
throw new RuntimeException("unit检测失败");
if (!"extension-1/extension-2".equals(bean.getUriExtension()))
throw new RuntimeException("uriExtension检测失败");
if (!"".equals(bean.getUriParameters().getString("c")))
throw new RuntimeException("uriParameters检测失败");
Assert.assertTrue(bean.getUriParameters().getJSONArray("a").size() == 3);
}
use of info.xiancloud.gateway.controller.URIBean 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