Search in sources :

Example 56 with PortalRequest

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;
}
Also used : PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 57 with PortalRequest

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();
    }
}
Also used : PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 58 with PortalRequest

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());
}
Also used : Site(com.enonic.xp.site.Site) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 59 with PortalRequest

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());
}
Also used : PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 60 with PortalRequest

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());
}
Also used : PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Aggregations

PortalRequest (com.enonic.xp.portal.PortalRequest)103 Test (org.junit.jupiter.api.Test)47 BeforeEach (org.junit.jupiter.api.BeforeEach)35 PortalResponse (com.enonic.xp.portal.PortalResponse)25 Site (com.enonic.xp.site.Site)19 Content (com.enonic.xp.content.Content)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ApplicationKey (com.enonic.xp.app.ApplicationKey)10 ContentPath (com.enonic.xp.content.ContentPath)10 ContentService (com.enonic.xp.content.ContentService)10 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)10 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)9 ResourceKey (com.enonic.xp.resource.ResourceKey)9 ResourceService (com.enonic.xp.resource.ResourceService)9 ContentId (com.enonic.xp.content.ContentId)7 Matcher (java.util.regex.Matcher)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)7 Assertions.fail (org.junit.jupiter.api.Assertions.fail)7 Mockito.when (org.mockito.Mockito.when)7