Search in sources :

Example 1 with EvaluationException

use of org.neo4j.server.rest.domain.EvaluationException in project neo4j by neo4j.

the class RestfulGraphDatabase method createPagedTraverser.

@POST
@Path(PATH_TO_CREATE_PAGED_TRAVERSERS)
public Response createPagedTraverser(@PathParam("nodeId") long startNode, @PathParam("returnType") TraverserReturnType returnType, @QueryParam("pageSize") @DefaultValue(FIFTY_ENTRIES) int pageSize, @QueryParam("leaseTime") @DefaultValue(SIXTY_SECONDS) int leaseTimeInSeconds, String body) {
    try {
        validatePageSize(pageSize);
        validateLeaseTime(leaseTimeInSeconds);
        String traverserId = actions.createPagedTraverser(startNode, input.readMap(body), pageSize, leaseTimeInSeconds);
        URI uri = new URI("node/" + startNode + "/paged/traverse/" + returnType + "/" + traverserId);
        return output.created(new ListEntityRepresentation(actions.pagedTraverse(traverserId, returnType), uri.normalize()));
    } catch (EvaluationException e) {
        return output.badRequest(e);
    } catch (BadInputException e) {
        return output.badRequest(e);
    } catch (NotFoundException e) {
        return output.notFound(e);
    } catch (URISyntaxException e) {
        return output.serverError(e);
    }
}
Also used : BadInputException(org.neo4j.server.rest.repr.BadInputException) StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) NotFoundException(org.neo4j.graphdb.NotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) EvaluationException(org.neo4j.server.rest.domain.EvaluationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ListEntityRepresentation(org.neo4j.server.rest.repr.ListEntityRepresentation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with EvaluationException

use of org.neo4j.server.rest.domain.EvaluationException in project neo4j by neo4j.

the class JavascriptExecutor method execute.

@Override
public Object execute(Map<String, Object> variables) throws EvaluationException {
    Context cx = Context.enter();
    try {
        Scriptable scope = cx.newObject(prototype);
        scope.setPrototype(prototype);
        if (variables != null) {
            for (String k : variables.keySet()) {
                scope.put(k, scope, variables.get(k));
            }
        }
        Object out = compiledScript.exec(cx, scope);
        if (out instanceof NativeJavaObject) {
            return ((NativeJavaObject) out).unwrap();
        } else if (out instanceof Undefined) {
            return null;
        } else {
            return out;
        }
    } catch (RhinoException e) {
        throw new EvaluationException("Failed to execute script, see nested exception.", e);
    } finally {
        Context.exit();
    }
}
Also used : Context(org.mozilla.javascript.Context) Undefined(org.mozilla.javascript.Undefined) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) RhinoException(org.mozilla.javascript.RhinoException) EvaluationException(org.neo4j.server.rest.domain.EvaluationException) Scriptable(org.mozilla.javascript.Scriptable) NativeJavaObject(org.mozilla.javascript.NativeJavaObject)

Aggregations

EvaluationException (org.neo4j.server.rest.domain.EvaluationException)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Context (org.mozilla.javascript.Context)1 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)1 RhinoException (org.mozilla.javascript.RhinoException)1 Scriptable (org.mozilla.javascript.Scriptable)1 Undefined (org.mozilla.javascript.Undefined)1 NotFoundException (org.neo4j.graphdb.NotFoundException)1 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)1 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)1 BadInputException (org.neo4j.server.rest.repr.BadInputException)1 ListEntityRepresentation (org.neo4j.server.rest.repr.ListEntityRepresentation)1