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