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 "Ralf Hauser (Jira)" <ji...@apache.org> on 2023/05/29 12:37:00 UTC

[jira] [Commented] (AXIS2-3879) Ability to change the http status code in the response being sent to the client

    [ https://issues.apache.org/jira/browse/AXIS2-3879?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17727102#comment-17727102 ] 

Ralf Hauser commented on AXIS2-3879:
------------------------------------

Still a problem is v1.8.2

Also, a non-2XX HttpServletResponse status should not be overwritten (especially if it is 5XX already), so in AxisServlet.java:387ff, it should along the lines of

    void processAxisFault(MessageContext msgContext, HttpServletResponse res,
                          OutputStream out, AxisFault e) {
        try {
            // If the fault is not going along the back channel we should be 202ing
            if (AddressingHelper.isFaultRedirected(msgContext)) {
                res.setStatus(HttpServletResponse.SC_ACCEPTED);
            } else {

                String status =
                        (String) msgContext.getProperty(Constants.HTTP_RESPONSE_STATE);
                if (status == null) {
                    log.error("processAxisFault() found a null HTTP status from the MessageContext"
                            + " instance, setting HttpServletResponse status to: " +
                            // or rather to HttpServletResponse.SC_INTERNAL_SERVER_ERROR ?
                            Constants.HTTP_RESPONSE_STATE);
                    int statI = res.getStatus();
                    if (300 > statI) {
                        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    } else {
                        log.error("processAxisFault() found a non 2XX HTTP status "
                                + "from the response object, so keeping "
                                + "HttpServletResponse status on: " + statI);
                    }
                } else {
                    log.error("processAxisFault() found an HTTP status from the "
                            + "MessageContext instance, setting HttpServletResponse "
                            + "status to: " + status);
                    int statI = res.getStatus();
                    if (300 > statI) {
                        res.setStatus(Integer.parseInt(status));
                    } else {
                        log.error("processAxisFault() found a non 2XX HTTP status "
                                + "from the response object, so keeping "
                                + "HttpServletResponse status on: " + statI);
                    }
                    //no further details written to the body
                    return;
                }

 

> Ability to change the http status code in the response being sent to the client
> -------------------------------------------------------------------------------
>
>                 Key: AXIS2-3879
>                 URL: https://issues.apache.org/jira/browse/AXIS2-3879
>             Project: Axis2
>          Issue Type: Improvement
>          Components: transports
>    Affects Versions: 1.4
>            Reporter: nikki
>            Priority: Major
>
> Hello
> I'd like the ability to change the http status code in the reponse. For example : I'd like to send in certain cases an http 503 (instead of a 500) when a soap fault occurs. Another of my needs is to send a 202 (instead of 200 for an in-out operation.)
> Here's what i attempted which didn't work & I was suggested by Saminda to open a JIRA.
>  HttpServletResponse resp =  (HttpServletResponse) 
>  msgContext.getCurrentMessageContext().getProperty(org.apache.axis2.transport.http.HT TPConstants.MC_HTTP_SERVLETRESPONSE); 
> if (resp != null) {
>  System.out.println("Resp not null ");
>  resp.setStatus(503 );
>  }
>  thankyou



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@axis.apache.org
For additional commands, e-mail: java-dev-help@axis.apache.org