Search in sources :

Example 1 with PortalRequest

use of com.enonic.xp.portal.PortalRequest 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 2 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class ExceptionRendererImpl method renderApplicationCustomError.

private PortalResponse renderApplicationCustomError(final ApplicationKey appKey, final String errorScriptPath, final PortalError portalError, final String handlerMethod) {
    final ResourceKey script = getScript(appKey, errorScriptPath);
    if (script == null) {
        return null;
    }
    final ErrorHandlerScript errorHandlerScript = this.errorHandlerScriptFactory.errorScript(script);
    final PortalRequest request = portalError.getRequest();
    final ApplicationKey previousApp = request.getApplicationKey();
    // set application of the error handler in the current context PortalRequest
    try {
        request.setApplicationKey(appKey);
        return errorHandlerScript.execute(portalError, handlerMethod);
    } finally {
        request.setApplicationKey(previousApp);
    }
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ErrorHandlerScript(com.enonic.xp.portal.impl.error.ErrorHandlerScript) ResourceKey(com.enonic.xp.resource.ResourceKey) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 3 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class AppPortalHandler method createPortalRequest.

@Override
protected PortalRequest createPortalRequest(final WebRequest webRequest, final WebResponse webResponse) {
    final Matcher matcher = PATTERN.matcher(webRequest.getRawPath());
    matcher.matches();
    final PortalRequest portalRequest = new PortalRequest(webRequest);
    portalRequest.setBaseUri(matcher.group(1));
    portalRequest.setApplicationKey(ApplicationKey.from(matcher.group(2)));
    return portalRequest;
}
Also used : Matcher(java.util.regex.Matcher) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 4 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class IdentityHandler method doHandle.

@Override
protected PortalResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
    final String restPath = findRestPath(webRequest);
    final Matcher matcher = PATTERN.matcher(restPath);
    if (!matcher.find()) {
        throw WebException.notFound("Not a valid idprovider url pattern");
    }
    final IdProviderKey idProviderKey = IdProviderKey.from(matcher.group(ID_PROVIDER_GROUP_INDEX));
    final VirtualHost virtualHost = VirtualHostHelper.getVirtualHost(webRequest.getRawRequest());
    if (!(virtualHost == null || virtualHost.getIdProviderKeys().contains(idProviderKey))) {
        throw WebException.forbidden(String.format("'%s' id provider is forbidden", idProviderKey));
    }
    String idProviderFunction = matcher.group(2);
    final PortalRequest portalRequest = webRequest instanceof PortalRequest ? (PortalRequest) webRequest : new PortalRequest(webRequest);
    portalRequest.setContextPath(findPreRestPath(portalRequest) + "/" + matcher.group(ID_PROVIDER_GROUP_INDEX));
    if (idProviderFunction != null) {
        checkTicket(portalRequest);
    }
    if (idProviderFunction == null) {
        idProviderFunction = webRequest.getMethod().toString().toLowerCase();
    }
    final IdentityHandlerWorker worker = new IdentityHandlerWorker(portalRequest);
    worker.idProviderKey = idProviderKey;
    worker.idProviderFunction = idProviderFunction;
    worker.contentResolver = new ContentResolver(contentService);
    worker.idProviderControllerService = this.idProviderControllerService;
    final Trace trace = Tracer.newTrace("portalRequest");
    if (trace == null) {
        return worker.execute();
    }
    trace.put("path", webRequest.getPath());
    trace.put("method", webRequest.getMethod().toString());
    trace.put("host", webRequest.getHost());
    trace.put("httpRequest", webRequest);
    trace.put("httpResponse", webResponse);
    trace.put("context", ContextAccessor.current());
    return Tracer.traceEx(trace, () -> {
        final PortalResponse response = worker.execute();
        addTraceInfo(trace, response);
        return response;
    });
}
Also used : Trace(com.enonic.xp.trace.Trace) PortalResponse(com.enonic.xp.portal.PortalResponse) Matcher(java.util.regex.Matcher) IdProviderKey(com.enonic.xp.security.IdProviderKey) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) PortalRequest(com.enonic.xp.portal.PortalRequest) ContentResolver(com.enonic.xp.portal.impl.ContentResolver)

Example 5 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class MacroContextMapper method serialize.

@Override
public void serialize(final MapGenerator gen) {
    gen.value("name", macroContext.getName());
    gen.value("body", macroContext.getBody());
    MapperHelper.serializeMultimap("params", gen, macroContext.getParameters());
    final PortalRequest request = macroContext.getRequest();
    gen.map("request");
    if (request != null) {
        new PortalRequestMapper(request).serialize(gen);
    }
    gen.end();
    gen.value("document", macroContext.getDocument());
}
Also used : PortalRequestMapper(com.enonic.xp.portal.impl.mapper.PortalRequestMapper) PortalRequest(com.enonic.xp.portal.PortalRequest)

Aggregations

PortalRequest (com.enonic.xp.portal.PortalRequest)103 Test (org.junit.jupiter.api.Test)47 BeforeEach (org.junit.jupiter.api.BeforeEach)35 PortalResponse (com.enonic.xp.portal.PortalResponse)25 Site (com.enonic.xp.site.Site)19 Content (com.enonic.xp.content.Content)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ApplicationKey (com.enonic.xp.app.ApplicationKey)10 ContentPath (com.enonic.xp.content.ContentPath)10 ContentService (com.enonic.xp.content.ContentService)10 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)10 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)9 ResourceKey (com.enonic.xp.resource.ResourceKey)9 ResourceService (com.enonic.xp.resource.ResourceService)9 ContentId (com.enonic.xp.content.ContentId)7 Matcher (java.util.regex.Matcher)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)7 Assertions.fail (org.junit.jupiter.api.Assertions.fail)7 Mockito.when (org.mockito.Mockito.when)7