Search in sources :

Example 1 with ResourceNotFoundException

use of com.enonic.xp.resource.ResourceNotFoundException in project xp by enonic.

the class JsonExceptionMapperTest method testToResponse_NotFoundException.

@Test
public void testToResponse_NotFoundException() {
    final Response res = this.mapper.toResponse(new ResourceNotFoundException(ResourceKey.from("app:/a/b/c")));
    assertEquals(404, res.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ResourceNotFoundException(com.enonic.xp.resource.ResourceNotFoundException) Test(org.junit.jupiter.api.Test)

Example 2 with ResourceNotFoundException

use of com.enonic.xp.resource.ResourceNotFoundException in project xp by enonic.

the class ResponseProcessorExecutor method execute.

public PortalResponse execute(final ResponseProcessorDescriptor filter, final PortalRequest request, final PortalResponse response) {
    final String filterName = filter.getName();
    final String filterJsPath = "/site/processors/" + filterName + ".js";
    final ResourceKey script = ResourceKey.from(filter.getApplication(), filterJsPath);
    final ScriptExports filterExports;
    try {
        filterExports = this.scriptService.execute(script);
    } catch (ResourceNotFoundException e) {
        LOG.warn("Filter execution failed: {}", e.getMessage());
        throw e;
    }
    final boolean exists = filterExports.hasMethod(RESPONSE_PROCESSOR_METHOD);
    if (!exists) {
        throw new RenderException("Missing exported function [{0}] in response filter [{1}]", RESPONSE_PROCESSOR_METHOD, filterJsPath);
    }
    final ApplicationKey previousApp = request.getApplicationKey();
    // set application of the filter in the current context PortalRequest
    request.setApplicationKey(filter.getApplication());
    PortalRequestAccessor.set(request);
    try {
        return Tracer.trace("controllerScript", () -> executeFilter(filterExports, request, response));
    } finally {
        PortalRequestAccessor.remove();
        request.setApplicationKey(previousApp);
    }
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) RenderException(com.enonic.xp.portal.impl.rendering.RenderException) ScriptExports(com.enonic.xp.script.ScriptExports) ResourceNotFoundException(com.enonic.xp.resource.ResourceNotFoundException) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 3 with ResourceNotFoundException

use of com.enonic.xp.resource.ResourceNotFoundException in project xp by enonic.

the class NamedTaskScriptFactoryImpl method doCreate.

private NamedTaskScript doCreate(final TaskDescriptor descriptor, final PropertyTree data) {
    final ResourceKey scriptResourceKey = ResourceKey.from(descriptor.getApplicationKey(), TASKS_PATH_PREFIX + descriptor.getName() + "/" + descriptor.getName() + ".js");
    final ScriptExports exports;
    try {
        exports = this.scriptService.execute(scriptResourceKey);
    } catch (ResourceNotFoundException e) {
        throw new TaskNotFoundException(descriptor.getKey(), "Missing task script");
    }
    final boolean exists = exports.hasMethod(NamedTaskScript.SCRIPT_METHOD_NAME);
    if (!exists) {
        throw new TaskNotFoundException(descriptor.getKey(), "Missing exported function '" + NamedTaskScript.SCRIPT_METHOD_NAME + "' in task script");
    }
    return new NamedTaskScript(exports, descriptor, data);
}
Also used : TaskNotFoundException(com.enonic.xp.task.TaskNotFoundException) ScriptExports(com.enonic.xp.script.ScriptExports) ResourceNotFoundException(com.enonic.xp.resource.ResourceNotFoundException) ResourceKey(com.enonic.xp.resource.ResourceKey)

Aggregations

ResourceNotFoundException (com.enonic.xp.resource.ResourceNotFoundException)3 ResourceKey (com.enonic.xp.resource.ResourceKey)2 ScriptExports (com.enonic.xp.script.ScriptExports)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)1 TaskNotFoundException (com.enonic.xp.task.TaskNotFoundException)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.jupiter.api.Test)1