You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by William Blackburn <wb...@nextrials.com> on 2008/11/25 01:22:33 UTC

Overriding status code on http response for soap service

I have implemented a webservice and successfully exposed it via soap  
using CXF. I have now been asked to set an http response code of 404  
under certain conditions. Though I am not in agreement with straying  
into unspecified behavior, I don't have much choice in the matter. I  
have tried everything I could find in the documentation to do this,  
but cannot make it work.

I have successfully acquired the web service context using:

     @Resource
     WebServiceContext wsc;

At the point I usually return a value from the service, I have tried  
both:

     MessageContext context = wsc.getMessageContext();
     context.put(Message.RESPONSE_CODE, new Integer(404));

and

     HttpServletResponse response = (HttpServletResponse)  
context.get(AbstractHTTPDestination.HTTP_RESPONSE);
     response.setStatus(new Integer(404));

In either case, the status code actually received is 200/OK

What, if any, is the proper way to do this?

Thanks in advance for any help.

Re: Overriding status code on http response for soap service

Posted by Daniel Kulp <dk...@apache.org>.
What version of CXF?    I know some work was done in this area for 2.1.3.

Dan


On Monday 24 November 2008 7:22:33 pm William Blackburn wrote:
> I have implemented a webservice and successfully exposed it via soap
> using CXF. I have now been asked to set an http response code of 404
> under certain conditions. Though I am not in agreement with straying
> into unspecified behavior, I don't have much choice in the matter. I
> have tried everything I could find in the documentation to do this,
> but cannot make it work.
>
> I have successfully acquired the web service context using:
>
>      @Resource
>      WebServiceContext wsc;
>
> At the point I usually return a value from the service, I have tried
> both:
>
>      MessageContext context = wsc.getMessageContext();
>      context.put(Message.RESPONSE_CODE, new Integer(404));
>
> and
>
>      HttpServletResponse response = (HttpServletResponse)
> context.get(AbstractHTTPDestination.HTTP_RESPONSE);
>      response.setStatus(new Integer(404));
>
> In either case, the status code actually received is 200/OK
>
> What, if any, is the proper way to do this?
>
> Thanks in advance for any help.



-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog