Ejemplo n.º 1
0
 @POST
 @Path(PATH_RELATIONSHIP_EXTENSION_METHOD)
 public Response invokeRelationshipExtension(
     @PathParam("name") String name,
     @PathParam("method") String method,
     @PathParam("relationshipId") long relationshipId,
     String data) {
   try {
     return output.ok(
         this.invokeRelationshipExtension(
             relationshipId, name, method, input.readParameterList(data)));
   } catch (RelationshipNotFoundException e) {
     return output.notFound(e);
   } catch (BadInputException e) {
     return output.badRequest(e);
   } catch (PluginLookupException e) {
     return output.notFound(e);
   } catch (BadPluginInvocationException e) {
     return output.badRequest(e.getCause());
   } catch (PluginInvocationFailureException e) {
     return output.serverError(e.getCause());
   } catch (Exception e) {
     return output.serverError(e.getCause());
   }
 }
Ejemplo n.º 2
0
  @POST
  public Response exec(@Context InputFormat input, String data) {
    Map<String, Object> args;
    try {
      args = input.readMap(data);
    } catch (BadInputException e) {
      return output.badRequest(e);
    }

    if (!args.containsKey("command")) {
      return Response.status(Status.BAD_REQUEST)
          .entity("Expected command argument not present.")
          .build();
    }

    ScriptSession scriptSession;
    try {
      scriptSession = getSession(args);
    } catch (IllegalArgumentException e) {
      return output.badRequest(e);
    }

    log.debug(scriptSession.toString());
    try {
      Pair<String, String> result = scriptSession.evaluate((String) args.get("command"));
      List<Representation> list =
          new ArrayList<Representation>(
              asList(
                  ValueRepresentation.string(result.first()),
                  ValueRepresentation.string(result.other())));

      return output.ok(new ListRepresentation(RepresentationType.STRING, list));
    } catch (Exception e) {
      List<Representation> list =
          new ArrayList<Representation>(
              asList(
                  ValueRepresentation.string(e.getClass() + " : " + e.getMessage() + "\n"),
                  ValueRepresentation.string(null)));
      return output.ok(new ListRepresentation(RepresentationType.STRING, list));
    }
  }
Ejemplo n.º 3
0
 @POST
 @Path(PATH_GRAPHDB_EXTENSION_METHOD)
 public Response invokeGraphDatabaseExtension(
     @PathParam("name") String name, @PathParam("method") String method, String data) {
   try {
     return output.ok(
         this.invokeGraphDatabaseExtension(name, method, input.readParameterList(data)));
   } catch (BadInputException e) {
     return output.badRequest(e);
   } catch (PluginLookupException e) {
     return output.notFound(e);
   } catch (BadPluginInvocationException e) {
     return output.badRequest(e.getCause());
   } catch (SyntaxException e) {
     return output.badRequest(e.getCause());
   } catch (PluginInvocationFailureException e) {
     return output.serverError(e.getCause());
   } catch (Exception e) {
     return output.serverError(e);
   }
 }