users@jersey.java.net

[Jersey] Re: Rest Post Unsupported Media Type

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 07 Jul 2011 11:42:53 +0200

Hi Peter,

please see inline...

On 07/05/2011 11:37 AM, peterwkc wrote:
> At this moment, let focus on question 1 first and will proceed to question 2
> after i have solved the question 1.
>
> 1. I have tested the function using the jersey client api and i found out
> that is the parameter problem in the
>
> @POST
> @Consumes(MediaType.APPLICATION_XML)
> public Response createOrder(Custorder myCustOrder, @Context UriInfo
> myUriInfo) {}
>
> When i removed the myCustOrder parameter, everything works fine but jersey
> runtime return bad request with the Custorder parameter.
>
> The Custorder POJO is like this :
>
> @Entity
> @Table(name = "CUSTORDER", catalog = "", schema = "PETERWKC")
> @XmlRootElement
> public class Custorder implements Serializable {} and has @XMLElement for
> every attributes.
>
>
> I tested the createOrder function like this :
>
> result = resource.type(MediaType.APPLICATION_XML)
> .accept(MediaType.APPLICATION_XML)
> .entity(new File(entity))
> .post(String.class);
> System.out.println("Result : " + result);
>
> What wrong or problem with it ?

It is hard to tell, as rather than using Jersey's XML message body writer,
you are sending an (already populated) XML file to the server.
And i do not see the file attached to your message.

I guess the XML file does not match what is expected on the server side.

To better align your client and server code, you might want to change
the above
to something like:

Custorder co = createCustorder();
result = resource.type(MediaType.APPLICATION_XML)
                             .accept(MediaType.APPLICATION_XML)
                            .entity(co)
                            .post(String.class);

HTH,

~Jakub

> Please help.
>
> Thanks.
>
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Rest-Post-Unsupported-Media-Type-tp6499271p6549038.html
> Sent from the Jersey mailing list archive at Nabble.com.
>