Search in sources :

Example 1 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class BaseContentHandler method createSitePropertySet.

private PropertySet createSitePropertySet(final Map<String, Object> siteConfig, final ContentTypeName contentTypeName) {
    if (siteConfig == null) {
        return null;
    }
    final ApplicationKey applicationKey = ApplicationKey.from(siteConfig.get("applicationKey").toString());
    final Map<String, ?> appConfigData = (Map<String, ?>) siteConfig.get("config");
    if (appConfigData == null) {
        return null;
    }
    final PropertySet propertySet = new PropertySet();
    propertySet.addString("applicationKey", applicationKey.toString());
    propertySet.addSet("config", this.translateToPropertyTree(appConfigData, applicationKey, contentTypeName).getRoot());
    return propertySet;
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) PropertySet(com.enonic.xp.data.PropertySet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey 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 ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class ExceptionRendererImpl method doRenderCustomError.

private PortalResponse doRenderCustomError(final PortalRequest req, final WebException cause, final String handlerMethod) {
    final PortalError portalError = PortalError.create().status(cause.getStatus()).message(cause.getMessage()).exception(cause).request(req).build();
    final Site siteInRequest = req.getSite();
    final Site site = siteInRequest != null ? siteInRequest : callAsContentAdmin(() -> this.contentService.findNearestSiteByPath(req.getContentPath()));
    if (site != null) {
        req.setSite(site);
        try {
            for (SiteConfig siteConfig : site.getSiteConfigs()) {
                final ApplicationKey applicationKey = siteConfig.getApplicationKey();
                for (final String scriptPath : SITE_ERROR_SCRIPT_PATHS) {
                    final PortalResponse response = renderApplicationCustomError(applicationKey, scriptPath, portalError, handlerMethod);
                    if (response != null) {
                        if (response.isPostProcess()) {
                            req.setApplicationKey(applicationKey);
                        }
                        return response;
                    }
                }
            }
        } finally {
            req.setSite(siteInRequest);
        }
    } else if (req.getApplicationKey() != null) {
        final ApplicationKey applicationKey = req.getApplicationKey();
        final PortalResponse response = renderApplicationCustomError(applicationKey, GENERIC_ERROR_SCRIPT_PATH, portalError, handlerMethod);
        if (response != null) {
            if (response.isPostProcess()) {
                req.setApplicationKey(applicationKey);
            }
            return response;
        }
    }
    return null;
}
Also used : Site(com.enonic.xp.site.Site) ApplicationKey(com.enonic.xp.app.ApplicationKey) PortalResponse(com.enonic.xp.portal.PortalResponse) PortalError(com.enonic.xp.portal.impl.error.PortalError) SiteConfig(com.enonic.xp.site.SiteConfig)

Example 4 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey 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 5 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class AssetUrlBuilder method buildUrl.

@Override
protected void buildUrl(final StringBuilder url, final Multimap<String, String> params) {
    super.buildUrl(url, params);
    final ApplicationKey applicationKey = new ApplicationResolver().portalRequest(this.portalRequest).application(this.params.getApplication()).resolve();
    final Resource resource = this.resourceService.getResource(ResourceKey.from(applicationKey, "META-INF/MANIFEST.MF"));
    if (!resource.exists()) {
        throw new IllegalArgumentException("Could not find application [" + applicationKey + "]");
    }
    final String fingerprint = RunMode.get() == RunMode.DEV ? String.valueOf(stableTime()) : HexCoder.toHex(resource.getTimestamp());
    appendPart(url, applicationKey + ":" + fingerprint);
    appendPart(url, this.params.getPath());
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) Resource(com.enonic.xp.resource.Resource)

Aggregations

ApplicationKey (com.enonic.xp.app.ApplicationKey)78 Test (org.junit.jupiter.api.Test)40 Application (com.enonic.xp.app.Application)16 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)12 Bundle (org.osgi.framework.Bundle)10 ResourceKey (com.enonic.xp.resource.ResourceKey)6 PropertyTree (com.enonic.xp.data.PropertyTree)5 ExtraData (com.enonic.xp.content.ExtraData)4 Site (com.enonic.xp.site.Site)4 Node (com.enonic.xp.node.Node)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 PortalRequest (com.enonic.xp.portal.PortalRequest)3 PortalResponse (com.enonic.xp.portal.PortalResponse)3 XDataName (com.enonic.xp.schema.xdata.XDataName)3 ByteSource (com.google.common.io.ByteSource)3 ApplicationInvalidator (com.enonic.xp.app.ApplicationInvalidator)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)2 PropertySet (com.enonic.xp.data.PropertySet)2 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)2 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)2