Search in sources :

Example 1 with ContentResolver

use of com.enonic.xp.portal.impl.ContentResolver in project xp by enonic.

the class ComponentHandler method doHandle.

@Override
protected PortalResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
    WebHandlerHelper.checkAdminAccess(webRequest);
    final String restPath = findRestPath(webRequest);
    final ComponentHandlerWorker worker = new ComponentHandlerWorker((PortalRequest) webRequest);
    worker.componentPath = ComponentPath.from(restPath);
    worker.contentService = contentService;
    worker.contentResolver = new ContentResolver(contentService);
    worker.rendererDelegate = rendererDelegate;
    worker.pageResolver = new PageResolver(pageTemplateService);
    worker.postProcessor = postProcessor;
    final Trace trace = Tracer.newTrace("renderComponent");
    if (trace == null) {
        return worker.execute();
    }
    return Tracer.traceEx(trace, worker::execute);
}
Also used : Trace(com.enonic.xp.trace.Trace) ContentResolver(com.enonic.xp.portal.impl.ContentResolver)

Example 2 with ContentResolver

use of com.enonic.xp.portal.impl.ContentResolver 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 3 with ContentResolver

use of com.enonic.xp.portal.impl.ContentResolver in project xp by enonic.

the class ServiceHandler 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 service url pattern");
    }
    final PortalRequest portalRequest = webRequest instanceof PortalRequest ? (PortalRequest) webRequest : new PortalRequest(webRequest);
    portalRequest.setContextPath(findPreRestPath(portalRequest) + "/" + matcher.group(0));
    final ServiceHandlerWorker worker = new ServiceHandlerWorker(portalRequest);
    worker.applicationKey = ApplicationKey.from(matcher.group(1));
    worker.name = matcher.group(2);
    worker.contentResolver = new ContentResolver(this.contentService);
    worker.resourceService = this.resourceService;
    worker.serviceDescriptorService = this.serviceDescriptorService;
    worker.controllerScriptFactory = this.controllerScriptFactory;
    return worker.execute();
}
Also used : Matcher(java.util.regex.Matcher) PortalRequest(com.enonic.xp.portal.PortalRequest) ContentResolver(com.enonic.xp.portal.impl.ContentResolver)

Example 4 with ContentResolver

use of com.enonic.xp.portal.impl.ContentResolver in project xp by enonic.

the class PageHandler method doHandle.

@Override
protected PortalResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
    WebHandlerHelper.checkAdminAccess(webRequest);
    final PageHandlerWorker worker = new PageHandlerWorker((PortalRequest) webRequest);
    worker.contentResolver = new ContentResolver(contentService);
    worker.rendererDelegate = rendererDelegate;
    worker.pageResolver = new PageResolver(pageTemplateService);
    worker.pageDescriptorService = pageDescriptorService;
    worker.portalUrlService = portalUrlService;
    final Trace trace = Tracer.newTrace("renderComponent");
    if (trace == null) {
        return worker.execute();
    }
    return Tracer.traceEx(trace, worker::execute);
}
Also used : Trace(com.enonic.xp.trace.Trace) ContentResolver(com.enonic.xp.portal.impl.ContentResolver)

Example 5 with ContentResolver

use of com.enonic.xp.portal.impl.ContentResolver in project xp by enonic.

the class MappingHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.request = new PortalRequest();
    final ControllerScriptFactory controllerScriptFactory = mock(ControllerScriptFactory.class);
    ControllerScript controllerScript = mock(ControllerScript.class);
    when(controllerScriptFactory.fromDir(Mockito.any())).thenReturn(controllerScript);
    final PortalResponse portalResponse = PortalResponse.create().build();
    when(controllerScript.execute(Mockito.any())).thenReturn(portalResponse);
    FilterScriptFactory filterScriptFactory = mock(FilterScriptFactory.class);
    FilterScript filterScript = mock(FilterScript.class);
    when(filterScriptFactory.fromScript(Mockito.any())).thenReturn(filterScript);
    when(filterScript.execute(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(portalResponse);
    this.resourceService = mock(ResourceService.class);
    final Resource resourceNotFound = mock(Resource.class);
    when(resourceNotFound.exists()).thenReturn(false);
    final Resource resource = mock(Resource.class);
    when(resource.exists()).thenReturn(true);
    when(this.resourceService.getResource(ResourceKey.from("demo:/services/test"))).thenReturn(resource);
    this.contentService = mock(ContentService.class);
    this.rendererDelegate = mock(RendererDelegate.class);
    this.siteService = mock(SiteService.class);
    this.handler = new MappingHandler(resourceService, controllerScriptFactory, filterScriptFactory, rendererDelegate, new ControllerMappingsResolver(siteService), new ContentResolver(contentService));
    this.request.setMethod(HttpMethod.GET);
}
Also used : FilterScriptFactory(com.enonic.xp.portal.filter.FilterScriptFactory) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) FilterScript(com.enonic.xp.portal.filter.FilterScript) ResourceService(com.enonic.xp.resource.ResourceService) Resource(com.enonic.xp.resource.Resource) ContentService(com.enonic.xp.content.ContentService) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) ContentResolver(com.enonic.xp.portal.impl.ContentResolver) PortalResponse(com.enonic.xp.portal.PortalResponse) SiteService(com.enonic.xp.site.SiteService) RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ContentResolver (com.enonic.xp.portal.impl.ContentResolver)5 PortalRequest (com.enonic.xp.portal.PortalRequest)3 Trace (com.enonic.xp.trace.Trace)3 PortalResponse (com.enonic.xp.portal.PortalResponse)2 Matcher (java.util.regex.Matcher)2 ContentService (com.enonic.xp.content.ContentService)1 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)1 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)1 FilterScript (com.enonic.xp.portal.filter.FilterScript)1 FilterScriptFactory (com.enonic.xp.portal.filter.FilterScriptFactory)1 RendererDelegate (com.enonic.xp.portal.impl.rendering.RendererDelegate)1 Resource (com.enonic.xp.resource.Resource)1 ResourceService (com.enonic.xp.resource.ResourceService)1 IdProviderKey (com.enonic.xp.security.IdProviderKey)1 SiteService (com.enonic.xp.site.SiteService)1 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1