users@jersey.java.net

Re: [Jersey] POST to RESTful services written using Jersey API

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 18 Mar 2010 09:30:21 +0100

On Mar 18, 2010, at 4:30 AM, Rameswara Sashi Kiran Challa wrote:

> Hi..
>
> Could someone please tell me what I am doing wrong in here.
>
> I am trying to write a simpe shell script in which I am calling the
> RESTful services that I have written using Jersey API. I am trying
> to call these services without using the Jersey Client API. I had
> earlier written a client using Jersey API and it all worked fine.
> Now I am trying to do simple curl Post to my service. The error(HTTP
> status 415) I get suggests that I am doing something wrong in
> specifying the Media Types.
>
> With Jersey Client API I got it working like this:
> String gaussianoutput =
> webResource2
> .accept
> (MediaType
> .TEXT_PLAIN_TYPE
> ,MediaType
> .APPLICATION_XML_TYPE
> ).type(MediaType.APPLICATION_XML_TYPE).post(String.class,s);
>
> What Media Types or Content0Type should I be specifying while using
> curl ?? If anybody has already figured out please help me out
>
> Here is my shell script calling service 1:
>
> abc=`curl http://gf18...:8080/InChIto3D/inchi/3dstructure?
> InChIstring=$inchi` //returns an xml string
>
> echo $abc //this works fine.
>
> Passing(Posting) this $abc to service 2
>
> def=`curl -d $abc -H "Content-Type:text/xml" http://gf18...:8080/
> CML2Gauss/cml3d/gaussinput`
>

Using are using the wrong media type for the Content-Type. Change the
above to:

   def=`curl -d $abc -H "Content-Type: application/xml" http://
gf18...:8080/CML2Gauss/cml3d/gaussinput`

Your implementation using the Jersey client API will send the
following headers:

  Accept: text/plain, application/xml
  Content-Type: application/xml

Paul.

> Error I get:
> ....
> ....
> <h1>HTTP Status 415 - </h1><HR size="1"
> noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b>
> <u></u></p><p><b>description</b> <u>The server refused this request
> because the request entity is in a format not supported by the
> requested resource for the requested method ().</u></p><HR size="1"
> noshade="noshade"><h3>Apache Tomcat/6.0.26</h3></body></html>
>
>
>
> Thanks a lot
>
> Regards
>
>
> --
> Sashikiran Challa
> MS Cheminformatics,
>
>