use of org.neo4j.server.rest.repr.BadInputException 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);
}
}
use of org.neo4j.server.rest.repr.BadInputException in project neo4j by neo4j.
the class URLTypeCaster method getList.
@Override
Object[] getList(GraphDatabaseAPI graphDb, ParameterList parameters, String name) throws BadInputException {
URI[] uris = parameters.getUriList(name);
URL[] urls = new URL[uris.length];
try {
for (int i = 0; i < urls.length; i++) {
urls[i] = uris[i].toURL();
}
} catch (MalformedURLException e) {
throw new BadInputException(e);
}
return urls;
}
use of org.neo4j.server.rest.repr.BadInputException in project neo4j by neo4j.
the class ConsoleService method exec.
@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));
}
}
use of org.neo4j.server.rest.repr.BadInputException in project neo4j by neo4j.
the class UserService method setPassword.
@POST
@Path("/{username}/password")
public Response setPassword(@PathParam("username") String username, @Context HttpServletRequest req, String payload) {
Principal principal = req.getUserPrincipal();
if (principal == null || !principal.getName().equals(username)) {
return output.notFound();
}
final Map<String, Object> deserialized;
try {
deserialized = input.readMap(payload);
} catch (BadInputException e) {
return output.response(BAD_REQUEST, new ExceptionRepresentation(new Neo4jError(Status.Request.InvalidFormat, e.getMessage())));
}
Object o = deserialized.get(PASSWORD);
if (o == null) {
return output.response(UNPROCESSABLE, new ExceptionRepresentation(new Neo4jError(Status.Request.InvalidFormat, String.format("Required parameter '%s' is missing.", PASSWORD))));
}
if (!(o instanceof String)) {
return output.response(UNPROCESSABLE, new ExceptionRepresentation(new Neo4jError(Status.Request.InvalidFormat, String.format("Expected '%s' to be a string.", PASSWORD))));
}
String newPassword = (String) o;
try {
SecurityContext securityContext = getSecurityContextFromUserPrincipal(principal);
if (securityContext == null) {
return output.notFound();
} else {
UserManager userManager = userManagerSupplier.getUserManager(securityContext);
userManager.setUserPassword(username, newPassword, false);
}
} catch (IOException e) {
return output.serverErrorWithoutLegacyStacktrace(e);
} catch (InvalidArgumentsException e) {
return output.response(UNPROCESSABLE, new ExceptionRepresentation(new Neo4jError(e.status(), e.getMessage())));
}
return output.ok();
}
use of org.neo4j.server.rest.repr.BadInputException in project neo4j by neo4j.
the class ParameterList method getList.
private <T> T[] getList(String name, GraphDatabaseAPI graphDb, Converter<T> converter) throws BadInputException {
Object value = data.get(name);
if (value == null) {
return null;
}
List<T> result = new ArrayList<>();
if (value instanceof Object[]) {
for (Object element : (Object[]) value) {
result.add(converter.convert(graphDb, element));
}
} else if (value instanceof Iterable<?>) {
for (Object element : (Iterable<?>) value) {
result.add(converter.convert(graphDb, element));
}
} else {
throw new BadInputException(name + " is not a list");
}
return result.toArray(converter.newArray(result.size()));
}
Aggregations