use of com.enonic.xp.web.HttpMethod in project xp by enonic.
the class ControllerScriptImpl method doExecute.
private PortalResponse doExecute(final PortalRequest portalRequest) {
Tracer.withCurrent(this::addTraceInfo);
final HttpMethod method = portalRequest.getMethod();
final boolean isHead = method == HttpMethod.HEAD;
String runMethod = isHead ? "get" : method.toString().toLowerCase();
final boolean exists = this.scriptExports.hasMethod(runMethod);
if (!exists) {
if (this.scriptExports.hasMethod(ALL_SCRIPT_METHOD_NAME)) {
runMethod = ALL_SCRIPT_METHOD_NAME;
} else {
return new PortalResponseSerializer(null, HttpStatus.METHOD_NOT_ALLOWED).serialize();
}
}
final PortalRequestMapper requestMapper = new PortalRequestMapper(portalRequest);
final ScriptValue result = this.scriptExports.executeMethod(runMethod, requestMapper);
return new PortalResponseSerializer(result).serialize();
}
use of com.enonic.xp.web.HttpMethod 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);
}
}
use of com.enonic.xp.web.HttpMethod in project xp by enonic.
the class BaseWebHandler method handle.
@Override
public WebResponse handle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
if (canHandle(webRequest)) {
final HttpMethod method = webRequest.getMethod();
checkMethodAllowed(method);
final WebResponse response = doHandle(webRequest, webResponse, webHandlerChain);
if (HttpMethod.OPTIONS == method && response.getStatus() == HttpStatus.METHOD_NOT_ALLOWED) {
return handleDefaultOptions();
}
return response;
} else {
return webHandlerChain.handle(webRequest, webResponse);
}
}
Aggregations