use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class BasePortalHandler method doHandle.
@Override
protected WebResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) {
final PortalRequest portalRequest;
if (webRequest instanceof PortalRequest) {
portalRequest = (PortalRequest) webRequest;
} else {
portalRequest = createPortalRequest(webRequest, webResponse);
}
try {
PortalRequestAccessor.set(portalRequest.getRawRequest(), portalRequest);
ContextAccessor.current().getLocalScope().setAttribute(portalRequest.getRepositoryId());
ContextAccessor.current().getLocalScope().setAttribute(portalRequest.getBranch());
final WebResponse returnedWebResponse = webHandlerChain.handle(portalRequest, webResponse);
exceptionMapper.throwIfNeeded(returnedWebResponse);
return returnedWebResponse;
} catch (Exception e) {
return handleError(portalRequest, e);
}
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class WebAppHandlerTest method handle_executeController_error.
@Test
public void handle_executeController_error() throws Exception {
mockResource("myapp:/assets/a.txt", null);
this.request.setApplicationKey(ApplicationKey.from("myapp"));
this.request.setRawPath("/webapp/myapp/a.txt");
final WebResponse response = this.handler.doHandle(this.request, null, this.chain);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatus());
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class WebAppHandlerTest method handle_serveAsset.
@Test
public void handle_serveAsset() throws Exception {
final Resource resource = mockResource("myapp:/assets/a/b.txt", "hello".getBytes());
this.request.setRawPath("/webapp/myapp/a/b.txt");
this.request.setMethod(HttpMethod.GET);
final WebResponse response = this.handler.doHandle(this.request, null, this.chain);
assertEquals(HttpStatus.OK, response.getStatus());
assertSame(resource, response.getBody());
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class WebDispatcherServlet method service.
@Override
protected void service(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException {
final WebRequest webRequest = newWebRequest(req);
final WebSocketContext webSocketContext = this.webSocketContextFactory.newContext(req, res);
webRequest.setWebSocketContext(webSocketContext);
final WebResponse webResponse = doHandle(webRequest);
final WebSocketConfig config = webResponse.getWebSocket();
if ((webSocketContext != null) && (config != null)) {
return;
}
responseSerializationService.serialize(webRequest, webResponse, res);
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class TraceWebFilter method doHandle.
@Override
protected WebResponse doHandle(final WebRequest req, final WebResponse res, final WebHandlerChain chain) throws Exception {
final Trace trace = Tracer.newTrace("portalRequest");
if (trace == null) {
return chain.handle(req, res);
}
trace.put("path", req.getPath());
trace.put("rawpath", req.getRawPath());
trace.put("url", ServletRequestUrlHelper.getFullUrl(req.getRawRequest()));
trace.put("method", req.getMethod().toString());
trace.put("host", req.getHost());
trace.put("httpRequest", req);
trace.put("httpResponse", res);
trace.put("context", ContextAccessor.current());
return Tracer.traceEx(trace, () -> {
final WebResponse webResponse = chain.handle(req, res);
addTraceInfo(trace, webResponse);
trace.put("httpResponse", webResponse);
return webResponse;
});
}
Aggregations