use of com.enonic.xp.portal.impl.controller.PortalResponseSerializer 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();
}
use of com.enonic.xp.portal.impl.controller.PortalResponseSerializer 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();
}
}
use of com.enonic.xp.portal.impl.controller.PortalResponseSerializer 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();
}
use of com.enonic.xp.portal.impl.controller.PortalResponseSerializer in project xp by enonic.
the class LayoutRendererTest method nullResponseComponentEditMode.
@Test
public void nullResponseComponentEditMode() {
final LayoutDescriptor layoutDescriptor = LayoutDescriptor.create().displayName("My layout component").config(Form.create().build()).key(DescriptorKey.from("module:myLayoutComponent")).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("left").build()).add(RegionDescriptor.create().name("right").build()).build()).build();
final ControllerScript controllerScript = new ControllerScript() {
@Override
public PortalResponse execute(final PortalRequest portalRequest) {
return new PortalResponseSerializer(null).serialize();
}
@Override
public void onSocketEvent(final WebSocketEvent event) {
}
};
final LayoutDescriptorService layoutDescriptorService = Mockito.mock(LayoutDescriptorService.class);
final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
renderer = new LayoutRenderer();
renderer.setLayoutDescriptorService(layoutDescriptorService);
renderer.setControllerScriptFactory(controllerScriptFactory);
when(layoutDescriptorService.getByKey(any())).thenReturn(layoutDescriptor);
when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
portalRequest.setMode(RenderMode.EDIT);
layoutComponent = LayoutComponent.create().descriptor("myapp:myLayoutComponent").descriptor(layoutDescriptor.getKey()).build();
// exercise
portalResponse = renderer.render(layoutComponent, portalRequest);
// verify
String expected = "<div data-portal-component-type=\"layout\"></div>";
assertEquals(expected, portalResponse.getAsString());
}
use of com.enonic.xp.portal.impl.controller.PortalResponseSerializer in project xp by enonic.
the class MacroProcessorScript method doProcess.
private PortalResponse doProcess(final MacroContext macroContext) {
final boolean exists = this.scriptExports.hasMethod(SCRIPT_METHOD_NAME);
if (!exists) {
return null;
}
final MacroContextMapper macroContextMapper = new MacroContextMapper(macroContext);
final ScriptValue result = this.scriptExports.executeMethod(SCRIPT_METHOD_NAME, macroContextMapper);
return new PortalResponseSerializer(result).serialize();
}
Aggregations