servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r359764 - in /incubator/servicemix/trunk/servicemix-components/src: main/java/org/apache/servicemix/components/http/ main/java/org/apache/servicemix/components/saaj/ test/java/org/apache/servicemix/components/http/
Date Thu, 29 Dec 2005 09:43:06 GMT
Author: gnodet
Date: Thu Dec 29 01:43:00 2005
New Revision: 359764

URL: http://svn.apache.org/viewcvs?rev=359764&view=rev
Log:
Fix problem with HttpSoap component when using Source others than DOM.
Also fix namespaces on SaajMarshaler

Modified:
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOutBinding.java
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajMarshaler.java
    incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOutBinding.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOutBinding.java?rev=359764&r1=359763&r2=359764&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOutBinding.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOutBinding.java
Thu Dec 29 01:43:00 2005
@@ -30,9 +30,12 @@
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
 
 import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.codehaus.xfire.DefaultXFire;
 import org.codehaus.xfire.MessageContext;
 import org.codehaus.xfire.XFire;
@@ -45,6 +48,7 @@
 import org.codehaus.xfire.service.binding.ObjectServiceFactory;
 import org.codehaus.xfire.soap.SoapConstants;
 import org.codehaus.xfire.transport.http.XFireServletController;
+import org.xml.sax.SAXException;
 
 public class HttpSoapInOutBinding extends ComponentSupport implements
         HttpBinding {
@@ -54,6 +58,7 @@
     protected Service service;
     protected boolean defaultInOut = true;
     protected String soapAction = "\"\"";
+    protected SourceTransformer transformer;
 
     public HttpSoapInOutBinding() {
     }
@@ -74,6 +79,7 @@
         }
         xfire.getServiceRegistry().register(service);
         controller = new Controller(xfire);
+        transformer = new SourceTransformer();
     }
     
     public void process(HttpServletRequest request, HttpServletResponse response)
@@ -137,10 +143,13 @@
             Source src = exchange.getOutMessage().getContent();
             exchange.setStatus(ExchangeStatus.DONE);
             channel.send(exchange);
+            src = transformer.toDOMSource(src);
             return src;
-        } catch (JBIException e) {
+        } catch (XFireFault e) {
+            throw e;
+        } catch (Exception e) {
             throw new XFireFault(e);
-        }
+		}
     }
     
     protected void populateExchange(MessageExchange exchange, Source src, MessageContext
ctx) throws JBIException {

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=359764&r1=359763&r2=359764&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 Dec 29 01:43:00 2005
@@ -24,6 +24,7 @@
 import javax.activation.DataHandler;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.XMLConstants;
 import javax.xml.soap.AttachmentPart;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.MimeHeader;
@@ -68,11 +69,12 @@
         SOAPElement elem = (SOAPElement) soapBody.getChildElements().next();
         
         for (SOAPElement parent = elem.getParentElement(); parent != null; parent = parent.getParentElement())
{
-        	for (int i = 0; i < parent.getAttributes().getLength(); i++) {
-        		Attr att = (Attr) parent.getAttributes().item(i);
-        		if (att.getName().startsWith("xmlns:") && 
-        			elem.getAttributeNodeNS(att.getNamespaceURI(), att.getLocalName()) == null) {
-        			elem.setAttributeNS(att.getNamespaceURI(), att.getName(), att.getValue());
+        	for (Iterator itNs = parent.getNamespacePrefixes(); itNs.hasNext();) {
+        		String prefix = (String) itNs.next();
+        		String nsuri = parent.getNamespaceURI(prefix);
+        		if (elem.getAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix) == null) {
+	        		elem.addNamespaceDeclaration(prefix, nsuri);
+	        		elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE
+ ":" + prefix, nsuri);
         		}
         	}
         }

Modified: incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java?rev=359764&r1=359763&r2=359764&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
Thu Dec 29 01:43:00 2005
@@ -23,29 +23,44 @@
 
 import javax.xml.messaging.URLEndpoint;
 import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerException;
 
 import junit.framework.TestCase;
 
-import org.apache.servicemix.components.http.HttpSoapConnector;
+import org.activemq.broker.BrokerService;
+import org.activemq.xbean.BrokerFactoryBean;
 import org.apache.servicemix.components.saaj.SaajBinding;
 import org.apache.servicemix.jbi.container.ActivationSpec;
 import org.apache.servicemix.jbi.container.JBIContainer;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.util.DOMUtil;
 import org.apache.servicemix.jbi.util.FileUtil;
+import org.apache.xpath.CachedXPathAPI;
+import org.springframework.core.io.ClassPathResource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.traversal.NodeIterator;
 
 public class HttpSoapAndSaajTest extends TestCase {
     
     private static final int PORT = 7012;
 
     protected JBIContainer container;
+	protected BrokerService broker;
     
     protected void setUp() throws Exception {
+        BrokerFactoryBean bfb = new BrokerFactoryBean(new ClassPathResource("broker.xml"));
+        bfb.afterPropertiesSet();
+        broker = bfb.getBroker();
+        broker.start();
         container = new JBIContainer();
         container.setMonitorInstallationDirectory(false);
         container.setUseMBeanServer(false);
         container.setCreateMBeanServer(false);
         container.setEmbedded(true);
+        container.setFlowName("jms?jmsURL=tcp://localhost:61626");
         container.init();
         container.start();
     }
@@ -54,6 +69,9 @@
         if (container != null) {
             container.shutDown();
         }
+        if (broker != null) {
+        	broker.stop();
+        }
     }
     
     public void testInOut() throws Exception {
@@ -85,7 +103,29 @@
         System.out.println(baos.toString());
         
         // Check xml validity
-        new SourceTransformer().toDOMNode(new StringSource(baos.toString()));
+        Node node = new SourceTransformer().toDOMNode(new StringSource(baos.toString()));
+        
+        String text = textValueOfXPath(node, "//Result").trim();
+
+        System.out.println("Found price: " + text);
+
+        assertTrue("price text should not be empty", text.length() > 0);
     }
 
+    protected String textValueOfXPath(Node node, String xpath) throws TransformerException
{
+        CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+        NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, xpath);
+        Node root = iterator.nextNode();
+        if (root instanceof Element) {
+            Element element = (Element) root;
+            if (element == null) {
+                return "";
+            }
+            String text = DOMUtil.getElementText(element);
+            return text;
+        }
+        else {
+            return root.getNodeValue();
+        }
+    }
 }



Mime
View raw message