servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r366162 - in /incubator/servicemix/trunk/servicemix-components/src: main/java/org/apache/servicemix/components/saaj/SaajMarshaler.java test/java/org/apache/servicemix/components/saaj/SaajMarshalerTest.java
Date Thu, 05 Jan 2006 11:19:51 GMT
Author: gnodet
Date: Thu Jan  5 03:19:43 2006
New Revision: 366162

URL: http://svn.apache.org/viewcvs?rev=366162&view=rev
Log:
Fix problems with saaj marshaler depending on implementation used.
Also fix SM-249.

Added:
    incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajMarshalerTest.java
Modified:
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajMarshaler.java

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajMarshaler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajMarshaler.java?rev=366162&r1=366161&r2=366162&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajMarshaler.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajMarshaler.java
Thu Jan  5 03:19:43 2006
@@ -18,7 +18,9 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
 
 import javax.activation.DataHandler;
 import javax.jbi.messaging.MessagingException;
@@ -65,9 +67,32 @@
 
         SOAPPart soapPart = soapMessage.getSOAPPart();
         SOAPBody soapBody = soapPart.getEnvelope().getBody();
-        SOAPElement elem = (SOAPElement) soapBody.getChildElements().next();
+        SOAPElement elem = null;
+        for (Iterator it = soapBody.getChildElements(); it.hasNext();) {
+        	Object child =  it.next();
+        	if (child instanceof SOAPElement) {
+        		elem = (SOAPElement) child;
+        		break;
+        	}
+        }
+        if (elem == null) {
+        	throw new IllegalStateException("Could not find any element in soap body");
+        }
         
         for (SOAPElement parent = elem.getParentElement(); parent != null; parent = parent.getParentElement())
{
+        	// The following code works with sun saaj implementation
+		    NamedNodeMap attributes = parent.getAttributes();
+		    if (attributes != null) {
+		        for (int i = 0; i < attributes.getLength(); i++) {
+		            Attr att = (Attr) parent.getAttributes().item(i);
+		            if (att.getName().startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")
+		                    && elem.getAttributeNodeNS(att.getNamespaceURI(), att.getLocalName())
== null) {
+		        		elem.addNamespaceDeclaration(att.getName().substring(XMLConstants.XMLNS_ATTRIBUTE.length()
+ 1), att.getValue());
+		                elem.setAttributeNS(att.getNamespaceURI(), att.getName(), att.getValue());
+		            }
+		        }
+		    }
+		    // The following code works with axis saaj implementation
         	for (Iterator itNs = parent.getNamespacePrefixes(); itNs.hasNext();) {
         		String prefix = (String) itNs.next();
         		String nsuri = parent.getNamespaceURI(prefix);
@@ -76,7 +101,7 @@
 	        		elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE
+ ":" + prefix, nsuri);
         		}
         	}
-        }
+		}
         
         if (log.isDebugEnabled()) {
         	try {

Added: incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajMarshalerTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajMarshalerTest.java?rev=366162&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajMarshalerTest.java
(added)
+++ incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajMarshalerTest.java
Thu Jan  5 03:19:43 2006
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.components.saaj;
+
+import java.io.InputStream;
+
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPMessage;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.apache.xpath.CachedXPathAPI;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.traversal.NodeIterator;
+
+import junit.framework.TestCase;
+
+public class SaajMarshalerTest extends TestCase {
+
+
+	public void testAxis() throws Exception {
+		MessageFactory messageFactory = new org.apache.axis.soap.MessageFactoryImpl();
+		testFactory(messageFactory);
+	}
+	
+	/*
+	public void testAxis2() throws Exception {
+		MessageFactory messageFactory = new org.apache.axis2.saaj.MessageFactoryImpl();
+		testFactory(messageFactory);
+	}
+	*/
+	
+	public void testSun() throws Exception {
+		MessageFactory messageFactory = new com.sun.xml.messaging.saaj.soap.MessageFactoryImpl();
+		testFactory(messageFactory);
+	}
+	
+	protected void testFactory(MessageFactory messageFactory) throws Exception {
+		MimeHeaders headers = new MimeHeaders();
+		headers.addHeader("Content-Type", "text/xml;");
+		InputStream is = getClass().getClassLoader().getResourceAsStream("org/apache/servicemix/components/http/soap-response.xml");
+		SOAPMessage sm = messageFactory.createMessage(headers, is);
+		NormalizedMessage nm = new NormalizedMessageImpl();
+		new SaajMarshaler().toNMS(nm, sm);
+
+        Node node = new SourceTransformer().toDOMNode(new SourceTransformer().toStreamSource(nm.getContent()));
+        System.out.println(new SourceTransformer().toString(node));
+		
+        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+        NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name()
= 'userId']");
+        Element root = (Element) iterator.nextNode();
+        QName qname = DOMUtil.createQName(root, root.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance",
"type"));
+        assertEquals("http://www.w3.org/2001/XMLSchema", qname.getNamespaceURI());
+        assertEquals("string", qname.getLocalPart());
+	}
+	
+}



Mime
View raw message