Author: nagy
Date: Sun Jan 28 14:57:04 2007
New Revision: 500909
URL: http://svn.apache.org/viewvc?view=rev&rev=500909
Log:
Fixed a problem with the HTTP (and probably other) return codes for faults which occur while
in the JAXWS layer not being set properly. The MessageContext created as the result of a
fault in the JAXWS layer will now be attached to an AxisFault and propagated back down to
the transport in a manner that is consistent with how other faults flow within the system.
Instead of creating a new MessageContext, the fault handling code will simply extract the
existing MessageContext from the fault and use that for the rest of the processing.
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/AxisFault.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java?view=diff&rev=500909&r1=500908&r2=500909
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/JAXWSMessageReceiver.java
Sun Jan 28 14:57:04 2007
@@ -55,6 +55,8 @@
*/
public void receive(org.apache.axis2.context.MessageContext axisRequestMsgCtx)
throws AxisFault {
+ AxisFault faultToReturn = null;
+
if (log.isDebugEnabled()) {
log.debug("new request received");
}
@@ -110,14 +112,24 @@
OperationContext opCtx = axisResponseMsgCtx.getOperationContext();
opCtx.addMessageContext(axisResponseMsgCtx);
+
+ // If this is a fault message, we want to throw it as an
+ // exception so that the transport can do the appropriate things
+ if (responseMsgCtx.getMessage().isFault())
+ {
+ faultToReturn = new AxisFault("An error was detected during JAXWS processing",
axisResponseMsgCtx);
+ }
+ else
+ {
//This assumes that we are on the ultimate execution thread
ThreadContextMigratorUtil.performMigrationToContext(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID,
axisResponseMsgCtx);
//Create the AxisEngine for the reponse and send it.
AxisEngine engine = new AxisEngine(axisResponseMsgCtx.getConfigurationContext());
engine.send(axisResponseMsgCtx);
- //This assumes that we are on the ultimate execution thread
- ThreadContextMigratorUtil.performContextCleanup(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID,
axisResponseMsgCtx);
+ //This assumes that we are on the ultimate execution thread
+ ThreadContextMigratorUtil.performContextCleanup(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID,
axisResponseMsgCtx);
+ }
}
} catch (Exception e) {
@@ -133,6 +145,11 @@
//This assumes that we are on the ultimate execution thread
ThreadContextMigratorUtil.performThreadCleanup(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID,
axisRequestMsgCtx);
+
+ if (faultToReturn != null)
+ {
+ throw faultToReturn;
+ }
}
private boolean isMepInOnly(String mep){
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/AxisFault.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/AxisFault.java?view=diff&rev=500909&r1=500908&r2=500909
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/AxisFault.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/AxisFault.java Sun Jan
28 14:57:04 2007
@@ -26,6 +26,7 @@
import org.apache.axiom.soap.SOAPFaultReason;
import org.apache.axiom.soap.SOAPFaultRole;
import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axis2.context.MessageContext;
import javax.xml.namespace.QName;
import java.lang.reflect.InvocationTargetException;
@@ -86,6 +87,14 @@
private Throwable cause;
/**
+ * If not null, the messageContext represents the fault as it
+ * should be returned. This is used by higher-level layers
+ * that want to generate the message themselves so that
+ * processing may take place before they return control (e.g. JAX-WS.)
+ */
+ private MessageContext faultMessageContext;
+
+ /**
* SOAP1.2: URI of faulting node. Null for unknown.
* <p/>
* The value of the Node element information item is the URI that
@@ -238,6 +247,19 @@
}
/**
+ * Create an AxisFault by providing a textual message and a MessageContext
+ * that contains the actual fault representation.
+ *
+ * @param message A string that's really only useful for logging.
+ * @param faultMessageContext
+ */
+ public AxisFault(String message, MessageContext faultMessageContext)
+ {
+ super(message);
+ this.faultMessageContext = faultMessageContext;
+ }
+
+ /**
* Add a header to the list of fault headers
*
* @param header to add.
@@ -429,6 +451,18 @@
return cause != null ? cause : super.getCause();
}
+ /**
+ * Returns the MessageContext representation of the fault if the fault
+ * was created by providing that.
+ *
+ * @return The MessageContext representing the fault message or null if the
+ * fault was not created with MessageContext representation.
+ */
+ public MessageContext getFaultMessageContext()
+ {
+ return faultMessageContext;
+ }
+
class FaultReason {
/**
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java?view=diff&rev=500909&r1=500908&r2=500909
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
Sun Jan 28 14:57:04 2007
@@ -172,6 +172,29 @@
throw new AxisFault(Messages.getMessage("errorwhileProcessingFault"));
}
+ // See if the throwable is an AxisFault and if it already contains the
+ // fault MessageContext
+ if (e instanceof AxisFault)
+ {
+ MessageContext faultMessageContext = ((AxisFault)e).getFaultMessageContext();
+ if (faultMessageContext != null)
+ {
+ // These may not have been set correctly when the original context
+ // was created -- an example of this is with the SimpleHTTPServer.
+ // I'm not sure if this is the correct thing to do, or if the
+ // code that created this context in the first place should
+ // expect that the transport out info was set correctly, as
+ // it may need to use that info at some point before we get to
+ // this code.
+ faultMessageContext.setProperty(MessageContext.TRANSPORT_OUT,
+ processingContext.getProperty(MessageContext.TRANSPORT_OUT));
+ faultMessageContext.setProperty(Constants.OUT_TRANSPORT_INFO,
+ processingContext.getProperty(Constants.OUT_TRANSPORT_INFO));
+ faultMessageContext.setProcessingFault(true);
+ return faultMessageContext;
+ }
+ }
+
// Create a basic response MessageContext with basic fields copied
MessageContext faultContext = createResponseMessageContext(processingContext);
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org
|