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 sc...@apache.org on 2007/01/19 22:01:00 UTC

svn commit: r497954 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: marshaller/impl/alt/MethodMarshallerUtils.java message/impl/XMLSpineImpl.java

Author: scheu
Date: Fri Jan 19 13:00:59 2007
New Revision: 497954

URL: http://svn.apache.org/viewvc?view=rev&rev=497954
Log:
AXIS2-1799
Contributor:Rich Scheuerle
Misc Changes that are the foundation for legacy exception support.

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/XMLSpineImpl.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=497954&r1=497953&r2=497954
==============================================================================
--- 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 Fri Jan 19 13:00:59 2007
@@ -30,6 +30,7 @@
 import javax.xml.bind.JAXBElement;
 import javax.xml.namespace.QName;
 import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPEnvelope;
 import javax.xml.soap.SOAPFault;
 import javax.xml.stream.XMLStreamException;
@@ -56,6 +57,7 @@
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.util.ClassUtils;
 import org.apache.axis2.jaxws.util.ConvertUtils;
+import org.apache.axis2.jaxws.util.SAAJFactory;
 import org.apache.axis2.jaxws.util.XMLRootElementUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -537,8 +539,19 @@
         XMLFault xmlfault = message.getXMLFault();
         Block[] detailBlocks = xmlfault.getDetailBlocks();
         
