users@jersey.java.net

[Jersey] Re: Rest Post Unsupported Media Type

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Tue, 28 Jun 2011 14:18:03 +0200

Hi Peter,

please see inline...

On 06/28/2011 12:12 PM, peterwkc wrote:
> Jakub Podlesak-2 wrote:
>> Hi Peter,
>>
>> ad 1) the content-type should be set to application/xml rather than just
>> xml.
>> some server log snippet would also be handy to such requests
>>
>> ad 2) i do not quite understand the question, you are setting the order id
>> on the CustOrderResource returned by the sub-locator method
>> what else would you want to pass?
>>
>>
> 1.
> I have set them using this annotation

I meant the content-type header sent by the client.

> @POST
> @Consumes({MediaType.WILDCARD, MediaType.APPLICATION_JSON,
> MediaType.APPLICATION_XML,
> MediaType.APPLICATION_FORM_URLENCODED}) for create order function but it
Another suspicious thing above is you are mixing application/json,
application/xml
and application/x-www-form-urlencoded media types. I guess Custorder
is a generic JAXB bean. I am afraid there is no default message body
reader for that.

> just rerun unsupported media type. What wrong with it ?

Again: what is the request header sent by the client?
Can you see anything in a log file?

> 2. @Path("{orderID}")
> public CustOrderResource ReadSingleCustomerOrder(@PathParam("orderID")
> String orderID) {
>
> int userOrderID = Integer.parseInt(orderID);
> int myOrderID = myCustOrderDAO.count();
>
> CustOrderResource myCustorder = null;
>
> if(userOrderID> myOrderID
> || myCustOrderDAO.find(orderID) == null) {
> throw new OrderNotFoundException("Order ID Not Found");
> }
>
> if(!mySecurityContext.isUserInRole("admin")) {
> // Propogates to specific resource class
> myCustorder = myResourceContext.getResource(CustOrderResource.class);
> myCustorder.setOrderID(orderID);
> }
>
> return myCustorder;
> }
>
> This function is redirect to sub resource locator based on the HTTP method
> like DELETE or POST where delete will called the deleteOrder function with
> the order data.

For the delete method, the order id is already passed to the getResource
method.
The instance returned from there is fully managed by you and it is the
instance,
which gets eventually invoked to fulfill the HTTP request. You have to
keep the id there.

For the POST method, you can still define an entity parameter in the
corresponding resource method:

public class CustOrderResource {

   @POST
   public CustOrder postMethod(CustOrder order) {
      ...
   }

HTH,

~Jakub

> The order data where i need to pass from resource class to sub resource
> locator method otherwise i cannot query the database.
>
> Another scenario is when i update order i need the updater order data too
> when the jersey servlet will call the updateOrder function.
>
> How to retrieve the data in message body ?
>
> Thanks.
>
>
>
>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Rest-Post-Unsupported-Media-Type-tp6499271p6524282.html
> Sent from the Jersey mailing list archive at Nabble.com.
>