@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)); } }