use of com.enonic.xp.portal.impl.ContentResolverResult in project xp by enonic.
the class ComponentHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
final ContentResolverResult resolvedContent = contentResolver.resolve(this.request);
final Content content = resolvedContent.getContentOrElseThrow();
final Site site = resolvedContent.getNearestSiteOrElseThrow();
Page page = content.getPage();
final PageResolverResult resolvedPage = pageResolver.resolve(request.getMode(), content, site);
Component component = null;
if (content.getType().isFragment()) {
// fragment content, try resolving component path in Layout fragment
final Component fragmentComponent = page.getFragment();
if (this.componentPath.isEmpty()) {
component = fragmentComponent;
} else if (fragmentComponent instanceof LayoutComponent) {
component = ((LayoutComponent) fragmentComponent).getComponent(this.componentPath);
}
}
final Page effectivePage;
if (component == null) {
effectivePage = inlineFragments(resolvedPage.getEffectivePage(), this.componentPath);
component = effectivePage.getRegions().getComponent(this.componentPath);
} else {
effectivePage = resolvedPage.getEffectivePage();
}
if (component == null) {
throw WebException.notFound(String.format("Page component for [%s] not found", this.componentPath));
}
final Content effectiveContent = Content.create(content).page(effectivePage).build();
final DescriptorKey controller = resolvedPage.getController();
this.request.setSite(site);
this.request.setContent(effectiveContent);
this.request.setComponent(component);
this.request.setApplicationKey(controller != null ? controller.getApplicationKey() : null);
final Trace trace = Tracer.current();
if (trace != null) {
trace.put("componentPath", component.getPath());
trace.put("type", component.getType().toString());
}
final PortalResponse response = rendererDelegate.render(component, this.request);
return this.postProcessor.processResponseInstructions(this.request, response);
}
use of com.enonic.xp.portal.impl.ContentResolverResult in project xp by enonic.
the class ServiceHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
// Retrieves the ServiceDescriptor
final DescriptorKey descriptorKey = DescriptorKey.from(applicationKey, name);
final ServiceDescriptor serviceDescriptor = serviceDescriptorService.getByKey(descriptorKey);
if (serviceDescriptor == null) {
throw WebException.notFound(String.format("Service [%s] not found", descriptorKey));
}
// Checks if the access to ServiceDescriptor is allowed
final PrincipalKeys principals = ContextAccessor.current().getAuthInfo().getPrincipals();
if (!serviceDescriptor.isAccessAllowed(principals)) {
throw WebException.forbidden(String.format("You don't have permission to access [%s]", descriptorKey));
}
final ContentResolverResult resolvedContent = contentResolver.resolve(request);
final Site site = resolvedContent.getNearestSite();
// Checks if the application is set on the current site
if (site != null) {
final PropertyTree siteConfig = site.getSiteConfig(applicationKey);
if (siteConfig == null) {
throw WebException.forbidden(String.format("Service [%s] forbidden for this site", descriptorKey));
}
}
// Checks if the application is set on the current application
final ApplicationKey baseApplicationKey = getBaseApplicationKey();
if (baseApplicationKey != null && !baseApplicationKey.equals(applicationKey)) {
throw WebException.forbidden(String.format("Service [%s] forbidden for this application", descriptorKey));
}
// Prepares the request
this.request.setApplicationKey(applicationKey);
this.request.setContent(resolvedContent.getContent());
this.request.setSite(site);
// Executes the service
final ControllerScript controllerScript = getScript();
final PortalResponse portalResponse = controllerScript.execute(this.request);
final WebSocketConfig webSocketConfig = portalResponse.getWebSocket();
final WebSocketContext webSocketContext = this.request.getWebSocketContext();
if ((webSocketContext != null) && (webSocketConfig != null)) {
final WebSocketEndpoint webSocketEndpoint = newWebSocketEndpoint(webSocketConfig);
webSocketContext.apply(webSocketEndpoint);
}
return portalResponse;
}
use of com.enonic.xp.portal.impl.ContentResolverResult in project xp by enonic.
the class PageHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
final ContentResolverResult resolvedContent = contentResolver.resolve(this.request);
final Content content = resolvedContent.getContentOrElseThrow();
if (content.getType().isShortcut()) {
return renderShortcut(content);
}
final Site site = resolvedContent.getNearestSiteOrElseThrow();
final PageResolverResult resolvedPage = pageResolver.resolve(request.getMode(), content, site);
final Content effectiveContent = Content.create(content).page(resolvedPage.getEffectivePage()).build();
final DescriptorKey pageDescriptorKey = resolvedPage.getController();
this.request.setSite(site);
this.request.setContent(effectiveContent);
this.request.setApplicationKey(pageDescriptorKey != null ? pageDescriptorKey.getApplicationKey() : null);
this.request.setPageDescriptor(pageDescriptorKey != null ? this.pageDescriptorService.getByKey(pageDescriptorKey) : null);
final Trace trace = Tracer.current();
if (trace != null) {
trace.put("contentPath", effectiveContent.getPath().toString());
trace.put("type", "page");
}
return rendererDelegate.render(effectiveContent, this.request);
}
use of com.enonic.xp.portal.impl.ContentResolverResult in project xp by enonic.
the class IdentityHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
final ContentResolverResult resolvedContent = contentResolver.resolve(this.request);
this.request.setContent(resolvedContent.getContent());
this.request.setSite(resolvedContent.getNearestSite());
final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().idProviderKey(idProviderKey).functionName(idProviderFunction).portalRequest(this.request).build();
final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
if (portalResponse == null) {
throw WebException.notFound(String.format("ID Provider function [%s] not found for id provider [%s]", idProviderFunction, idProviderKey));
} else {
return portalResponse;
}
}
use of com.enonic.xp.portal.impl.ContentResolverResult in project xp by enonic.
the class MappingHandler method handle.
@Override
public WebResponse handle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
if (!(webRequest instanceof PortalRequest) || webRequest.getEndpointPath() != null) {
return webHandlerChain.handle(webRequest, webResponse);
}
final PortalRequest request = (PortalRequest) webRequest;
if (request.getMode() == RenderMode.ADMIN || !request.isSiteBase()) {
return webHandlerChain.handle(webRequest, webResponse);
}
WebHandlerHelper.checkAdminAccess(request);
final HttpMethod method = webRequest.getMethod();
if (!HttpMethod.standard().contains(method)) {
throw new WebException(HttpStatus.METHOD_NOT_ALLOWED, String.format("Method %s not allowed", method));
}
final ContentResolverResult resolvedContent = contentResolver.resolve(request);
final Site site = resolvedContent.getNearestSite();
if (site == null) {
return webHandlerChain.handle(request, webResponse);
}
final Content content = resolvedContent.getContent();
final Optional<ControllerMappingDescriptor> resolve = controllerMappingsResolver.resolve(resolvedContent.getSiteRelativePath(), request.getParams(), content, site.getSiteConfigs());
if (resolve.isPresent()) {
final ControllerMappingDescriptor mapping = resolve.get();
request.setContent(content);
request.setSite(site);
request.setContextPath(request.getBaseUri() + "/" + request.getBranch() + site.getPath());
request.setApplicationKey(mapping.getApplication());
if (mapping.isController()) {
return handleController(request, mapping);
} else {
return handleFilter(request, webResponse, webHandlerChain, mapping);
}
} else {
return webHandlerChain.handle(request, webResponse);
}
}
Aggregations