The error I am getting is ".No operation matching request path...." though 
@POST is there with the @PATH annotation that should match.

Thanks.

Sadhana Jain
Sr. Software Engineer


Rovi Corporation
795 Folsom St, Suite 200
San Francisco, CA 94107
Direct: 415.247.5023 | Mobile: 925.212.6495
[email protected]
rovicorp.com


Rovi. The new name for Macrovision.


-----Original Message-----
From: Sadhana Jain [mailto:[email protected]] 
Sent: Tuesday, September 15, 2009 12:16 PM
To: [email protected]
Subject: JAX-RS POST method example 

Hi All,

I am new to using JAX-RS and CXF. I was wondering if anyone can point me 
To an example that uses POST method as I am running into a problem when using 
POST. Cxf is not able to match to request uri to a method annotated with @POST 
though @GET works ok.
Does anyone know a known issue using POST?

Any sample code will be great help.

Thanks,
Sadhana

Sadhana Jain
Sr. Software Engineer


Rovi Corporation
795 Folsom St, Suite 200
San Francisco, CA 94107
Direct: 415.247.5023 | Mobile: 925.212.6495
[email protected]
rovicorp.com


Rovi. The new name for Macrovision.


-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]] 
Sent: Tuesday, September 15, 2009 9:30 AM
To: Pydipati, Karuna; [email protected]; Sergey Beryozkin
Subject: Re: CXF -Strange HTTP PUT (REST) behavior

Hi,

@FormParams can only be used to refer to field values in form submissions, with 
 application/x-www-form-urlencoded (or similar).
In your case you just need to remove  @FormParam. A given JAXRS method can 
refer to a request body (sent as part of POST or PUT. etc) by either not 
annotating a given parameter with JAXRS param annotations, like this :

 @PUT
 @Path("{userGuid}/contacts/{contactId}")
 @Consumes({"application/json", "application/xml"})
 @Produces({"application/json", "application/xml"})
 public Response updateContact(@PathParam("userGuid")String userGuid, 
@PathParam("contactId")String contactId, UserContact contact);

or by annotating parameters with @FormParam as in your case but note a 
different @Consumes value :

 @Consumes("application/x-www-form-urlencoded")
 @Produces({"application/json", "application/xml"})
 public Response updateContact(@PathParam("userGuid")String userGuid, 
@PathParam("contactId")String contactId, 
                                               @FormParam UserContact contact);

So if you need to your web app to handle both 'plain' requests and form 
requests (those meeting application/x-www-form-urlencoded  rules, name=value 
pairs) then you need to have both methods as suggested above, otherwise the 
updated first method will do. 



cheers, Sergey
  ----- Original Message ----- 
  From: Pydipati, Karuna 
  To: Sergey Beryozkin ; [email protected] ; Sergey Beryozkin 
  Sent: Tuesday, September 15, 2009 4:40 PM
  Subject: RE: CXF -Strange HTTP PUT (REST) behavior


  Thanks a lot Sergey for your quick response.

  Yes, you right. We have the following method

   @PUT
   @Path("{userGuid}/contacts/{contactId}")
   @Consumes({"application/json", "application/xml"})
   @Produces({"application/json", "application/xml"})
   public Response updateContact(@PathParam("userGuid")String userGuid, 
@PathParam("contactId")String contactId, @FormParam("contact")UserContact 
contact);

  What you are suggesting is that we should have another method like this

   @PUT
   @Path("{userGuid}/contacts/{contactId}")
   public Response updateContact(@PathParam("userGuid")String userGuid, 
@PathParam("contactId")String contactId, @FormParam("contact")UserContact 
contact);

  My question is...how is it working..if I package in another buy.ear or 
cog.ear files ....where as it fails userapi.ear? I am still grappling with this 
puzzle. Pardon my ignorance on @FormParam and Content-type area. Could you 
elaborate your answer a bit further?



  Regards

  Karuna Pydipati

  StubHub/eBay - Platform & Services

  Phone: (415)222-8752

  Email: [email protected]







