users@jersey.java.net

Re: [Jersey] HowTo get HTTP Header from a POST response?

From: Bruno Luiz Pereira da Silva <blpsilva_at_gmail.com>
Date: Sat, 17 May 2008 12:57:17 -0300

I don't know which client API you're using, but using commons-http-client,
this is pretty easy.

I'll show a little example of how you could do it, but I'll skip some
details.

HttpClient client = new HttpClient(); // the class that allows you to
execute HTTP requests

PostMethod method = new PostMethod(uri); // creating a new POST request, to
a given URI

StringRequestEntity requestEntity = new StringRequestEntity(requestXML,
"text/xml", "UTF-8"); // defining the request body, specifying the context
type and encoding

method.setRequestEntity(requestEntity); // assigning the request body to the
POST method

int statusCode = client.executeMethod(method); // here the request is
submitted to the server

Header[] responseHeaders = method.getResponseHeaders(); // getting all the
response headers

for(Header header : responseHeaders){
   System.out.println(header.getName() + " : " + header.getValue()); //
printing all the response headers
}

Header myCustomHeader = method.getResponseHeader("myCustomHeader"); // this
will give you the header you want

-- 
Regards,
Bruno Luiz Pereira da Silva
blpsilva_at_gmail.com
http://brunopereira.com.br
On Sat, May 17, 2008 at 12:42 PM, Markus Kolb <java-sun_at_tower-net.de> wrote:
> Hello,
>
> I need some help...
> My client does a POST and in the response from WebService I've inserted
> a custom X Header with Response.ok().header(...).build()
> OK, that's fine, the header is there.
> How does the client get the custom X Header?
> I tried to get it from WebResource with the head().
> But there is only getLanguage(), getStatus(), etc. and nothing to get a
> custom header?!
> How can this be done?
>
> Many thanks
> Markus
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>