[jboss-svn-commits] JBossWS SVN: r772 - in branches/jbossws-1.0/src: main/java/org/jboss/ws/soap test/java/org/jboss/test/ws/soap

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 18 08:58:59 EDT 2006


Author: heiko.braun at jboss.com
Date: 2006-08-18 08:58:50 -0400 (Fri, 18 Aug 2006)
New Revision: 772

Modified:
   branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/DOMEnvelopeBuilder.java
   branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/MessageFactoryImpl.java
   branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPConnectionImpl.java
   branches/jbossws-1.0/src/test/java/org/jboss/test/ws/soap/MessageFactoryTestCase.java
   branches/jbossws-1.0/src/test/java/org/jboss/test/ws/soap/SAAJElementWriterTestCase.java
Log:
Fix JBWS-1138

Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/DOMEnvelopeBuilder.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/DOMEnvelopeBuilder.java	2006-08-18 12:58:20 UTC (rev 771)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/DOMEnvelopeBuilder.java	2006-08-18 12:58:50 UTC (rev 772)
@@ -6,10 +6,8 @@
 import org.jboss.xb.binding.NamespaceRegistry;
 import org.jboss.ws.jaxrpc.Style;
 import org.jboss.ws.WSException;
-import org.jboss.ws.Constants;
 
 import javax.xml.soap.*;
-import javax.xml.soap.Node;
 import javax.xml.namespace.QName;
 import java.io.InputStream;
 import java.io.IOException;