------------------------------------------------------------------------------
  From: Sergey Beryozkin [mailto:[email protected]] 
  Sent: Tuesday, September 15, 2009 2:32 AM
  To: Pydipati, Karuna; [email protected]; Sergey Beryozkin
  Subject: Re: CXF -Strange HTTP PUT (REST) behavior


  Hi

  What is most likely happening is that you have a method parameter annotated 
with @FormParam.
  In that case no message body readers are checked (which would've prevented 
the NPE) but the runtime checks if its a application/x-www-form-urlencoded 
request and if not then it assumes straight away it's a mulltipart/form-data 
request (so this will have to be fixed so that an unsupported media type 
exception is thrown instead).

  So you just need to remove @FormParams from the @PUT-annotated method. If you 
do need to keep @FormParams, then just introduce another method which accepts 
PUT and application/json (@Consumes) media type

  hope it helps, Sergey

  ----- Original Message ----- 
    From: Pydipati, Karuna 
    To: [email protected] ; Sergey Beryozkin 
    Sent: Tuesday, September 15, 2009 6:28 AM
    Subject: CXF -Strange HTTP PUT (REST) behavior


    Hi

    I posted this in a separate thread today. Sorry. After some investigation, 
I found this. Please help me.

    I see a strange behavior in HTTP PUT (REST). When I tried CXF-2.2.2 
deploying userapi.ear (with "user" as context-root in jboss), it is failing 
with following error. If I rename same ear file to something else such as 
cog.ear (with 'cog' as context-root), it started working. Is 'user' a reserve 
word in HTTP/CXF/REST world? Can't I use "user' word for my application for 
"Address"?

    [in my app, cog.ear contains cog.war. Same way, user.ear contains user.war 
too]

    17:28:54,290 ERROR [STDERR] Sep 14, 2009 5:28:54 PM 
org.apache.cxf.interceptor.LoggingInInterceptor logging

    INFO: Inbound Message

    ----------------------------

    ID: 3

    Address: /userapi/user/users/6E2D6D23D40D2FC9E04400144F8AE084/contacts/2

    Encoding: UTF-8

    Content-Type: application/json

    Headers: {content-length=[536], connection=[keep-alive], 
cache-control=[no-cache], host=[localhost:28080], user-agent=[J ava/1.5.0_14], 
pragma=[no-cache], Content-Type=[application/json], 
content-type=[application/json], Accept=[text/html, i mage/gif, image/jpeg, *; 
q=.2, */*; q=.2], content-language=[en-US]}

    Payload: { "UserContact": { "ContactId": 111111, "UserId": 11111, 
"FirstName": "xxxxxx",

    "LastName": "xxxxxx", "Street": "Sharynne Ln.", "AptNumber": 5350, "City": 
"Malibu",

    "State": "CA", "Zip": 90265, "Phone1": "xxxxxxx", "Phone2": "xxxxxxx", 
"Company": "Ebay", "Email": "[email protected]", "DateAdded": "24-OCT-02", 
"Active": 1, "Note": "Note", "Fax": "56356", "Country": "US",

    "DefaultContact": 1, "PaymentContact": 1, "Title":"Mr.", 
"LastModifiedDate": "10-SEP-09", "ChkPmtToCo": 0

    }}

    --------------------------------------

    17:28:54,290 ERROR [STDERR] Sep 14, 2009 5:28:54 PM 
org.apache.cxf.phase.PhaseInterceptorChain doIntercept

    INFO: Interceptor has thrown exception, unwinding now 
java.lang.NullPointerException

    at 
org.apache.cxf.attachment.AttachmentUtil.createAttachment(AttachmentUtil.java:136)

    at 
org.apache.cxf.jaxrs.ext.MessageContextImpl.createAttachments(MessageContextImpl.java:135)

    at 
org.apache.cxf.jaxrs.ext.MessageContextImpl.get(MessageContextImpl.java:58)

    at 
org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils.getMultipartBody(AttachmentUtils.java:54)

    at 
org.apache.cxf.jaxrs.utils.JAXRSUtils.processFormParam(JAXRSUtils.java:590)


    Regards

    Karuna Pydipati

    StubHub/eBay - Platform & Services

    Phone: (415)222-8752

    Email: [email protected]



Reply via email to