Search in sources :

Example 1 with HttpWrapper

use of com.orion.lang.wrapper.HttpWrapper in project orion-ops by lijiahangmax.

the class WrapperResultHandler method handleReturnValue.

@Override
public void handleReturnValue(Object o, MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest) throws Exception {
    HttpServletResponse response = nativeWebRequest.getNativeResponse(HttpServletResponse.class);
    if (response == null) {
        return;
    }
    HttpWrapper<?> wrapper;
    if (o instanceof HttpWrapper) {
        wrapper = (HttpWrapper<?>) o;
    } else if (o instanceof RpcWrapper) {
        wrapper = ((RpcWrapper<?>) o).toHttpWrapper();
    } else {
        wrapper = new HttpWrapper<>().data(o);
    }
    modelAndViewContainer.setRequestHandled(true);
    response.setContentType(StandardContentType.APPLICATION_JSON);
    Servlets.transfer(response, wrapper.toJsonString().getBytes());
}
Also used : RpcWrapper(com.orion.lang.wrapper.RpcWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpWrapper(com.orion.lang.wrapper.HttpWrapper)

Aggregations

HttpWrapper (com.orion.lang.wrapper.HttpWrapper)1 RpcWrapper (com.orion.lang.wrapper.RpcWrapper)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1