You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Je...@royalsunalliance.ca on 2005/08/30 14:41:56 UTC

How to stop the fault and return a normal message

i'm writing a little Handler to convert the faults to another XML, which i 
hope to be returned to the caller without an HTTP 500 error. In doing so, 
i placed my handler as the first in the request chain and the last in the 
response chain.
I overwrote its onFault() method to remove the fault from the message and 
place another message in it. 
On the response, I can see my injected message but I still see the HTTP500 
being thrown.
Examining the code more in details, I came across the following in 
SimpleChain which shows that regardless of the message, the original fault 
keeps getting thrown:
        } catch( AxisFault f ) {
            // Something went wrong.  If we haven't already put this fault
            // into the MessageContext's response message, do so and make 
sure
            // we only do it once.  This allows onFault() methods to 
safely
            // set headers and such in the response message without them
            // getting stomped.
            if (!msgContext.isPropertyTrue(CAUGHTFAULT_PROPERTY)) {
                // Attach the fault to the response message; enabling 
access to the
                // fault details while inside the handler onFault methods.
                Message respMsg = new Message(f);
                msgContext.setResponseMessage(respMsg);
                msgContext.setProperty(CAUGHTFAULT_PROPERTY, 
Boolean.TRUE);
            }
            while( --i >= 0 )
                ((Handler) handlers.elementAt( i )).onFault( msgContext );
            throw f;
        }
Which ultimately causes the 500 error to be returned in AxisServlet:
    private void configureResponseFromAxisFault(HttpServletResponse 
response,
                                                AxisFault fault) {
        ..
        int status = getHttpServletResponseStatus(fault);
        if (status == HttpServletResponse.SC_UNAUTHORIZED) {
            // unauth access results in authentication request
            // TODO: less generic realm choice?
            response.setHeader("WWW-Authenticate", "Basic 
realm=\"AXIS\"");
        }
        response.setStatus(status);
    }

Any suggestions?

Jeff Saremi


--------------------------------------------------
THIS EMAIL COMMUNICATION IS INTENDED ONLY FOR THE PERSON OR ENTITY TO WHICH IT IS ADDRESSED AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION. ANY USE OF THIS INFORMATION BY PERSONS OR ENTITIES OTHER THAN THE INTENDED RECIPIENT IS PROHIBITED.  IF YOU RECEIVED THIS IN ERROR, PLEASE CONTACT THE SENDER AND DELETE THE EMAIL AND ALL COPIES (ELECTRONIC OR OTHERWISE) IMMEDIATELY.

CE COURRIEL EST DESTINE UNIQUEMENT A LA PERSONNE OU A L'ENTITE A LAQUELLE IL EST ENVOYE ET PEUT CONTENIR DE L'INFORMATION CONFIDENTIELLE OU PRIVILEGIEE.  TOUTE UTILISATION DE L'INFORMATION PAR UNE PERSONNE OU UNE ENTITE AUTRE QUE CELLE A LAQUELLE ELLE EST DESTINEE EST INTERDITE. SI VOUS RECEVEZ CE COURRIEL PAR ERREUR,  VEUILLEZ COMMUNIQUER AVEC SON EXPEDITEUR ET  SUPPRIMER CE COURRIEL ET TOUTE COPIE (ELECTRONIQUE OU AUTRE) IMMEDIATEMENT.