Search in sources :

Example 1 with PortalRequestMapper

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

the class MacroContextMapper method serialize.

@Override
public void serialize(final MapGenerator gen) {
    gen.value("name", macroContext.getName());
    gen.value("body", macroContext.getBody());
    MapperHelper.serializeMultimap("params", gen, macroContext.getParameters());
    final PortalRequest request = macroContext.getRequest();
    gen.map("request");
    if (request != null) {
        new PortalRequestMapper(request).serialize(gen);
    }
    gen.end();
    gen.value("document", macroContext.getDocument());
}
Also used : PortalRequestMapper(com.enonic.xp.portal.impl.mapper.PortalRequestMapper) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 2 with PortalRequestMapper

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

the class FilterScriptImpl method doExecute.

private PortalResponse doExecute(final PortalRequest request, final WebResponse response, final WebHandlerChain webHandlerChain) {
    if (!this.scriptExports.hasMethod(FILTER_SCRIPT_METHOD)) {
        throw new WebException(HttpStatus.NOT_IMPLEMENTED, "Missing exported function '" + FILTER_SCRIPT_METHOD + "' in filter script: " + scriptExports.getScript());
    }
    Tracer.withCurrent(this::addTraceInfo);
    final PortalRequestMapper requestMapper = new PortalRequestMapper(request);
    final FilterNextFunctionWrapper nextHandler = new FilterNextFunctionWrapper(webHandlerChain, request, response, scriptExports.getScript(), scriptService);
    final ScriptValue result = this.scriptExports.executeMethod(FILTER_SCRIPT_METHOD, requestMapper, nextHandler);
    return new PortalResponseSerializer(result).serialize();
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) PortalResponseSerializer(com.enonic.xp.portal.impl.controller.PortalResponseSerializer) WebException(com.enonic.xp.web.WebException) PortalRequestMapper(com.enonic.xp.portal.impl.mapper.PortalRequestMapper)

Example 3 with PortalRequestMapper

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

the class IdProviderControllerScriptImpl method doExecute.

private PortalResponse doExecute(final String functionName, final PortalRequest portalRequest) {
    final boolean exists = this.scriptExports.hasMethod(functionName);
    if (!exists) {
        return new PortalResponseSerializer(null, HttpStatus.NOT_FOUND).serialize();
    }
    final PortalRequestMapper requestMapper = new PortalRequestMapper(portalRequest);
    final ScriptValue result = this.scriptExports.executeMethod(functionName, requestMapper);
    if ((result == null) || !result.isObject()) {
        return null;
    } else {
        return new PortalResponseSerializer(result).serialize();
    }
}
Also used : PortalResponseSerializer(com.enonic.xp.portal.impl.controller.PortalResponseSerializer) ScriptValue(com.enonic.xp.script.ScriptValue) PortalRequestMapper(com.enonic.xp.portal.impl.mapper.PortalRequestMapper)

Example 4 with PortalRequestMapper

use of com.enonic.xp.portal.impl.mapper.PortalRequestMapper 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)

Example 5 with PortalRequestMapper

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

the class ControllerScriptImpl method doExecute.

private PortalResponse doExecute(final PortalRequest portalRequest) {
    Tracer.withCurrent(this::addTraceInfo);
    final HttpMethod method = portalRequest.getMethod();
    final boolean isHead = method == HttpMethod.HEAD;
    String runMethod = isHead ? "get" : method.toString().toLowerCase();
    final boolean exists = this.scriptExports.hasMethod(runMethod);
    if (!exists) {
        if (this.scriptExports.hasMethod(ALL_SCRIPT_METHOD_NAME)) {
            runMethod = ALL_SCRIPT_METHOD_NAME;
        } else {
            return new PortalResponseSerializer(null, HttpStatus.METHOD_NOT_ALLOWED).serialize();
        }
    }
    final PortalRequestMapper requestMapper = new PortalRequestMapper(portalRequest);
    final ScriptValue result = this.scriptExports.executeMethod(runMethod, requestMapper);
    return new PortalResponseSerializer(result).serialize();
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) PortalRequestMapper(com.enonic.xp.portal.impl.mapper.PortalRequestMapper) HttpMethod(com.enonic.xp.web.HttpMethod)

Aggregations

PortalRequestMapper (com.enonic.xp.portal.impl.mapper.PortalRequestMapper)5 ScriptValue (com.enonic.xp.script.ScriptValue)4 PortalResponseSerializer (com.enonic.xp.portal.impl.controller.PortalResponseSerializer)3 PortalRequest (com.enonic.xp.portal.PortalRequest)1 PortalResponseMapper (com.enonic.xp.portal.impl.mapper.PortalResponseMapper)1 HttpMethod (com.enonic.xp.web.HttpMethod)1 WebException (com.enonic.xp.web.WebException)1