axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wood...@apache.org
Subject svn commit: r818096 - in /webservices/axis2/trunk/java/modules/kernel: src/org/apache/axis2/util/MessageContextBuilder.java test/org/apache/axis2/util/MessageContextBuilderTest.java
Date Wed, 23 Sep 2009 13:23:15 GMT
Author: woodroy
Date: Wed Sep 23 13:23:15 2009
New Revision: 818096

URL: http://svn.apache.org/viewvc?rev=818096&view=rev
Log:
Apply proper namespace qualification to SOAPFaultCode text field per SOAP specification

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/util/MessageContextBuilderTest.java

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?rev=818096&r1=818095&r2=818096&view=diff
==============================================================================
--- 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
Wed Sep 23 13:23:15 2009
@@ -436,7 +436,10 @@
      */
     private static SOAPEnvelope createFaultEnvelope(MessageContext context, Throwable e)
{
         SOAPEnvelope envelope;
-
+        
+        if(log.isDebugEnabled()){
+        	log.debug("start createFaultEnvelope()");
+        }
         if (context.isSOAP11()) {
             envelope = OMAbstractFactory.getSOAP11Factory().getDefaultFaultEnvelope();
         } else {
@@ -444,7 +447,6 @@
             envelope = OMAbstractFactory.getSOAP12Factory().getDefaultFaultEnvelope();
         }
         SOAPFault fault = envelope.getBody().getFault();
-
         SOAPProcessingException soapException = null;
         AxisFault axisFault = null;
 
@@ -479,17 +481,83 @@
         String soapFaultCode = "";
 
         if (faultCode != null) {
+        	if(log.isDebugEnabled()){
+        		log.debug("faultCode != null");
+        	}
             fault.setCode((SOAPFaultCode) faultCode);
         } else if (soapException != null) {
+        	if(log.isDebugEnabled()){
+        		log.debug("soapException != null");
+        	}
             soapFaultCode = soapException.getFaultCode();
+            OMNamespace namespace = null;
+            if(envelope!=null){
+            	if(log.isDebugEnabled()){
+            		log.debug("envelope!=null");
+            	}	
+            	namespace = envelope.getNamespace();
+            }
+            
+            if (namespace != null){
+                String sfcLocalPart = soapFaultCode.substring(soapFaultCode.lastIndexOf(":")+1);
+      
+                //If the fault code is one of the predefined ones that make sure the prefix

+                //matches that of the envelope NS
+                if (sfcLocalPart.equals(SOAPConstants.FAULT_CODE_VERSION_MISMATCH) ||
+                    sfcLocalPart.equals(SOAPConstants.FAULT_CODE_MUST_UNDERSTAND) ||
+                    sfcLocalPart.equals(SOAPConstants.FAULT_CODE_DATA_ENCODING_UNKNOWN) ||
+                    sfcLocalPart.equals(SOAPConstants.FAULT_CODE_RECEIVER) ||
+                    sfcLocalPart.equals(SOAPConstants.FAULT_CODE_SENDER)) {
+                
+                    if(log.isDebugEnabled()){
+                        log.debug("SoapFaultCode local part= " +sfcLocalPart);
+                    }
+
+                    String prefix = namespace.getPrefix() + ":";
+
+                    if (!soapFaultCode.contains(":")) {
+                        soapFaultCode = prefix + soapFaultCode;
+                    } else {
+                        soapFaultCode = prefix + soapFaultCode.substring(soapFaultCode.indexOf(":")+1);
+                    }
+
+                    if(log.isDebugEnabled()){
+                        log.debug("SoapFaultCode reset to " +soapFaultCode);
+                    }
+
+                }
+            } else {
+                if(log.isDebugEnabled()){
+                    log.debug("Namespace is null, cannot attach prefix to SOAPFaultCode");
+                }
+            }
+            
+            if(log.isDebugEnabled()){        	
+                log.debug("SoapFaultCode ="+soapFaultCode);        	
+            }
+        	
         } else if (axisFault != null) {
+        	if(log.isDebugEnabled()){
+        		log.debug("axisFault != null");
+        	}
             if (axisFault.getFaultCodeElement() != null) {
                 fault.setCode(axisFault.getFaultCodeElement());
             } else {
                 QName faultCodeQName = axisFault.getFaultCode();
                 if (faultCodeQName != null) {
+                	if(log.isDebugEnabled()){
+                		log.debug("prefix ="+faultCodeQName.getPrefix());
+                		log.debug("Fault Code namespace ="+faultCodeQName.getNamespaceURI());
+                		log.debug("Fault Code ="+faultCodeQName.getLocalPart());
+                	}
                     if (faultCodeQName.getLocalPart().indexOf(":") == -1) {
+                    	if(log.isDebugEnabled()){
+                    		log.debug("faultCodeQName.getLocalPart().indexOf(\":\") == -1");
+                    	}
                         String prefix = faultCodeQName.getPrefix();
+                        if(log.isDebugEnabled()){
+                        	log.debug("prefix = "+prefix);
+                        }
                         String uri = faultCodeQName.getNamespaceURI();
                         // Get the specified prefix and uri
                         prefix = prefix == null ? "" : prefix;
@@ -499,6 +567,9 @@
                         // get the resulting prefix.
                         prefix = fault.declareNamespace(uri, prefix).getPrefix();
                         soapFaultCode = prefix + ":" + faultCodeQName.getLocalPart();
+                        if(log.isDebugEnabled()){
+                        	log.debug("Altered soapFaultCode ="+soapFaultCode);
+                        }
                     } else {
                         soapFaultCode = faultCodeQName.getLocalPart();
                     }
@@ -515,9 +586,35 @@
         }
         
         if (faultCode == null) {
+        	if(log.isDebugEnabled()){
+        		log.debug("faultCode == null");
+        	}
             if (context.isSOAP11()) {
+            	if(log.isDebugEnabled()){
+            		log.debug("context.isSOAP11() = true");
+            		SOAPFaultCode code = (fault!=null)?fault.getCode():null;
+            		SOAPFaultValue value = (code!=null)?code.getValue():null;
+            		if(value !=null){
+            			QName name = value.getQName();
+            			log.debug("prefix ="+name.getPrefix());
+            			log.debug("Fault Code namespace ="+name.getNamespaceURI());
+            			log.debug("Fault Code ="+name.getLocalPart());
+            		}
+            	}
+
                 fault.getCode().setText(soapFaultCode);
             } else {
+            	if(log.isDebugEnabled()){
+            		log.debug("context.isSOAP11() = false");
+            		SOAPFaultCode code = (fault!=null)?fault.getCode():null;
+            		SOAPFaultValue value = (code!=null)?code.getValue():null;
+            		if(value !=null){
+            			QName name = value.getQName();
+            			log.debug("prefix ="+name.getPrefix());
+            			log.debug("Fault Code namespace ="+name.getNamespaceURI());
+            			log.debug("Fault Code ="+name.getLocalPart());
+            		}
+            	}
                 SOAPFaultValue value = fault.getCode().getValue();
                 if(log.isDebugEnabled()){
                     log.debug("soapFaultCode originally was set to : " + soapFaultCode);
@@ -642,7 +739,9 @@
                 fault.setException(new Exception(e));
             }
         }
-
+        
+        if(log.isDebugEnabled())
+            log.debug("End createFaultEnvelope()");
         return envelope;
     }
     
@@ -687,7 +786,6 @@
 
     
     
-    
     /**
      * By the time the exception comes here it can be wrapped by so many levels. This will
crip down
      * to the root cause and get the initial error depending on the property

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/util/MessageContextBuilderTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/util/MessageContextBuilderTest.java?rev=818096&r1=818095&r2=818096&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/util/MessageContextBuilderTest.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/util/MessageContextBuilderTest.java
Wed Sep 23 13:23:15 2009
@@ -1,13 +1,39 @@
 package org.apache.axis2.util;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import javax.xml.stream.XMLStreamException;
+
 import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.OMNamespaceImpl;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPConstants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFault;
+import org.apache.axiom.soap.SOAPProcessingException;
+import org.apache.axis2.builder.SOAPBuilder;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.engine.AxisConfiguration;
+
 import org.apache.axis2.namespace.Constants;
+import org.apache.axis2.AbstractTestCase;
+import org.apache.axis2.AxisFault;
+
 
-public class MessageContextBuilderTest extends TestCase {
+public class MessageContextBuilderTest extends AbstractTestCase {
     private OMNamespaceImpl nsp = new OMNamespaceImpl(Constants.URI_SOAP11_ENV, "soapenv");
 
+    public MessageContextBuilderTest(String testName) {
+        super(testName);
+    }
+
+    
     public void testSwitchNamespacePrefixes()
             throws Exception {
 
@@ -23,4 +49,35 @@
         assertEquals("soapenv:" + SOAPConstants.FAULT_CODE_VERSION_MISMATCH,
                 MessageContextBuilder.switchNamespacePrefix(":" + SOAPConstants.FAULT_CODE_VERSION_MISMATCH,
nsp));
     }
+    
+    public void testElementNamespaces() throws Exception {
+        File file = getTestResourceFile("soapmessage.xml");
+        SOAPBuilder soapBuilder = new SOAPBuilder();
+        FileInputStream fis = new FileInputStream(file);
+        MessageContext mc = new MessageContext();
+        
+        //Set up a mock envelope
+        try {   
+            OMElement envelope = soapBuilder.processDocument(fis, SOAP11Constants.SOAP_11_CONTENT_TYPE,
mc);   
+        } catch (Exception e) {
+        }
+
+        SOAPProcessingException e =  new SOAPProcessingException(
+            "Transport level information does not match with SOAP" +
+                    " Message namespace URI", "S:"  + ":" +
+                        SOAPConstants.FAULT_CODE_VERSION_MISMATCH);
+
+        AxisFault axisFault = AxisFault.makeFault(e);
+        ConfigurationContext configContext = new ConfigurationContext(new AxisConfiguration());
+        mc.setConfigurationContext(configContext);
+        MessageContext faultContext = MessageContextBuilder.createFaultMessageContext(mc,
axisFault);
+
+        SOAPFault fault = faultContext.getEnvelope().getBody().getFault();
+        String se = faultContext.getEnvelope().getNamespace().getPrefix();
+        
+        assertEquals (fault.getCode().getTextAsQName().getPrefix(), se);
+    }
+
+    
+    
 }
\ No newline at end of file



Mime
View raw message