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