You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2006/12/04 21:10:22 UTC
svn commit: r482334 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/marshaller/impl/alt/
src/org/apache/axis2/jaxws/message/impl/
src/org/apache/axis2/jaxws/message/util/
test/org/apache/axis2/jaxws/framework/ test/org/apac...
Author: scheu
Date: Mon Dec 4 12:10:19 2006
New Revision: 482334
URL: http://svn.apache.org/viewvc?view=rev&rev=482334
Log:
AXIS2-1799
Contributor: Rich Scheuerle
Support for marshalling SOAPFaultException and other minor JAX-WS fault issues.
Added:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java
- copied, changed from r481336, webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLFaultUtils.java
Removed:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLFaultUtils.java
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartBase.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultyWebServiceTests.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java?view=diff&rev=482334&r1=482333&r2=482334
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java Mon Dec 4 12:10:19 2006
@@ -32,11 +32,13 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPFault;
import javax.xml.stream.XMLStreamException;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.Holder;
import javax.xml.ws.Response;
import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.SOAPFaultException;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.description.EndpointDescription;
@@ -55,6 +57,7 @@
import org.apache.axis2.jaxws.message.XMLFaultReason;
import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.util.XMLFaultUtils;
import org.apache.axis2.jaxws.registry.FactoryRegistry;
import org.apache.axis2.jaxws.util.ClassUtils;
import org.apache.axis2.jaxws.util.JavaUtils;
@@ -411,21 +414,44 @@
throws MessageException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
// Get the root cause of the throwable object
+ Throwable t = ClassUtils.getRootCause(throwable);
if (log.isDebugEnabled()) {
log.debug("Marshal Throwable =" + throwable.getClass().getName());
- log.debug(" exception=" + throwable.toString());
+ log.debug(" rootCause =" + t.getClass().getName());
+ log.debug(" exception=" + t.toString());
}
- Throwable t = ClassUtils.getRootCause(throwable);
XMLFault xmlfault = null;
+ // There are 5 different categories of exceptions. Each category has a little different marshaling code.
+ // A) Service Exception that matches the JAX-WS specification (chapter 2.5 of the spec)
+ // B) Service Exception that matches the JAX-WS "legacy" exception (chapter 3.7 of the spec)
+ // C) SOAPFaultException
+ // D) WebServiceException
+ // E) Other runtime exceptions (i.e. NullPointerException)
+
// Get the FaultDescriptor matching this Exception.
// If FaultDescriptor is found, this is a JAX-B Service Exception.
// If not found, this is a System Exception
FaultDescription fd = operationDesc.resolveFaultByExceptionName(t.getClass().getName());
- if (fd != null) {
- // Service Exception.
+ if (t instanceof SOAPFaultException) {
+ // Category C: SOAPFaultException
+ // Construct the xmlFault from the SOAPFaultException's Fault
+ SOAPFaultException sfe = (SOAPFaultException) t;
+ SOAPFault soapFault = sfe.getFault();
+ if (soapFault == null) {
+ // No fault ? I will treat this like category E
+ xmlfault = new XMLFault(null, // Use the default XMLFaultCode
+ new XMLFaultReason(t.toString())); // Assumes text is the language supported by the current Locale
+ } else {
+ xmlfault = XMLFaultUtils.createXMLFault(soapFault);
+ }
+
+ } else if (fd != null) {
+ // The exception is a Service Exception. It may be (A) JAX-WS compliant exception or (B) JAX-WS legacy exception
+
+ // TODO Need to add detection and code to differentiate between (A) and (B)
// Get the fault bean object. Make sure it can be rendered as an element
Method getFaultInfo = t.getClass().getMethod("getFaultInfo", null);
@@ -448,9 +474,19 @@
detailBlocks[0] = factory.createFrom(faultBeanObject,context,null);
// Now make a XMLFault containing the detailblock
- xmlfault = new XMLFault(null, new XMLFaultReason(t.toString()), detailBlocks);
+ xmlfault = new XMLFault(null, new XMLFaultReason(t.getMessage()), detailBlocks);
+ } else if (t instanceof WebServiceException) {
+ // Category D: WebServiceException
+ // The reason is constructed with the getMessage of the exception.
+ // There is no detail
+ WebServiceException wse = (WebServiceException) t;
+ xmlfault = new XMLFault(null, // Use the default XMLFaultCode
+ new XMLFaultReason(wse.getMessage())); // Assumes text is the language supported by the current Locale
} else {
- // System Exception
+ // Category E: Other System Exception
+ // The reason is constructed with the toString of the exception.
+ // This places the class name of the exception in the reason
+ // There is no detail.
xmlfault = new XMLFault(null, // Use the default XMLFaultCode
new XMLFaultReason(t.toString())); // Assumes text is the language supported by the current Locale
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartBase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartBase.java?view=diff&rev=482334&r1=482333&r2=482334
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartBase.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLPartBase.java Mon Dec 4 12:10:19 2006
@@ -42,6 +42,7 @@
import org.apache.axis2.jaxws.message.XMLPart;
import org.apache.axis2.jaxws.message.factory.BlockFactory;
import org.apache.axis2.jaxws.message.factory.SOAPEnvelopeBlockFactory;
+import org.apache.axis2.jaxws.message.util.XMLFaultUtils;
import org.apache.axis2.jaxws.util.JavaUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java?view=diff&rev=482334&r1=482333&r2=482334
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLSpineImpl.java Mon Dec 4 12:10:19 2006
@@ -51,6 +51,7 @@
import org.apache.axis2.jaxws.message.factory.OMBlockFactory;
import org.apache.axis2.jaxws.message.util.MessageUtils;
import org.apache.axis2.jaxws.message.util.Reader2Writer;
+import org.apache.axis2.jaxws.message.util.XMLFaultUtils;
import org.apache.axis2.jaxws.registry.FactoryRegistry;
/**
Copied: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java (from r481336, webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLFaultUtils.java)
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java?view=diff&rev=482334&p1=webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLFaultUtils.java&r1=481336&p2=webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java&r2=482334
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/XMLFaultUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java Mon Dec 4 12:10:19 2006
@@ -14,9 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.axis2.jaxws.message.impl;
+package org.apache.axis2.jaxws.message.util;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.QName;
@@ -37,26 +38,28 @@
import org.apache.axiom.soap.SOAPFaultSubCode;
import org.apache.axiom.soap.SOAPFaultText;
import org.apache.axiom.soap.SOAPFaultValue;
+import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.message.Block;
import org.apache.axis2.jaxws.message.MessageException;
import org.apache.axis2.jaxws.message.XMLFault;
import org.apache.axis2.jaxws.message.XMLFaultCode;
import org.apache.axis2.jaxws.message.XMLFaultReason;
-import org.apache.axis2.jaxws.message.util.MessageUtils;
+import org.apache.axis2.jaxws.message.factory.OMBlockFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
/**
* Collection of utilities used by the Message implementation to
* process XMLFaults.
* @see XMLFault
*/
-class XMLFaultUtils {
+public class XMLFaultUtils {
/**
* @param envelope javax.xml.soap.SOAPEnvelope
* @return true if the SOAPEnvelope contains a SOAPFault
*/
- static boolean isFault(javax.xml.soap.SOAPEnvelope envelope) throws SOAPException {
+ public static boolean isFault(javax.xml.soap.SOAPEnvelope envelope) throws SOAPException {
javax.xml.soap.SOAPBody body = envelope.getBody();
if (body != null) {
return (body.getFault() != null);
@@ -68,7 +71,7 @@
* @param envelope org.apache.axiom.soap.SOAPEnvelope
* @return true if the SOAPEnvelope contains a SOAPFault
*/
- static boolean isFault(SOAPEnvelope envelope) {
+ public static boolean isFault(SOAPEnvelope envelope) {
SOAPBody body = envelope.getBody();
if (body != null) {
return (body.getFault() != null);
@@ -179,6 +182,44 @@
return xmlFault;
}
+ /**
+ * Create an XMLFault object from a SOAPFault and detail Blocks
+ * @param soapFault
+ * @param detailBlocks
+ * @return
+ */
+ public static XMLFault createXMLFault(javax.xml.soap.SOAPFault soapFault) throws MessageException {
+ // Convert the SOAPFault into an OM SOAPFault. OMSOAP Fault already supports SOAP 1.2, so this makes the code easier to migrate
+ SAAJConverter converter =
+ (SAAJConverter) FactoryRegistry.getFactory(SAAJConverter.class);
+ SOAPFault omSOAPFault = (SOAPFault) converter.toOM(soapFault);
+ Block[] detailBlocks = getDetailBlocks(omSOAPFault);
+ XMLFault xmlFault = createXMLFault(omSOAPFault, detailBlocks);
+ return xmlFault;
+ }
+
+ private static Block[] getDetailBlocks(SOAPFault soapFault) throws MessageException {
+ try {
+ Block[] blocks = null;
+ SOAPFaultDetail detail = soapFault.getDetail();
+ if (detail != null) {
+ // Create a block for each element
+ OMBlockFactory bf = (OMBlockFactory) FactoryRegistry.getFactory(OMBlockFactory.class);
+ ArrayList<Block> list = new ArrayList<Block>();
+ Iterator it = detail.getChildElements();
+ while (it.hasNext()) {
+ OMElement om = (OMElement) it.next();
+ Block b = bf.createFrom(om, null,om.getQName());
+ list.add(b);
+ }
+ blocks = list.toArray(blocks);
+ }
+ return blocks;
+ } catch (Exception e) {
+ throw ExceptionFactory.makeMessageException(e);
+ }
+ }
+
/**
* Create a SOAPFault representing the XMLFault and attach it to body.
* If there are 1 or more detail Blocks on the XMLFault, a SOAPFaultDetail is attached.
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?view=diff&rev=482334&r1=482333&r2=482334
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Mon Dec 4 12:10:19 2006
@@ -81,7 +81,7 @@
static {
// Uncomment the followign line to enable debug
-// BasicConfigurator.configure();
+ BasicConfigurator.configure();
}
/**
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java?view=diff&rev=482334&r1=482333&r2=482334
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java Mon Dec 4 12:10:19 2006
@@ -65,7 +65,10 @@
SoapMessageProvider.XML_SWAREF_REQUEST +
"</invoke_str>" +
SoapMessageProvider.SWAREF_REF +
- "</ns2:invoke>";
+ "</ns2:invoke>";
+ private String XML_FAULT_INVOKE = "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>" +
+ SoapMessageProvider.XML_FAULT_REQUEST +
+ "</invoke_str></ns2:invoke>";
protected void setUp() throws Exception {
@@ -117,6 +120,42 @@
}catch(Exception e){
e.printStackTrace();
+ fail("Caught exception " + e);
+ }
+
+ }
+
+ /**
+ * Sends an SOAPMessage containing only xml data
+ * Provider will throw a Fault
+ */
+ public void testProviderSOAPFault(){
+ try{
+ // Create the dispatch
+ Dispatch<SOAPMessage> dispatch = createDispatch();
+
+ // Create the SOAPMessage
+ String msg = reqMsgStart + XML_FAULT_INVOKE + reqMsgEnd;
+ MessageFactory factory = MessageFactory.newInstance();
+ SOAPMessage request = factory.createMessage(null,
+ new ByteArrayInputStream(msg.getBytes()));
+
+ // Test the transport headers by sending a content description
+ request.setContentDescription(SoapMessageProvider.XML_FAULT_REQUEST);
+
+ try {
+ // Dispatch
+ System.out.println(">> Invoking SourceMessageProviderDispatch");
+ SOAPMessage response = dispatch.invoke(request);
+ assertTrue("Expected failure", false);
+ } catch (Exception e) {
+
+ }
+
+
+
+ }catch(Exception e){
+ e.printStackTrace();
fail("Caught exception " + e);
}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java?view=diff&rev=482334&r1=482333&r2=482334
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java Mon Dec 4 12:10:19 2006
@@ -25,11 +25,18 @@
import javax.xml.ws.ServiceMode;
import javax.xml.ws.WebServiceProvider;
import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.ws.soap.SOAPFaultException;
import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.Detail;
import javax.xml.soap.MessageFactory;
+import javax.xml.soap.Name;
import javax.xml.soap.Node;
import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPMessage;
@WebServiceProvider()
@@ -55,6 +62,7 @@
public static String XML_MTOM_RESPONSE = "xml and mtom response";
public static String XML_SWAREF_REQUEST = "xml and swaref request";
public static String XML_SWAREF_RESPONSE = "xml and swaref response";
+ public static String XML_FAULT_REQUEST = "xml fault";
private String XML_RETURN = "<ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>" +
SoapMessageProvider.XML_RESPONSE +
@@ -85,7 +93,7 @@
- public SOAPMessage invoke(SOAPMessage soapMessage) {
+ public SOAPMessage invoke(SOAPMessage soapMessage) throws SOAPFaultException {
System.out.println(">> SoapMessageProvider: Request received.");
try{
@@ -110,6 +118,8 @@
response = getXMLMTOMResponse(soapMessage, discElement);
} else if (XML_SWAREF_REQUEST.equals(text)) {
response = getXMLSWARefResponse(soapMessage, discElement);
+ } else if (XML_FAULT_REQUEST.equals(text)) {
+ throwSOAPFaultException();
} else {
// We should not get here
System.out.println("Unknown Type of Message");
@@ -121,7 +131,9 @@
//response.writeTo(System.out);
//System.out.println("\n");
return response;
- }catch(Exception e){
+ } catch (SOAPFaultException sfe) {
+ throw sfe;
+ } catch(Exception e){
System.out.println("***ERROR: In SoapMessageProvider.invoke: Caught exception " + e);
e.printStackTrace();
}
@@ -268,6 +280,28 @@
return response;
}
+ private void throwSOAPFaultException() throws SOAPFaultException {
+ try {
+ MessageFactory mf = MessageFactory.newInstance();
+ SOAPFactory sf = SOAPFactory.newInstance();
+
+ SOAPMessage m = mf.createMessage();
+ SOAPBody body = m.getSOAPBody();
+ SOAPFault fault = body.addFault();
+ fault.setFaultString("sample fault");
+ Detail detail = fault.addDetail();
+ Name deName = sf.createName("detailEntry");
+ SOAPElement detailEntry = detail.addDetailEntry(deName);
+ detailEntry.addTextNode("sample detail");
+
+ SOAPFaultException sfe = new SOAPFaultException(fault);
+ throw sfe;
+ } catch (SOAPFaultException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
/**
* Count Attachments
* @param msg
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultyWebServiceTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultyWebServiceTests.java?view=diff&rev=482334&r1=482333&r2=482334
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultyWebServiceTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultyWebServiceTests.java Mon Dec 4 12:10:19 2006
@@ -39,7 +39,7 @@
System.out.println("----------------------------------");
assertNotNull(exception);
- assertEquals("org.apache.axis2.jaxws.sample.faults.FaultyWebServiceFault_Exception: custom exception", exception.getMessage());
+ assertEquals("custom exception", exception.getMessage());
assertNotNull(exception.getFaultInfo());
assertEquals("bean custom fault info", exception.getFaultInfo().getFaultInfo());
assertEquals("bean custom message", exception.getFaultInfo().getMessage());
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org