use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PortalRequestAdapter method adapt.
public PortalRequest adapt(final HttpServletRequest req) {
final PortalRequest result = new PortalRequest();
setBaseUri(req, result);
setRenderMode(req, result);
result.setMethod(HttpMethod.valueOf(req.getMethod().toUpperCase()));
result.setRawRequest(req);
result.setContentType(req.getContentType());
// TODO Temporary fix until Admin/Site full refactoring
// The Servlet request should be translated to Portal request only once
// result.setBody( RequestBodyReader.readBody( req ) );
result.setScheme(req.getScheme());
result.setHost(req.getServerName());
result.setRemoteAddress(req.getRemoteAddr());
result.setPort(req.getServerPort());
result.setPath(ServletRequestUrlHelper.getPath(req));
result.setRawPath(req.getPathInfo());
result.setUrl(ServletRequestUrlHelper.getFullUrl(req));
setParameters(req, result);
setHeaders(req, result);
setCookies(req, result);
return result;
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class MacroProcessorScript method process.
@Override
public PortalResponse process(final MacroContext macroContext) {
final PortalRequest portalRequest = macroContext.getRequest();
PortalRequestAccessor.set(portalRequest);
try {
return doProcess(macroContext);
} finally {
PortalRequestAccessor.remove();
}
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ContentResolverTest method resolve_self_in_edit_mode.
@Test
void resolve_self_in_edit_mode() {
final Site site = newSite();
final PortalRequest request = new PortalRequest();
request.setMode(RenderMode.EDIT);
request.setContentPath(ContentPath.from("/c8da0c10-0002-4b68-b407-87412f3e45c9"));
when(this.contentService.getById(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c9"))).thenReturn(site);
when(this.contentService.getNearestSite(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c9"))).thenReturn(site);
final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
assertSame(site, result.getContent());
assertSame(site, result.getNearestSite());
assertEquals("/", result.getSiteRelativePath());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PortalErrorTest method testGetException.
@Test
public void testGetException() throws Exception {
final Exception exception = new Exception("my exception");
final PortalRequest request = new PortalRequest();
final PortalError error = PortalError.create().request(request).status(HttpStatus.INTERNAL_SERVER_ERROR).exception(exception).build();
assertSame(exception, error.getException());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PortalErrorTest method testCopy.
@Test
public void testCopy() throws Exception {
final Exception exception = new Exception("my exception");
final PortalRequest request = new PortalRequest();
final PortalError error = PortalError.create().request(request).status(HttpStatus.INTERNAL_SERVER_ERROR).exception(exception).message("Some error").build();
final PortalError errorCopy = PortalError.create(error).build();
assertSame(errorCopy.getException(), errorCopy.getException());
assertEquals(errorCopy.getMessage(), errorCopy.getMessage());
assertSame(errorCopy.getRequest(), errorCopy.getRequest());
assertEquals(errorCopy.getStatus(), errorCopy.getStatus());
}
Aggregations