axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ngalla...@apache.org
Subject svn commit: r551659 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: handler/HandlerChainProcessor.java handler/LogicalMessageImpl.java message/util/impl/SAAJConverterImpl.java
Date Thu, 28 Jun 2007 19:00:27 GMT
Author: ngallardo
Date: Thu Jun 28 12:00:26 2007
New Revision: 551659

URL: http://svn.apache.org/viewvc?view=rev&rev=551659
Log:
LogicalMessage.getPayload() for faults causes ClassCastException

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerChainProcessor.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerChainProcessor.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerChainProcessor.java?view=diff&rev=551659&r1=551658&r2=551659
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerChainProcessor.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerChainProcessor.java
Thu Jun 28 12:00:26 2007
@@ -515,12 +515,14 @@
 
         // need to check if message is already a fault message or not,
         // probably by way of a flag (isFault) in the MessageContext or Message
+        if (log.isDebugEnabled()) {
+            log.debug("Creating a fault Message object for the exception: " + e.getClass().getName());
+        }
+           
         try {
-
             /* TODO TODO TODO
-                * There has GOT to be a better way to do this.
-                */
-
+             * There has GOT to be a better way to do this.
+             */
             if (protocol == Protocol.soap11 || protocol == Protocol.soap12) {
                 String protocolNS = (protocol == Protocol.soap11) ?
                         SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE :

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java?view=diff&rev=551659&r1=551658&r2=551659
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java
Thu Jun 28 12:00:26 2007
@@ -57,11 +57,14 @@
 import org.apache.axis2.jaxws.message.factory.MessageFactory;
 import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
 
 public class LogicalMessageImpl implements LogicalMessage {
 
+    private static final Log log = LogFactory.getLog(LogicalMessageImpl.class);
 
     private MEPContext mepCtx;
 
@@ -84,6 +87,10 @@
      * @see javax.xml.ws.LogicalMessage#getPayload(javax.xml.bind.JAXBContext)
      */
     public Object getPayload(JAXBContext context) {
+        if (log.isDebugEnabled()) {
+            log.debug("Retreiving the message payload as a Source object");
+        }
+        
         BlockFactory factory = (JAXBBlockFactory) FactoryRegistry.getFactory(JAXBBlockFactory.class);
         JAXBBlockContext jbc = new JAXBBlockContext(context);
         Object payload = _getPayload(jbc, factory);
@@ -94,16 +101,30 @@
         Object payload = null;
         try {
             Block block = mepCtx.getMessageObject().getBodyBlock(context, factory);
-            Object content = block.getBusinessObject(true);
-            
-            // For now, we have to create a new Block from the original content
-            // and set that back on the message.  The Block is not currently
-            // able to create a copy of itself just yet.
-            Payloads payloads = createPayloads(content);
-            
-            _setPayload(payloads.CACHE_PAYLOAD, context, factory);
-            
-            payload = payloads.HANDLER_PAYLOAD;
+            if (block != null) {
+               if (log.isDebugEnabled()) {
+                       log.debug("A message payload was found.");
+               }
+               Object content = block.getBusinessObject(true);
+               
+               // For now, we have to create a new Block from the original content
+               // and set that back on the message.  The Block is not currently
+               // able to create a copy of itself just yet.
+               Payloads payloads = createPayloads(content);
+               _setPayload(payloads.CACHE_PAYLOAD, context, factory);
+  
+               payload = payloads.HANDLER_PAYLOAD;             
+            }
+            else {
+                // If the block was null, then let's return an empty
+                // Source object rather than a null.
+                if (log.isDebugEnabled()) {
+                    log.debug("There was no payload to be found.  Returning an empty Source
object");
+                }
+                byte[] bytes = new byte[0];
+                payload = new StreamSource(new ByteArrayInputStream(bytes));
+           }
+   
         } catch (XMLStreamException e) {
             throw ExceptionFactory.makeWebServiceException(e);
         }
@@ -138,6 +159,10 @@
                 mepCtx.getMessageObject().setBodyBlock(block);
             }
             else {
+                if (log.isDebugEnabled()) {
+                    log.debug("The payload contains a fault");
+                }
+                
                 mepCtx.getMessageObject().setBodyBlock(block);
                 
                 // If the payload is a fault, then we can't set it back on the message
@@ -151,6 +176,9 @@
                     XMLStreamReader stream = StAXUtils.createXMLStreamReader(sr);
                     Message msg = mf.createFrom(stream, mepCtx.getMessageObject().getProtocol());
                    
+                    // This is required for proper serialization of the OM structure.
+                    msg.getAsOMElement().build();
+                    
                     mepCtx.setMessage(msg);
                 } catch (Exception e) {
                     throw ExceptionFactory.makeWebServiceException(e);

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java?view=diff&rev=551659&r1=551658&r2=551659
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java
Thu Jun 28 12:00:26 2007
@@ -118,7 +118,11 @@
       */
     public org.apache.axiom.soap.SOAPEnvelope toOM(SOAPEnvelope saajEnvelope)
             throws WebServiceException {
-        // Before we do the conversion, we have to fix the QNames for fault elements
+    	if (log.isDebugEnabled()) {
+    		log.debug("Converting SAAJ SOAPEnvelope to an OM SOAPEnvelope");
+    	}    	
+    	
+    	// Before we do the conversion, we have to fix the QNames for fault elements
         _fixFaultElements(saajEnvelope);        
         // Get a XMLStreamReader backed by a SOAPElement tree
         XMLStreamReader reader = new SOAPElementReader(saajEnvelope);
@@ -175,6 +179,10 @@
       * @see org.apache.axis2.jaxws.message.util.SAAJConverter#toOM(javax.xml.soap.SOAPElement)
       */
     public OMElement toOM(SOAPElement soapElement) throws WebServiceException {
+    	if (log.isDebugEnabled()) {
+    		log.debug("Converting SAAJ SOAPElement to an OMElement");
+    	}
+    	
         // Get a XMLStreamReader backed by a SOAPElement tree
         XMLStreamReader reader = new SOAPElementReader(soapElement);
         // Get a OM Builder.
@@ -196,7 +204,11 @@
       * @see org.apache.axis2.jaxws.message.util.SAAJConverter#toSAAJ(org.apache.axiom.om.OMElement,
javax.xml.soap.SOAPElement)
       */
     public SOAPElement toSAAJ(OMElement omElement, SOAPElement parent) throws WebServiceException
{
-        XMLStreamReader reader = null;
+    	if (log.isDebugEnabled()) {
+    		log.debug("Converting OMElement to an SAAJ SOAPElement");
+    	}
+    	
+    	XMLStreamReader reader = null;
 
         // If the OM element is not attached to a parser (builder), then the OM
         // is built and you cannot ask for XMLStreamReaderWithoutCaching.
@@ -225,7 +237,11 @@
       */
     public SOAPElement toSAAJ(OMElement omElement, SOAPElement parent, SOAPFactory sf)
             throws WebServiceException {
-        XMLStreamReader reader = null;
+    	if (log.isDebugEnabled()) {
+    		log.debug("Converting OMElement to an SAAJ SOAPElement");
+    	}
+    	
+    	XMLStreamReader reader = null;
 
         // If the OM element is not attached to a parser (builder), then the OM
         // is built and you cannot ask for XMLStreamReaderWithoutCaching.
@@ -510,14 +526,27 @@
             }
             
             SOAPBody body = env.getBody();
-            if (body != null && body.hasFault()) {
-                SOAPFault fault = body.getFault();
+            if (body != null && !body.hasFault()) {
+            	if (log.isDebugEnabled()) {
+            		log.debug("No fault found.  No conversion necessary.");
+            	}
+            	return;
+            }
+            else if (body != null && body.hasFault()) {
+                if (log.isDebugEnabled()) {
+                	log.debug("A fault was found.  Converting the fault child elements to SOAP
1.1 format");
+                }
+            	
+            	SOAPFault fault = body.getFault();
                 
                 Iterator itr = fault.getChildElements();
                 while (itr.hasNext()) {
                     SOAPElement se = (SOAPElement) itr.next();
                     if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME))
{ 
-                        // Axis2 SAAJ stores the acutal faultcode text under a SOAPFaultValue
object, so we have to 
+                    	if (log.isDebugEnabled()) {
+                    		log.debug("Converting: faultcode");
+                    	}
+                    	// Axis2 SAAJ stores the acutal faultcode text under a SOAPFaultValue
object, so we have to 
                         // get that and add it as a text node under the original element.
                         Node value = se.getFirstChild();
                         if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl)
{
@@ -532,9 +561,15 @@
                         }
                     }
                     else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME))
{
+                    	if (log.isDebugEnabled()) {
+                    		log.debug("Converting: detail");
+                    	}
                         se.setElementQName(new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
                     }
                     else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME))
{
+                    	if (log.isDebugEnabled()) {
+                    		log.debug("Converting: faultstring");
+                    	}
                         se.setElementQName(new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME));
                         // Axis2 SAAJ stores the acutal faultstring text under a SOAPFaultValue
object, so we have to 
                         // get that and add it as a text node under the original element.
@@ -553,6 +588,9 @@
                 }
             }
         } catch (SOAPException e) {
+        	if (log.isDebugEnabled()) {
+        		log.debug("An error occured while converting fault elements: " + e.getMessage());
+        	}
             throw ExceptionFactory.makeWebServiceException(e);
         }
     }



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


Mime
View raw message