use of io.leopard.web.view.WsView in project leopard by tanhaichao.
the class WsViewTest method getData.
@Test
public void getData() {
WsView webserviceView = new WsView("success");
Assert.assertEquals("success", webserviceView.getData());
Assert.assertEquals(200, webserviceView.getStatus());
Assert.assertEquals("", webserviceView.getMessage());
}
use of io.leopard.web.view.WsView in project leopard by tanhaichao.
the class WsViewTest method getBody.
@Test
public void getBody() {
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
WsView webserviceView = new WsView("data");
String body = webserviceView.getBody(request, response);
// System.out.println("body:" + body);
Assert.assertEquals("{\"status\":200,\"message\":\"\",\"clazz\":\"java.lang.String\",\"data\":\"\\\"data\\\"\"}", body);
Assert.assertEquals("text/plain; charset=UTF-8", webserviceView.getContentType());
}
use of io.leopard.web.view.WsView in project leopard by tanhaichao.
the class WsViewTrynbResolver method resolveView.
@Override
public ModelAndView resolveView(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, Exception exception, TrynbInfo trynbInfo) {
Class<?> returnType = handler.getMethod().getReturnType();
if (!returnType.equals(WsView.class)) {
return null;
}
WsView webserviceView = new WsView(null);
if (exception instanceof StatusCodeException) {
StatusCodeException e = (StatusCodeException) exception;
webserviceView.setStatus(e.getStatus());
webserviceView.setMessage(e.getMessage());
} else {
webserviceView.setStatus(trynbInfo.getStatusCode());
webserviceView.setMessage(trynbInfo.getMessage());
}
return webserviceView;
}
Aggregations