use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class WidgetHandler method doHandle.
@Override
protected WebResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
WebHandlerHelper.checkAdminAccess(webRequest);
final String restPath = findRestPath(webRequest);
final Matcher matcher = PATTERN.matcher(restPath);
if (!matcher.find()) {
throw WebException.notFound("Not a valid service url pattern");
}
final PortalRequest portalRequest = webRequest instanceof PortalRequest ? (PortalRequest) webRequest : new PortalRequest(webRequest);
portalRequest.setContextPath(findPreRestPath(portalRequest) + "/" + matcher.group(0));
final WidgetHandlerWorker worker = new WidgetHandlerWorker(portalRequest);
worker.controllerScriptFactory = this.controllerScriptFactory;
worker.widgetDescriptorService = this.widgetDescriptorService;
worker.descriptorKey = DescriptorKey.from(ApplicationKey.from(matcher.group(1)), matcher.group(2));
return worker.execute();
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class AdminToolHandler method doHandle.
@Override
protected WebResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
WebHandlerHelper.checkAdminAccess(webRequest);
PortalRequest portalRequest = (PortalRequest) webRequest;
portalRequest.setContextPath(portalRequest.getBaseUri());
final AdminToolHandlerWorker worker = new AdminToolHandlerWorker(portalRequest);
worker.controllerScriptFactory = this.controllerScriptFactory;
worker.adminToolDescriptorService = adminToolDescriptorService;
final DescriptorKey descriptorKey = AdminToolPortalHandler.getDescriptorKey(webRequest);
worker.descriptorKey = descriptorKey == null ? AdminToolPortalHandler.DEFAULT_DESCRIPTOR_KEY : descriptorKey;
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 AdminSiteHandlerTest method testCreatePortalRequest.
@Test
public void testCreatePortalRequest() {
this.request.setRawPath("/admin/site/edit/repo/master/content/1");
PortalRequest portalRequest = this.handler.createPortalRequest(this.request, this.response);
assertEquals("/admin/site/edit", portalRequest.getBaseUri());
assertEquals("com.enonic.cms.repo", portalRequest.getRepositoryId().toString());
assertEquals("master", portalRequest.getBranch().toString());
assertEquals("/content/1", portalRequest.getContentPath().toString());
assertEquals("edit", portalRequest.getMode().toString());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class LocaleScriptBean method resolveLocaleFromSite.
private Locale resolveLocaleFromSite() {
final PortalRequest request = portalRequest.get();
if (request == null) {
return null;
}
final Site site = request.getSite();
if (site != null) {
return site.getLanguage();
}
return null;
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class BasePortalHandler method doHandle.
@Override
protected WebResponse doHandle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) {
final PortalRequest portalRequest;
if (webRequest instanceof PortalRequest) {
portalRequest = (PortalRequest) webRequest;
} else {
portalRequest = createPortalRequest(webRequest, webResponse);
}
try {
PortalRequestAccessor.set(portalRequest.getRawRequest(), portalRequest);
ContextAccessor.current().getLocalScope().setAttribute(portalRequest.getRepositoryId());
ContextAccessor.current().getLocalScope().setAttribute(portalRequest.getBranch());
final WebResponse returnedWebResponse = webHandlerChain.handle(portalRequest, webResponse);
exceptionMapper.throwIfNeeded(returnedWebResponse);
return returnedWebResponse;
} catch (Exception e) {
return handleError(portalRequest, e);
}
}
Aggregations