use of com.enonic.xp.portal.PortalRequest 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.portal.PortalRequest 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.portal.PortalRequest in project xp by enonic.
the class AppPortalHandler method createPortalRequest.
@Override
protected PortalRequest createPortalRequest(final WebRequest webRequest, final WebResponse webResponse) {
final Matcher matcher = PATTERN.matcher(webRequest.getRawPath());
matcher.matches();
final PortalRequest portalRequest = new PortalRequest(webRequest);
portalRequest.setBaseUri(matcher.group(1));
portalRequest.setApplicationKey(ApplicationKey.from(matcher.group(2)));
return portalRequest;
}
use of com.enonic.xp.portal.PortalRequest 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.PortalRequest in project xp by enonic.
the class MacroContextMapper method serialize.
@Override
public void serialize(final MapGenerator gen) {
gen.value("name", macroContext.getName());
gen.value("body", macroContext.getBody());
MapperHelper.serializeMultimap("params", gen, macroContext.getParameters());
final PortalRequest request = macroContext.getRequest();
gen.map("request");
if (request != null) {
new PortalRequestMapper(request).serialize(gen);
}
gen.end();
gen.value("document", macroContext.getDocument());
}
Aggregations