users@jersey.java.net

[Jersey] Re: Best way to diagnose a 400 error on POST

From: Jason Erickson <jason_at_jasonerickson.com>
Date: Fri, 10 Dec 2010 15:27:25 -0600

I did switch the argument type to String (but keeping the same media type) and the JSON string came through with no problem. The problem is that the error gives no indication of what is wrong with the string. How would one unit test marshalling and unmarshalling the JSON strings?

On Dec 10, 2010, at 1:25 PM, Kevin Duffey wrote:

> Hmm..I'd say make sure the client Content-Type is set correctly..but that would probably be a different response code (405? forget the code for media type not supported). If it's not even getting inside the method.. can you try using XML just to rule out if it is indeed your json format or not?
>
> You can also add a filter before the methods get called, and check there to see what is going on perhaps.
>
>
> --- On Thu, 12/9/10, Jason Erickson <jason_at_jasonerickson.com> wrote:
>
> From: Jason Erickson <jason_at_jasonerickson.com>
> Subject: [Jersey] Best way to diagnose a 400 error on POST
> To: users_at_jersey.java.net
> Date: Thursday, December 9, 2010, 9:10 PM
>
> Hi. I have a REST method defined thus:
> @POST
> @Consumes(MediaType.APPLICATION_JSON)
> public Response addObservationSession(ObservationSession session, @Context UriInfo uriInfo) throws URISyntaxException
> {
> .. do some stuff
> return Response.created(new URI("/" + session.getId())).build();
>
> }
>
> This is giving me a 400 error when I call it. Clearly it doesn't like my JSON string, but it's hard for me to tell what's wrong with it (or if it's not the string, maybe it's the header or who knows). I can't put a breakpoint in my code because it never gets to my code. What's the best way to get a clue?
>