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);
}
}
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();
}
Aggregations