Search in sources :

Example 1 with WebResponse

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;
}
Also used : WebException(com.enonic.xp.web.WebException) WebResponse(com.enonic.xp.web.WebResponse)

Example 2 with 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;
    });
}
Also used : Trace(com.enonic.xp.trace.Trace) ApplicationKey(com.enonic.xp.app.ApplicationKey) WebResponse(com.enonic.xp.web.WebResponse) Matcher(java.util.regex.Matcher) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 3 with WebResponse

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);
    }
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) WebException(com.enonic.xp.web.WebException)

Example 4 with WebResponse

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;
}
Also used : WebException(com.enonic.xp.web.WebException) WebResponse(com.enonic.xp.web.WebResponse)

Example 5 with 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"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) Test(org.junit.jupiter.api.Test) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest)

Aggregations

WebResponse (com.enonic.xp.web.WebResponse)63 Test (org.junit.jupiter.api.Test)53 BaseHandlerTest (com.enonic.xp.web.handler.BaseHandlerTest)32 PortalResponse (com.enonic.xp.portal.PortalResponse)11 WebRequest (com.enonic.xp.web.WebRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 ByteSource (com.google.common.io.ByteSource)6 Cookie (javax.servlet.http.Cookie)6 ResourceKey (com.enonic.xp.resource.ResourceKey)5 WebException (com.enonic.xp.web.WebException)5 ServletOutputStream (javax.servlet.ServletOutputStream)5 PortalRequest (com.enonic.xp.portal.PortalRequest)4 Content (com.enonic.xp.content.Content)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 PageUrlParams (com.enonic.xp.portal.url.PageUrlParams)2 MockResource (com.enonic.xp.resource.MockResource)2 Resource (com.enonic.xp.resource.Resource)2 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)2 Trace (com.enonic.xp.trace.Trace)2 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)2