use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class BasePortalHandler method handleError.
private WebResponse handleError(final WebRequest webRequest, final Exception e) {
final WebException webException = exceptionMapper.map(e);
final WebResponse webResponse = exceptionRenderer.render(webRequest, webException);
webRequest.getRawRequest().setAttribute("error.handled", Boolean.TRUE);
return webResponse;
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class WebAppHandler method doHandle.
@Override
protected WebResponse doHandle(final WebRequest webRequest, final WebResponse res, final WebHandlerChain chain) throws Exception {
PortalRequest portalRequest = (PortalRequest) webRequest;
portalRequest.setContextPath(portalRequest.getBaseUri());
final Matcher matcher = PATTERN.matcher(portalRequest.getRawPath());
matcher.matches();
final ApplicationKey applicationKey = ApplicationKey.from(matcher.group(1));
final String restPath = matcher.group(2);
final Trace trace = Tracer.newTrace("renderApp");
if (trace == null) {
return handleAppRequest(portalRequest, applicationKey, restPath);
}
return Tracer.traceEx(trace, () -> {
final WebResponse resp = handleAppRequest(portalRequest, applicationKey, restPath);
addTraceInfo(trace, applicationKey, restPath);
return resp;
});
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class WebAppHandler method handleRequest.
private WebResponse handleRequest(final PortalRequest req) {
try {
PortalRequestAccessor.set(req.getRawRequest(), req);
final WebResponse returnedWebResponse = executeController(req);
exceptionMapper.throwIfNeeded(returnedWebResponse);
return returnedWebResponse;
} catch (Exception e) {
return handleError(req, e);
}
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class WebAppHandler method handleError.
private WebResponse handleError(final WebRequest webRequest, final Exception e) {
final WebException webException = exceptionMapper.map(e);
final WebResponse webResponse = exceptionRenderer.render(webRequest, webException);
webRequest.getRawRequest().setAttribute("error.handled", Boolean.TRUE);
return webResponse;
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class ErrorHandlerTest method testOptions.
@Test
public void testOptions() throws Exception {
this.request.setEndpointPath("/_/error/401");
this.request.setMethod(HttpMethod.OPTIONS);
final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
assertNotNull(res);
assertEquals(HttpStatus.OK, res.getStatus());
assertEquals("GET,POST,HEAD,OPTIONS,PUT,DELETE,TRACE", res.getHeaders().get("Allow"));
}
Aggregations