Robles
Robles

Reputation: 123

I generate a 400 Response with Jersey but I dont get it returned

I'm trying to program a web service with java and jersey. Recently I noticed that sometimes, after creating an error 400 response, I dont get anything returned from server.

For example, with this function I get a 201 code without problems, but when I try to get the 400 response, I get stuck waiting for a response until I get a timeout.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
public Response registerUser(String json) {
    Gson gson = new Gson();
    try {
        RegistryData r = gson.fromJson(json, RegistryData.class);
        new RegisterValidator().validate(r);
        // new UserDao().addUser(new User(r));
        return Response.ok(gson.toJson(r), MediaType.APPLICATION_JSON).status(Status.CREATED).build();
    } catch (JsonSyntaxException e) {
        e.printStackTrace();
        return Response.status(Status.BAD_REQUEST).entity("ERROR: BAD REQUEST").build();
    } catch (ValidationException e) {
        return Response.status(Response.Status.BAD_REQUEST).entity("ERROR: " + e.getMessage())
                .type(MediaType.TEXT_PLAIN).build();
    }
}

I'm using Tomcat 7, Java 7, Jersey 1.19 and I'm testing with Advanced Rest Client plugin for Chrome.

Upvotes: 1

Views: 588

Answers (1)

ernest_k
ernest_k

Reputation: 45339

I've encountered similar issues with this plugin, seeing it "getting stuck" when the server responds with an error.

You could try an alternative client, such as curl (if you're on *nix), RestClient (http://code.fosshub.com/WizToolsorg-RESTClient/downloads), or other tools you can find online.

Upvotes: 1

Related Questions