Search in sources :

Example 1 with PortalResponseMapper

use of com.enonic.xp.portal.impl.mapper.PortalResponseMapper in project xp by enonic.

the class FilterNextFunctionWrapper method apply.

@Override
public Object apply(final Object scriptRequestObject) {
    if (functionWasCalled) {
        throw scriptError("Filter 'next' function was called multiple times", null);
    }
    functionWasCalled = true;
    ScriptValue scriptRequestParam = scriptService.toScriptValue(this.script, scriptRequestObject);
    try {
        final PortalRequest portalRequest = new PortalRequestSerializer(request, scriptRequestParam).serialize();
        final WebResponse newResponse = webHandlerChain.handle(portalRequest, response);
        final PortalResponseMapper response = new PortalResponseMapper((PortalResponse) newResponse);
        return scriptService.toNativeObject(this.script, response);
    } catch (ResourceProblemException | WebException e) {
        throw e;
    } catch (Exception e) {
        throw scriptError("Error executing filter script: " + script, e);
    }
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) WebResponse(com.enonic.xp.web.WebResponse) PortalResponseMapper(com.enonic.xp.portal.impl.mapper.PortalResponseMapper) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) WebException(com.enonic.xp.web.WebException) WebException(com.enonic.xp.web.WebException) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 2 with PortalResponseMapper

use of com.enonic.xp.portal.impl.mapper.PortalResponseMapper in project xp by enonic.

the class ResponseProcessorExecutor method executeFilter.

private PortalResponse executeFilter(final ScriptExports filterExports, final PortalRequest request, final PortalResponse response) {
    final PortalRequestMapper requestMapper = new PortalRequestMapper(request);
    final PortalResponseMapper responseMapper = new PortalResponseMapper(response);
    final ScriptValue result = filterExports.executeMethod(RESPONSE_PROCESSOR_METHOD, requestMapper, responseMapper);
    final PortalResponseSerializer portalResponseSerializer = new PortalResponseSerializer(result);
    if (unmodifiedByteSourceBody(response, result)) {
        portalResponseSerializer.body(response.getBody());
    }
    addTraceInfo(Tracer.current(), filterExports);
    return portalResponseSerializer.serialize();
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) PortalResponseSerializer(com.enonic.xp.portal.impl.controller.PortalResponseSerializer) PortalResponseMapper(com.enonic.xp.portal.impl.mapper.PortalResponseMapper) PortalRequestMapper(com.enonic.xp.portal.impl.mapper.PortalRequestMapper)

Aggregations

PortalResponseMapper (com.enonic.xp.portal.impl.mapper.PortalResponseMapper)2 ScriptValue (com.enonic.xp.script.ScriptValue)2 PortalRequest (com.enonic.xp.portal.PortalRequest)1 PortalResponseSerializer (com.enonic.xp.portal.impl.controller.PortalResponseSerializer)1 PortalRequestMapper (com.enonic.xp.portal.impl.mapper.PortalRequestMapper)1 ResourceProblemException (com.enonic.xp.resource.ResourceProblemException)1 WebException (com.enonic.xp.web.WebException)1 WebResponse (com.enonic.xp.web.WebResponse)1