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);
}
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;
});
}
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();
}
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);
}
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);
}
Aggregations