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 Chris Berry <ch...@gmail.com> on 2006/07/04 16:40:15 UTC
Building a SOAPFaultHandler
I am reposting this once more w/ hopes that one of the Axis wizards
might give me some advice. I'm really stumped on this one...
Thanks,
-- Chris
---------- Forwarded message ----------
From: Chris Berry <ch...@gmail.com>
Date: Jun 26, 2006 7:55 AM
Subject: Building a SOAPFaultHandler
To: axis-user@ws.apache.org
Greetings,
I'm struggling to build an Axis Handler which modifies a SOAPFault on
it's way back out to the Client. I want to add a bit of generic
information (e.g. hostname, svcname, timestamp, etc.) to the SOAPFault
(i.e. to the faultstring and faultactor) o assist my Client's in their
debugging. Unfortunately I am not able to actually modify what the
Client sees, although I can see the Message is changed locally. Is
this even possible?? It appears that the Message is read-only at this
point?? Below is the code I'm using.
Does anyone have any ideas for me?? Am I just doing something silly??
Thanks,
-- Chris
public class ErrorHandler
extends BasicHandler
{
//------------------------------------
public void invoke( MessageContext msgContext )
throws AxisFault
{
try {
/* do nothing */
}
catch ( Exception e ) {
errlog.error( e );
throw AxisFault.makeFault( e );
}
}
//------------------------------------
public void onFault(MessageContext msgContext)
{
try {
addFaultDetails( msgContext );
logError( msgContext );
}
catch ( Exception ee ) {
errlog.error( "An additional error occured while processing
onFault()", ee );
}
}
//------------------------------------
public void addFaultDetails( MessageContext msgContext )
{
try {
if ( msgContext == null )
return; // EXIT
SOAPMessage msg = msgContext.getMessage();
if ( msg == null )
return; // EXIT
SOAPBody body = msg.getSOAPBody();
if ( body == null )
return; // EXIT
SOAPFault fault = (SOAPFault)(body.getFault());
if ( fault == null )
return; // EXIT
// send back hostname, timestamp, svcname as part of the
// "faultcode/faultstring/faultactor" fields..
String targetService = msgContext.getTargetService();
if ( targetService == null )
targetService = "UNKNOWN_SVC";
String operation = "UNKNOWN_OP";
if ( msgContext.getOperation() != null
&& msgContext.getOperation().getName() != null )
operation = msgContext.getOperation().getName();
String svcname = targetService + "." + operation;
String timestamp = (new Date()).toString();
String hostname = java.net.Inet4Address.getLocalHost().getHostName();
String faultString = fault.getFaultString();
faultString = "SOAPFault @ <" + timestamp + "> = " + faultString;
fault.setFaultString( faultString );
String faultActor = fault.getFaultActor();
fault.setFaultActor( "[" + svcname + "] @ (" + hostname + ") "
+ faultActor );
SOAPEnvelope env = new SOAPEnvelope();
env.clearBody();
env.addBodyElement(fault);
Message respMsg = new Message(env);
msgContext.setResponseMessage(respMsg);
}
catch ( Exception ee ) {
errlog.error( "An additional error occured while processing
onFault()", ee );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org