users@jersey.java.net

[Jersey] Re: How to set error response code from Rest web service and get it by Jersey client

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 07 Jul 2011 15:02:36 +0200

Hi Jitesh,

i dunno, that is really strange.
Please try to download [1] and apply the attached patch.

Then see the header sub-resource method in the HelloWorldResource class
and the appropriate HelloWorldWebAppTest#testHeader() method.

I have also added request logging, so that after mvn clean install,
you should see something like follows:

--8<--
INFO: 1 * Server in-bound request
1 > GET http://localhost:9998/helloworld-webapp/helloworld/header
1 > appkey: appKeyVal
1 > user-agent: Java/1.6.0_24
1 > host: localhost:9998
1 > accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
1 > connection: keep-alive
1 >
-->8--

Which has the appKey header included in the request coming from the test
client.

To test manually, launch mvn embedded-glassfish:run

and

curl -HappKey:app1 http://localhost:8080/helloworld-webapp/helloworld/header

should give you: app1

If the above work for you, you might want to re-run the web application
on your
container. If it breaks there, i guess the issue is container specific.

What container do you use?

~Jakub

[1]http://download.java.net/maven/2/com/sun/jersey/samples/helloworld-webapp/1.9-SNAPSHOT/helloworld-webapp-1.9-SNAPSHOT-project.zip


On 07/04/2011 06:36 AM, Jitesh Sinha -X (jisinha - Siliconweb Inc. at
Cisco) wrote:
>
> Hi Jakub,
>
> Thanks for your response. I tried HeaderParam code that you mentioned
> in your email and it still does not work. I still get appKey as null.
>
> Do I need to do something else?
>
> Thanks
>
> -Jitesh
>
> *From:*Jakub Podlesak [mailto:jakub.podlesak_at_oracle.com]
> *Sent:* Wednesday, June 29, 2011 10:47 PM
> *To:* users_at_jersey.java.net
> *Subject:* [Jersey] Re: How to set error response code from Rest web
> service and get it by Jersey client
>
> Hi Jitesh,
>
> the client side looks fine.
>
> On the server side, you might want to consume the header
> parameter with the @HeaderParam annotation. E.g.
>
> @GET
> public Response getMethod(@HeaderParam("appKey") String appKey) {
> ...
> }
>
> ~Jakub
>
> On 06/29/2011 02:32 AM, Jitesh wrote:
>
> Sorry one correction --
>
> On serverside it is
>
> String appKey = request.getHeader("appKey") ;
>
> *From:*Jitesh Sinha -X (jisinha - Siliconweb Inc. at Cisco)
> *Sent:* Tuesday, June 28, 2011 5:26 PM
> *To:* 'Pavel Bucek-2 [via Jersey]'
> *Subject:* RE: How to set error response code from Rest web service
> and get it by Jersey client
>
> Thanks Pavel.
>
> How do we send header parameters through GET request?
>
> I am using following code and on server side I get appKey as null --
>
> This is client side code -
>
> Client client = Client.create();
>
> WebResource service = client.resource(URL);
>
> MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
>
> queryParams.add("transactionId",testCommand.getTransactionId()) ;
>
> ClientResponse response =
> service.queryParams(queryParams).header("appKey",appkey).get(ClientResponse.class);
>
> Server Side --
>
> String appKey = request.getParameter("appKey") ;
>
> Is something wrong in above code?
>
> Thanks
>
> -Jitesh
>
> *From:*Pavel Bucek-2 [via Jersey] [mailto:[hidden email]
> </user/SendEmail.jtp?type=node&node=6527169&i=0>]
> *Sent:* Tuesday, June 28, 2011 12:53 PM
> *To:* Jitesh Sinha -X (jisinha - Siliconweb Inc. at Cisco)
> *Subject:* Re: How to set error response code from Rest web service
> and get it by Jersey client
>
> http://jersey.java.net/nonav/apidocs/latest/jersey/javax/ws/rs/core/Response.html
> http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/client/ClientResponse.html
> http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e363
>
>
> On 6/28/11 9:31 PM, Jitesh Sinha -X (jisinha - Siliconweb Inc. at Cisco)
> wrote:
> > Is there a way to set error code and message by Rest API and then to
> > retrieve it by using Jersey client?
> > Currently I know only about Response.ok(variable).build() which is
> > supposed to be called when request has been processed ok.
> >
> > Thanks
> > -Jitesh
> >
>
>
> ------------------------------------------------------------------------
>
> *If you reply to this email, your message will be added to the
> discussion below:*
>
> http://jersey.576304.n2.nabble.com/How-to-post-a-file-and-other-form-fields-by-Jersey-client-tp6502947p6526332.html
>
>
> To unsubscribe from How to post a file and other form fields by Jersey
> client, click here.
>
> ------------------------------------------------------------------------
>
> View this message in context: RE: How to set error response code from
> Rest web service and get it by Jersey client
> <http://jersey.576304.n2.nabble.com/How-to-post-a-file-and-other-form-fields-by-Jersey-client-tp6502947p6527169.html>
> Sent from the Jersey mailing list archive
> <http://jersey.576304.n2.nabble.com/> at Nabble.com.
>