You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Nikki Payne <ni...@gmail.com> on 2008/06/27 23:12:26 UTC

Changing the http status code in the response

Hello

I am running a service on  Axis2 v1.4  I am attempting to change the HTTP
status code in the reponse back to the client, but have been unsuccessful so
far. Here's what I am doing :
I get the response object from the messagecontext in the
MessageReceiverInOut


HttpServletResponse resp =
    (HttpServletResponse)
msgContext.getCurrentMessageContext().getProperty(org.apache.axis2.transport.http.HTTPConstants.MC_HTTP_SERVLETRESPONSE);
         if (resp != null) {
             System.out.println("Resp not null ");
             resp.setStatus(503 );
             resp.addHeader("abcd" , "newval11");
         }


Here's the response http header :
HTTP/1.1 *500 *Internal Server Error
Server: Apache-Coyote/1.1
*abcd: newval11*
Content-Type: application/soap+xml; action="
http://www.w3.org/2005/08/addressing/soap/fault";charset=UTF-8



The new header "abcd" does show up, but the status-code remains unchanged to
500 (not 503).

Any help will be greatly appreciated

thank you
-nikki

Re: Changing the http status code in the response

Posted by Saminda Abeyruwan <sa...@gmail.com>.
If your response is a success or accepted, AxisServlet will return the
response code as 200 OK or 202 Accepted. You will not be able to change
this.

But you could change the response header to 401 Unauthorized,  by setting
property Constants.HTTP_RESPONSE_STATE to
HttpServletResponse.SC_UNAUTHORIZED and Constants.HTTP_BASIC_AUTH_REALM,

thus the response header can be set with "WWW-Authenticate". To do this you
would have to throw an AxisFault exception from your hander or service.

The exact requirement you are asking is not available at the moment. Please
open an JIRA as a feature improvement.

Thank you!

Saminda

On Sat, Jun 28, 2008 at 2:42 AM, Nikki Payne <ni...@gmail.com> wrote:

> Hello
>
> I am running a service on  Axis2 v1.4  I am attempting to change the HTTP
> status code in the reponse back to the client, but have been unsuccessful so
> far. Here's what I am doing :
> I get the response object from the messagecontext in the
> MessageReceiverInOut
>
>
> HttpServletResponse resp =
>     (HttpServletResponse)
> msgContext.getCurrentMessageContext().getProperty(org.apache.axis2.transport.http.HTTPConstants.MC_HTTP_SERVLETRESPONSE);
>          if (resp != null) {
>              System.out.println("Resp not null ");
>              resp.setStatus(503 );
>              resp.addHeader("abcd" , "newval11");
>          }
>
>
> Here's the response http header :
> HTTP/1.1 *500 *Internal Server Error
> Server: Apache-Coyote/1.1
> *abcd: newval11*
> Content-Type: application/soap+xml; action="
> http://www.w3.org/2005/08/addressing/soap/fault";charset=UTF-8
>
>
>
> The new header "abcd" does show up, but the status-code remains unchanged
> to 500 (not 503).
>
> Any help will be greatly appreciated
>
> thank you
> -nikki
>
>
>


-- 
Saminda Abeyruwan

Senior Software Engineer
WSO2 Inc. - www.wso2.org