servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r579619 - in /incubator/servicemix/trunk/common/servicemix-soap/src: main/java/org/apache/servicemix/soap/handlers/addressing/ test/java/org/apache/servicemix/soap/handlers/addressing/
Date Wed, 26 Sep 2007 11:57:37 GMT
Author: gnodet
Date: Wed Sep 26 04:57:37 2007
New Revision: 579619

URL: http://svn.apache.org/viewvc?rev=579619&view=rev
Log:
SM-1021: DOMException: NAMESPACE_ERR

Added:
    incubator/servicemix/trunk/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/addressing/
    incubator/servicemix/trunk/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandlerTest.java
Modified:
    incubator/servicemix/trunk/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandler.java

Modified: incubator/servicemix/trunk/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandler.java?rev=579619&r1=579618&r2=579619&view=diff
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandler.java
(original)
+++ incubator/servicemix/trunk/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandler.java
Wed Sep 26 04:57:37 2007
@@ -118,10 +118,33 @@
     protected DocumentFragment createHeader(QName name, String value) throws Exception {
         Document doc = new SourceTransformer().createDocument();
         DocumentFragment df = doc.createDocumentFragment();
-        Element el = doc.createElementNS(name.getNamespaceURI(), name.getPrefix() + ":" +
name.getLocalPart());
+        Element el = doc.createElementNS(name.getNamespaceURI(), getQualifiedName(name));
         el.appendChild(doc.createTextNode(value));
         df.appendChild(el);
         return df;
     }
     
+    /**
+     * Gets the QName prefix.  If the QName has no set prefix, the specified default prefix
will be used.
+     */    
+    protected String getPrefix(QName qname, String defaultPrefix) {
+    	String prefix = qname.getPrefix();
+    	if(null == prefix || "".equals(prefix)) {
+    		prefix = defaultPrefix;
+    	}
+    	
+    	return prefix;
+    }
+    
+    protected String getQualifiedName(QName qname) {
+    	String name = qname.getLocalPart();
+    	
+    	String prefix = qname.getPrefix();
+    	if(null != prefix && (!"".equals(prefix))) {
+    		name = prefix + ":" + name;
+    	}
+    	
+    	return name;
+    }
+  
 }

Added: incubator/servicemix/trunk/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandlerTest.java?rev=579619&view=auto
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandlerTest.java
(added)
+++ incubator/servicemix/trunk/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandlerTest.java
Wed Sep 26 04:57:37 2007
@@ -0,0 +1,89 @@
+package org.apache.servicemix.soap.handlers.addressing;
+
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.soap.Context;
+import org.apache.servicemix.soap.marshalers.SoapMessage;
+import org.w3c.dom.DocumentFragment;
+
+import junit.framework.TestCase;
+
+public class AddressingHandlerTest extends TestCase {
+
+
+	private AddressingHandler handler;
+
+	public AddressingHandlerTest(String name) {
+		super(name);
+	}
+
+	protected void setUp() throws Exception {
+		this.handler = new AddressingHandler();
+	}
+	
+	public void testCreateHeader() throws Exception {
+		QName messageIdQN = new QName(AddressingHandler.WSA_NAMESPACE_200408, AddressingHandler.EL_MESSAGE_ID,
AddressingHandler.WSA_PREFIX);
+		String messageId = "uuid:1234567890";
+		DocumentFragment wsaMessageId = this.handler.createHeader(messageIdQN, messageId);
+
+		assertNotNull("DocumentFragment is null", wsaMessageId);
+		assertEquals("messageId", messageId, wsaMessageId.getTextContent());
+		
+	}
+	
+	public void testWSAEmptyPrefix() throws Exception {
+		// setup
+		QName messageIdQN = new QName(AddressingHandler.WSA_NAMESPACE_200408, AddressingHandler.EL_MESSAGE_ID,
"");
+		QName relatesToQN = new QName(AddressingHandler.WSA_NAMESPACE_200408, AddressingHandler.EL_RELATES_TO,
"");
+
+		
+		// create messages and add them to the context
+		Context msgContext = new Context();
+		SoapMessage inMessage = new SoapMessage();
+		SoapMessage outMessage = new SoapMessage();
+		msgContext.setInMessage(inMessage);
+		msgContext.setOutMessage(outMessage);
+		
+		// add wsa MessageID header to in message
+		String messageId = "uuid:1234567890";
+		DocumentFragment wsaMessageId = this.handler.createHeader(messageIdQN, messageId);
+		inMessage.addHeader(messageIdQN, wsaMessageId);
+		
+		// run handler
+		this.handler.onReply(msgContext);
+		
+		// verify relates-to
+		DocumentFragment wsaRelatesTo = (DocumentFragment) outMessage.getHeaders().get(relatesToQN);
+		assertNotNull("No RelatesTo header", wsaRelatesTo);
+		assertEquals("Value", messageId, wsaRelatesTo.getTextContent());
+	}
+	
+	public void testWSAPrefix() throws Exception {
+		// setup
+		QName messageIdQN = new QName(AddressingHandler.WSA_NAMESPACE_200408, AddressingHandler.EL_MESSAGE_ID,
AddressingHandler.WSA_PREFIX);
+		QName relatesToQN = new QName(AddressingHandler.WSA_NAMESPACE_200408, AddressingHandler.EL_RELATES_TO,
AddressingHandler.WSA_PREFIX);
+
+		
+		// create messages and add them to the context
+		Context msgContext = new Context();
+		SoapMessage inMessage = new SoapMessage();
+		SoapMessage outMessage = new SoapMessage();
+		msgContext.setInMessage(inMessage);
+		msgContext.setOutMessage(outMessage);
+		
+		// add wsa MessageID header to in message
+		String messageId = "uuid:1234567890";
+		DocumentFragment wsaMessageId = this.handler.createHeader(messageIdQN, messageId);
+		inMessage.addHeader(messageIdQN, wsaMessageId);
+		
+		// run handler
+		this.handler.onReply(msgContext);
+		
+		// verify relates-to
+		DocumentFragment wsaRelatesTo = (DocumentFragment) outMessage.getHeaders().get(relatesToQN);
+		assertNotNull("No RelatesTo header", wsaRelatesTo);
+		assertEquals("Value", messageId, wsaRelatesTo.getTextContent());
+	}
+	
+
+}



Mime
View raw message