You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by rodgersh <hu...@lmco.com> on 2013/08/07 02:51:16 UTC

How to get HTTP response headers when using JAXRSClientFactoryBean to create JAXRS Client

I am using JAXRSClientFactoryBean to programmatically create my JAXRS client
and want to get the Content-Disposition HTTP header from the response when I
invoke a method on the client.

I am programmatically creating my JAXRS client as follows:

       JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
        bean.setServiceClass(Wcs.class);
        bean.setAddress("http://my.site.com/myservice");
        MyInterface proxy = bean.create(MyInterface.class);

The implementation of MyInterface has this method:

    @Override
    @POST
    @Consumes({"text/xml", "application/xml"})
    public InputStream getCoverage(GetCoverage request) throws WcsException
{

        InputStream is = proxy.getCoverage(request);
        if (httpServletResponse != null) {
            String contentDisposition =
httpServletResponse.getHeader("Content-Disposition");
        }

        return is;
    }

I have tried injecting HttpServletResponse using @Context and I have tried
injecting MessgageContext using @Context (both in a declaration and with a
setter method like so:

    @Context
    public void setHttpServletResponse(HttpServletResponse
httpServletResponse) {
        LOGGER.debug("Setting HttpServletResponse");
        this.httpServletResponse = httpServletResponse;
    }

The context is never injected, it is always null. I verified with a debugger
that the setter method was not called.

What might I be doing wrong? I am using CXF version 2.7.5

Thanks.

Hugh



--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-get-HTTP-response-headers-when-using-JAXRSClientFactoryBean-to-create-JAXRS-Client-tp5732047.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to get HTTP response headers when using JAXRSClientFactoryBean to create JAXRS Client

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

You mean from the actual response, when using a proxy ?

You can do it like this:

Response r = WebClient.getClient(proxy).getResponse()

and then use that Response.

Contexts are ignored on the client side

Thanks, Sergey

On 07/08/13 01:51, rodgersh wrote:
> I am using JAXRSClientFactoryBean to programmatically create my JAXRS client
> and want to get the Content-Disposition HTTP header from the response when I
> invoke a method on the client.
>
> I am programmatically creating my JAXRS client as follows:
>
>         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
>          bean.setServiceClass(Wcs.class);
>          bean.setAddress("http://my.site.com/myservice");
>          MyInterface proxy = bean.create(MyInterface.class);
>
> The implementation of MyInterface has this method:
>
>      @Override
>      @POST
>      @Consumes({"text/xml", "application/xml"})
>      public InputStream getCoverage(GetCoverage request) throws WcsException
> {
>
>          InputStream is = proxy.getCoverage(request);
>          if (httpServletResponse != null) {
>              String contentDisposition =
> httpServletResponse.getHeader("Content-Disposition");
>          }
>
>          return is;
>      }
>
> I have tried injecting HttpServletResponse using @Context and I have tried
> injecting MessgageContext using @Context (both in a declaration and with a
> setter method like so:
>
>      @Context
>      public void setHttpServletResponse(HttpServletResponse
> httpServletResponse) {
>          LOGGER.debug("Setting HttpServletResponse");
>          this.httpServletResponse = httpServletResponse;
>      }
>
> The context is never injected, it is always null. I verified with a debugger
> that the setter method was not called.
>
> What might I be doing wrong? I am using CXF version 2.7.5
>
> Thanks.
>
> Hugh
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-get-HTTP-response-headers-when-using-JAXRSClientFactoryBean-to-create-JAXRS-Client-tp5732047.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com