@@ -78,7 +76,7 @@
          while (it.hasNext())
          {
             Element srcElement = (Element)it.next();
-            //registerLocalNamespace(srcElement);
+            //registerNamespacesLocally(srcElement);
             String xmlFragment = DOMWriter.printNode(srcElement, false);
 
             Name name = new NameImpl(srcElement.getLocalName(), srcElement.getPrefix(), srcElement.getNamespaceURI());
@@ -166,7 +164,7 @@
                while (itBodyElement.hasNext())
                {
                   Element srcElement = (Element)itBodyElement.next();
-                  registerLocalNamespace(srcElement);
+                  registerNamespacesLocally(srcElement);
 
                   Name name = new NameImpl(srcElement.getLocalName(), srcElement.getPrefix(), srcElement.getNamespaceURI());
                   SOAPContentElement destElement = new SOAPContentElement(name);
@@ -195,6 +193,8 @@
             else if (style == Style.DOCUMENT)
             {
                Element srcElement = (Element)domBodyElement;
+               registerNamespacesLocally(srcElement);
+
                SOAPBodyElementDoc destElement = new SOAPBodyElementDoc(beName);
                destElement = (SOAPBodyElementDoc)soapBody.addChildElement(destElement);
 
@@ -244,7 +244,11 @@
       return soapEnv;
    }
 
-   private void registerLocalNamespace(Element srcElement) {
+   /**
+    * Register globally available namespaces on element level.
+    * This is necessary to ensure that each xml fragment is valid.    
+    */
+   private void registerNamespacesLocally(Element srcElement) {
       if(srcElement.getPrefix()== null)
       {
          srcElement.setAttribute("xmlns", srcElement.getNamespaceURI());

Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/MessageFactoryImpl.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/MessageFactoryImpl.java	2006-08-18 12:58:20 UTC (rev 771)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/MessageFactoryImpl.java	2006-08-18 12:58:50 UTC (rev 772)
@@ -23,22 +23,6 @@
 
 // $Id$
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.Iterator;
-
-import javax.mail.internet.ContentType;
-import javax.mail.internet.ParseException;
-import javax.xml.soap.AttachmentPart;
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.MimeHeader;
-import javax.xml.soap.MimeHeaders;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPMessage;
-
 import org.jboss.logging.Logger;
 import org.jboss.ws.Constants;
 import org.jboss.ws.jaxrpc.Style;
@@ -47,6 +31,16 @@
 import org.jboss.ws.utils.IOUtils;
 import org.jboss.ws.utils.ThreadLocalAssociation;
 
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
+import javax.xml.soap.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.Iterator;
+
 /**
  * MessageFactory implementation
  * 
@@ -219,7 +213,9 @@
       if (attachments != null)
          soapMessage.setAttachments(attachments);
 
-      SAAJEnvelopeBuilder envelopeBuilder = new DOMEnvelopeBuilder();
+      // create the SAAJ object model
+      SAAJEnvelopeBuilderFactory builderFactory = SAAJEnvelopeBuilderFactory.newInstance();
+      SAAJEnvelopeBuilder envelopeBuilder = builderFactory.createSAAJEnvelopeBuilder();
       envelopeBuilder.setIgnoreParseException(ingnoreParseException);
       envelopeBuilder.setStyle(getStyle());
       envelopeBuilder.setSOAPMessage(soapMessage);

Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPConnectionImpl.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPConnectionImpl.java	2006-08-18 12:58:20 UTC (rev 771)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/soap/SOAPConnectionImpl.java	2006-08-18 12:58:50 UTC (rev 772)
@@ -71,6 +71,8 @@
    private static Map<String, String> configMap = new HashMap<String, String>();
    static
    {
+      //  Remoting 2.0.0
+      //  configMap.put(StubExt.PROPERTY_KEY_STORE, SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH);
       configMap.put(StubExt.PROPERTY_KEY_STORE, RemotingSSLSocketFactory.REMOTING_KEY_STORE_FILE_PATH);
       configMap.put(StubExt.PROPERTY_KEY_STORE_PASSWORD, RemotingSSLSocketFactory.REMOTING_KEY_STORE_PASSWORD);
       configMap.put(StubExt.PROPERTY_KEY_STORE_TYPE, RemotingSSLSocketFactory.REMOTING_KEY_STORE_TYPE);
@@ -120,7 +122,7 @@
          EndpointInfo epInfo = (EndpointInfo)endpoint;
          targetAddress = epInfo.getTargetAddress();
          callProps = epInfo.getProperties();
-         
+
          if (callProps.containsKey(StubExt.PROPERTY_CLIENT_TIMEOUT))
          {
             Object timeout = callProps.get(StubExt.PROPERTY_CLIENT_TIMEOUT);
@@ -139,7 +141,7 @@
          targetAddress = endpoint.toString();
          callProps = null;
       }
-      
+
       try
       {
          // Get the invoker from Remoting for a given endpoint address
@@ -152,10 +154,12 @@
       }
 
       Map metadata = getRemotingMetaData(reqMessage, targetAddress, callProps);
-      
+
       try
       {
          remotingClient = new Client(locator, "saaj", config);
+         // Remoting 2.0.0
+         // remotingClient.connect();
          remotingClient.setMarshaller(new SOAPMessageMarshaller());
          remotingClient.setUnMarshaller(oneway == false ? new SOAPMessageUnMarshaller() : null);
       }

Modified: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/soap/MessageFactoryTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/soap/MessageFactoryTestCase.java	2006-08-18 12:58:20 UTC (rev 771)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/soap/MessageFactoryTestCase.java	2006-08-18 12:58:50 UTC (rev 772)
@@ -22,17 +22,15 @@
 package org.jboss.test.ws.soap;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPBodyElement;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.*;
 
 import org.jboss.test.ws.JBossWSTest;
 import org.jboss.util.xml.DOMUtils;
 import org.jboss.ws.Constants;
-import org.jboss.ws.soap.MessageFactoryImpl;
+import org.jboss.ws.jaxrpc.Style;
+import org.jboss.ws.soap.*;
 import org.w3c.dom.Element;
 
 /**
@@ -103,4 +101,46 @@
       Element expEnv = DOMUtils.parse(expEnvStr);
       assertEquals(expEnv, env);
    }
+
+   // http://jira.jboss.org/jira/browse/JBWS-1138
+   public void testJBWS1138() throws Exception
+   {
+      String xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" "
+                  +"xmlns:typ=\"http://www.jboss.org/support/phonebook/types\">\n" +
+          "   <soapenv:Body>\n" +
+          "      <typ:lookup>\n" +
+          "         <firstName>Darran</firstName>\n" +
+          "         <surname>Lofthouse</surname>\n" +
+          "      </typ:lookup>\n" +
+          "   </soapenv:Body>\n" +
+          "</soapenv:Envelope> ";
+
+      MessageFactory factory = new MessageFactoryImpl();
+      SOAPMessage soapMsg = factory.createMessage();
+
+      SAAJEnvelopeBuilder envelopeBuilder = SAAJEnvelopeBuilderFactory.newInstance().createSAAJEnvelopeBuilder();
+      envelopeBuilder.setIgnoreParseException(false);
+      envelopeBuilder.setStyle(Style.DOCUMENT);
+      envelopeBuilder.setSOAPMessage(soapMsg);
+      envelopeBuilder.build(new ByteArrayInputStream(xml.getBytes()));
+
+      SOAPBody body = soapMsg.getSOAPBody();
+      SOAPElement payload = (SOAPElement)body.getChildElements().next();
+      assertTrue(payload instanceof SOAPContentElement);
+
+      SOAPContentElement sce = (SOAPContentElement)payload;
+      try
+      {
+         DOMUtils.parse(
+             new ByteArrayInputStream(sce.getXMLFragment().getBytes())
+         );
+      }
+      catch (IOException e)
+      {
+         // fails due to missing NS declaration
+         fail(e.getMessage());
+      }
+
+   }
+
 }

Modified: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/soap/SAAJElementWriterTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/soap/SAAJElementWriterTestCase.java	2006-08-18 12:58:20 UTC (rev 771)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/soap/SAAJElementWriterTestCase.java	2006-08-18 12:58:50 UTC (rev 772)
@@ -63,7 +63,7 @@
       for(int i=1; i<10; i++)
       {
          String fileName = "resources/soap/req" + i + ".xml";
-         //System.out.println("Testing " + fileName);
+         System.out.println("\nTesting " + fileName);
 
          File source = new File(fileName);
          InputStream inputStream = new BufferedInputStream(new FileInputStream(source));
@@ -75,8 +75,13 @@
 
          try
          {
-            String xml = dump(env);
-            verify(xml);
+            String saajMarshalled = marshall(env);
+            String domMarshalled = verify(saajMarshalled);
+
+            System.out.println(saajMarshalled);
+            System.out.println("");
+            System.out.println(domMarshalled);
+
          }
          catch (Exception e)
          {
@@ -103,7 +108,7 @@
          SOAPMessage soapMsg = factory.createMessage(null, inputStream);
          SOAPEnvelope env = soapMsg.getSOAPPart().getEnvelope();
 
-         String xml = dump(env);
+         String xml = marshall(env);
          verify(xml);
       }
   }
@@ -123,12 +128,12 @@
           SOAPMessage soapMsg = factory.createMessage(null, inputStream);
           SOAPEnvelope env = soapMsg.getSOAPPart().getEnvelope();
 
-          String xml = dump(env);
+          String xml = marshall(env);
           verify(xml);
        }
    }
 
-   private String dump(SOAPEnvelope env) throws Exception
+   private String marshall(SOAPEnvelope env) throws Exception
    {
       String xml = SAAJElementWriter.printSOAPElement((SOAPElementImpl)env, true);
       //System.out.println(xml);
@@ -136,7 +141,7 @@
       return xml;
    }
 
-   private void verify(String xml) throws Exception {
+   private String verify(String xml) throws Exception {
       ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes());
 
       MessageFactoryImpl factory = new MessageFactoryImpl();
@@ -144,8 +149,6 @@
       SOAPMessage soapMsg = factory.createMessage(null, inputStream);
       SOAPEnvelope env = soapMsg.getSOAPPart().getEnvelope();
 
-      String marshalled = DOMWriter.printNode(env, true);
-      //System.out.println( marshalled );
-      //System.out.println("\n\n");
+      return DOMWriter.printNode(env, true);
    }
 }




More information about the jboss-svn-commits mailing list