+        // Sometimes Axis2 will flow a single detail element with the name "Exception".  
+        // "Exception" contains stack information.  This is a violation of the WSI specification; however
+        // we still need to work around it.
+        boolean isStack = false;
+        QName elementName = null;
+        if (detailBlocks !=null && detailBlocks.length == 1) {
+            elementName = detailBlocks[0].getQName();
+            isStack = (elementName.getNamespaceURI().length() == 0 && elementName.getLocalPart().equals("Exception"));
+        }
+        
         
         if ((operationDesc.getFaultDescriptions().length == 0) || 
+                isStack ||
                 (detailBlocks == null) || 
                 (detailBlocks.length > 1))  {
             // This is a system exception if the method does not throw a checked exception or if 
@@ -554,9 +567,6 @@
                 // to unmarshal the object.  But we don't know the declared
                 // type without knowing the name of the type (sigh)
                 
-                // First get the QName...this might cause a parse
-                QName elementName = detailBlocks[0].getQName();
-                
                 // Now search the FaultDescriptors to find the right 
                 // declared type
                 Class rpcType = null;
@@ -574,7 +584,7 @@
             
             // TODO This code assumes that the block can be demarshalled as a 
             // known JAXB object.  But what if a detail is flowed that we don't know how to handle.
-            // for example, what if the detail is a stack trace.  To be on the safe side, we should
+            // To be on the safe side, we should
             // probably make a copy of the OMBlock and then throw create a SystemException if
             // with the original detail if JAXB unmarshalling fails.
             // (I agree that this would not be performant, but we are on an exception path)
@@ -683,7 +693,7 @@
      */
     private static Exception createServiceException(String message, Class exceptionclass, Object bean, Class beanFormalType) throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException {
         // All webservice exception classes are required to have a constructor that takes a (String, bean) argument
-        // TODO necessary to be more careful here with instantiating, cassting, etc?
+        // TODO necessary to be more careful here with instantiating, casting, etc?
         if (log.isDebugEnabled()) {
             log.debug("Constructing JAX-WS Exception:" + exceptionclass);
         }
@@ -703,16 +713,20 @@
         ProtocolException e = null;
         Protocol protocol = message.getProtocol();
         String text = xmlFault.getReason().getText();
+        
         if (protocol == Protocol.soap11 || protocol == Protocol.soap12) {
             // Throw a SOAPFaultException
             if (log.isDebugEnabled()) {
                 log.debug("Constructing SOAPFaultException for " + text);
             }
+            String protocolNS = (protocol == Protocol.soap11) ? 
+                    SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE : 
+                        SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;
             try {
                 // The following set of instructions is used to avoid 
                 // some unimplemented methods in the Axis2 SAAJ implementation
-                SOAPEnvelope env = message.getAsSOAPEnvelope();
-                SOAPBody body = env.getBody();
+                javax.xml.soap.MessageFactory mf = SAAJFactory.createMessageFactory(protocolNS);
+                SOAPBody body = mf.createMessage().getSOAPBody();
                 SOAPFault soapFault = XMLFaultUtils.createSAAJFault(xmlFault, body);
                 e = new SOAPFaultException(soapFault);
             } catch (Exception ex) {

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=497954&r1=497953&r2=497954
==============================================================================
--- 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 Fri Jan 19 13:00:59 2007
@@ -135,8 +135,7 @@
 		SOAPHeader header = root.getHeader();
 		if (header != null) {
             Iterator it = header.getChildren();
-            advanceIterator(it, headerBlocks, false); 
-            //advanceIterator(it, headerBlocks, true);            
+            advanceIterator(it, headerBlocks, true);             
         }
 
 		
@@ -162,6 +161,7 @@
                 }
                 bodyIterator = op.getChildren();
             }
+            // We only want to advance past the first block...we will lazily parse the other blocks
 			advanceIterator(bodyIterator, bodyBlocks, false);
 		} else {
 			// Process the Fault
@@ -170,7 +170,7 @@
 			SOAPFaultDetail detail = fault.getDetail();
 			if (detail != null) {
 			  detailIterator = detail.getChildren();
-			  advanceIterator(detailIterator, detailBlocks, false);
+			  advanceIterator(detailIterator, detailBlocks, true);  // Advance through all of the detail blocks
 			}
 		}
 		return;
@@ -188,25 +188,22 @@
 		// TODO This code must be reworked.  The OM Iterator causes the entire OMElement to be 
 		// parsed when it.next() is invoked.  I will need to fix this to gain performance.  (scheu)
 		
-		boolean found = false;
-		boolean first = true;
-		while (it.hasNext() && (!found && !toEnd)) {
-			// Remove the nodes as they are converted into blocks
-			if (!first) {
-				it.remove();
-			}
-			first = true;
-			
+        boolean found = false;
+		while (it.hasNext() && !found) {
 			OMNode node = (OMNode) it.next();
 			if (node instanceof OMElement) {
 				// Elements are converted into Blocks
 				Block block = null;
 				try { 
 					block = obf.createFrom((OMElement) node, null, null);
+                    it.remove();  // Remove the nodes as they are converted 
 				} catch (XMLStreamException xse) {
 					throw ExceptionFactory.makeMessageException(xse);
 				}
 				blocks.add(block);
+                if (!toEnd) {
+                    found = true;  // Found the one element, indicate that we can quit
+                }
 			} else {
                 // TODO LOGGING ?
 				// A Non-element is found, it is probably whitespace text, but since
@@ -379,7 +376,7 @@
 	            OMElement e = new OMSourcedElementImpl(b.getQName(),soapFactory, b);                  
 	            root.getBody().getFault().getDetail().addChild(e);                  
 	        }               
-	        bodyBlocks.clear();  
+	        detailBlocks.clear();  
 	    }
 	    return root;
 	}
@@ -432,8 +429,11 @@
 
 	public Block getHeaderBlock(String namespace, String localPart, Object context, BlockFactory blockFactory) throws MessageException {
 		int index = getHeaderBlockIndex(namespace, localPart);
+        if (index < 0) {
+            // REVIEW What should happen if header block not found
+            return null;  
+        }
 		try {
-			//Block oldBlock = bodyBlocks.get(index);
 			Block oldBlock = headerBlocks.get(index);
 			// Convert to new Block
 			Block newBlock = blockFactory.createFrom(oldBlock, context);
@@ -448,8 +448,11 @@
 
 	public void setHeaderBlock(String namespace, String localPart, Block block) throws MessageException {
 		int index = getHeaderBlockIndex(namespace, localPart);
-		headerBlocks.add(block);
-		//headerBlocks.set(index, block);
+        if (index >= 0) {
+            headerBlocks.set(index, block);
+        } else {
+            headerBlocks.add(block);
+        }
 	}
 
 	/**
@@ -472,7 +475,9 @@
 	}
 	public void removeHeaderBlock(String namespace, String localPart) throws MessageException {
 		int index = getHeaderBlockIndex(namespace, localPart);
-		headerBlocks.remove(index);
+        if (index >= 0) {
+            headerBlocks.remove(index);
+        }
 	}
 
 	public String traceString(String indent) {



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