use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class BaseSiteHandler method doCreatePortalRequest.
protected PortalRequest doCreatePortalRequest(final WebRequest webRequest, final String baseUri, final String baseSubPath) {
final RepositoryId repositoryId = findRepository(baseSubPath);
final Branch branch = findBranch(baseSubPath);
final ContentPath contentPath = findContentPath(baseSubPath);
final PortalRequest portalRequest = new PortalRequest(webRequest);
portalRequest.setBaseUri(baseUri);
portalRequest.setRepositoryId(repositoryId);
portalRequest.setBranch(branch);
portalRequest.setContentPath(contentPath);
return portalRequest;
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class AbstractUrlParamsTest method setup.
@BeforeEach
public void setup() {
this.portalRequest = new PortalRequest();
this.portalRequest.setBranch(Branch.from("draft"));
this.portalRequest.setApplicationKey(ApplicationKey.from("myapplication"));
this.portalRequest.setBaseUri("/site");
this.portalRequest.setContentPath(ContentPath.from("context/path"));
}
use of com.enonic.xp.portal.PortalRequest 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.PortalRequest in project xp by enonic.
the class PortalRequestSerializer method serialize.
public PortalRequest serialize() {
final PortalRequest req = new PortalRequest(sourceRequest);
if ((value == null) || !value.isObject()) {
return req;
}
req.setBaseUri(sourceRequest.getBaseUri());
req.setContentPath(sourceRequest.getContentPath());
req.setContent(sourceRequest.getContent());
req.setSite(sourceRequest.getSite());
req.setPageTemplate(sourceRequest.getPageTemplate());
req.setComponent(sourceRequest.getComponent());
req.setApplicationKey(sourceRequest.getApplicationKey());
req.setPageDescriptor(sourceRequest.getPageDescriptor());
req.setControllerScript(sourceRequest.getControllerScript());
req.setRepositoryId(sourceRequest.getRepositoryId());
populateMethod(req, value.getMember("method"));
populateScheme(req, value.getMember("scheme"));
populateHost(req, value.getMember("host"));
populatePort(req, value.getMember("port"));
populatePath(req, value.getMember("path"));
populateUrl(req, value.getMember("url"));
populateRemoteAddress(req, value.getMember("remoteAddress"));
populateMode(req, value.getMember("mode"));
populateValidTicket(req, value.getMember("validTicket"));
populateBranch(req, value.getMember("branch"));
populateContentType(req, value.getMember("contentType"));
populateBody(req, value.getMember("body"));
populateHeaders(req, value.getMember("headers"));
populateCookies(req, value.getMember("cookies"));
populateParams(req, value.getMember("params"));
return req;
}
use of com.enonic.xp.portal.PortalRequest 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