use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class ExceptionRendererImpl method render.
@Override
public PortalResponse render(final WebRequest webRequest, final WebException cause) {
String tip = null;
final ExceptionInfo info = toErrorInfo(cause);
logIfNeeded(info);
if (webRequest instanceof PortalRequest) {
PortalRequest portalRequest = (PortalRequest) webRequest;
final HttpStatus httpStatus = cause.getStatus();
if (httpStatus != null) {
final String handlerMethod = "handle" + httpStatus.value();
final PortalResponse statusCustomError = renderCustomError(portalRequest, cause, handlerMethod);
if (statusCustomError != null) {
logIfNeeded(toErrorInfo(cause));
return statusCustomError;
}
}
final PortalResponse idProviderError = renderIdProviderError(portalRequest, cause);
if (idProviderError != null) {
logIfNeeded(toErrorInfo(cause));
return idProviderError;
}
final PortalResponse defaultCustomError = renderCustomError(portalRequest, cause, DEFAULT_HANDLER);
if (defaultCustomError != null) {
logIfNeeded(toErrorInfo(cause));
return defaultCustomError;
}
if ("/site".equals(portalRequest.getBaseUri()) && ContentConstants.BRANCH_MASTER.equals(portalRequest.getBranch()) && HttpStatus.NOT_FOUND.equals(cause.getStatus())) {
tip = "Tip: Did you remember to publish the site?";
}
}
return renderInternalErrorPage(webRequest, tip, cause);
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class AttachmentHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
final Content content = getContent(this.id);
final Attachment attachment = resolveAttachment(content, this.name);
final BinaryReference binaryReference = attachment.getBinaryReference();
final ByteSource binary = resolveBinary(this.id, binaryReference);
if (request.getMethod() == HttpMethod.OPTIONS) {
// it will be handled by default OPTIONS handler in BaseWebHandler
return PortalResponse.create().status(HttpStatus.METHOD_NOT_ALLOWED).build();
}
final MediaType contentType = MediaType.parse(attachment.getMimeType());
final PortalResponse.Builder portalResponse = PortalResponse.create().contentType(contentType).body(binary);
if (this.download) {
portalResponse.header("Content-Disposition", contentDispositionAttachment(attachment.getName()));
}
if (this.name.endsWith(".svgz")) {
portalResponse.header("Content-Encoding", "gzip");
}
if (!nullToEmpty(this.fingerprint).isBlank()) {
final boolean isPublic = content.getPermissions().isAllowedFor(RoleKeys.EVERYONE, Permission.READ) && ContentConstants.BRANCH_MASTER.equals(request.getBranch());
final String cacheControlHeaderConfig = isPublic ? publicCacheControlHeaderConfig : privateCacheControlHeaderConfig;
if (!nullToEmpty(cacheControlHeaderConfig).isBlank() && this.fingerprint.equals(resolveHash(this.id, binaryReference))) {
portalResponse.header(HttpHeaders.CACHE_CONTROL, cacheControlHeaderConfig);
}
}
new RangeRequestHelper().handleRangeRequest(request, portalResponse, binary, contentType);
return portalResponse.build();
}
use of com.enonic.xp.portal.PortalResponse 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.PortalResponse in project xp by enonic.
the class MappingHandlerWorker method execute.
@Override
public PortalResponse execute() throws Exception {
final ControllerScript controllerScript = getScript();
final Trace trace = Tracer.current();
if (trace != null) {
trace.put("contentPath", this.request.getContentPath().toString());
trace.put("type", "mapping");
}
this.request.setControllerScript(controllerScript);
final PortalResponse portalResponse = rendererDelegate.render(mappingDescriptor, this.request);
final WebSocketConfig webSocketConfig = portalResponse.getWebSocket();
final WebSocketContext webSocketContext = this.request.getWebSocketContext();
if (webSocketContext != null && webSocketConfig != null) {
final WebSocketEndpoint webSocketEndpoint = newWebSocketEndpoint(webSocketConfig, this::getScript, request.getApplicationKey());
webSocketContext.apply(webSocketEndpoint);
}
return portalResponse;
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class PostProcessEvaluator method executeInstruction.
private HtmlBlocks executeInstruction(final String content) {
for (final PostProcessInstruction instruction : this.instructions) {
final PortalResponse instructionResponse = instruction.evaluate(this.portalRequest, content);
if (instructionResponse == null) {
continue;
}
final boolean hasHeaders = !instructionResponse.getHeaders().isEmpty();
final boolean hasCookies = !instructionResponse.getCookies().isEmpty();
final boolean hasContributions = instructionResponse.hasContributions();
final boolean skipFilters = !instructionResponse.applyFilters();
if (hasContributions || hasHeaders || skipFilters || hasCookies) {
final PortalResponse.Builder newPortalResponse = PortalResponse.create(this.portalResponse);
if (hasContributions) {
newPortalResponse.contributionsFrom(instructionResponse);
}
if (hasHeaders) {
newPortalResponse.headers(instructionResponse.getHeaders());
}
if (hasCookies) {
newPortalResponse.cookies(instructionResponse.getCookies());
}
if (skipFilters) {
newPortalResponse.applyFilters(false);
}
this.portalResponse = newPortalResponse.build();
}
final String resultBody = instructionResponse.getAsString();
return resultBody == null ? null : new HtmlBlockParser().parse(resultBody);
}
return null;
}
Aggregations