You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/03/23 13:28:07 UTC

svn commit: r388152 - in /incubator/servicemix/trunk: servicemix-http/src/main/java/org/apache/servicemix/http/ servicemix-http/src/test/java/org/apache/servicemix/http/ servicemix-jms/src/main/java/org/apache/servicemix/jms/ servicemix-soap/src/main/j...

Author: gnodet
Date: Thu Mar 23 04:28:02 2006
New Revision: 388152

URL: http://svn.apache.org/viewcvs?rev=388152&view=rev
Log:
Ensure that WSDL is only build once from the DOM document

Modified:
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
    incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java?rev=388152&r1=388151&r2=388152&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java Thu Mar 23 04:28:02 2006
@@ -217,6 +217,15 @@
                 logger.warn("Could not create document from wsdl description", e);
             }
         }
+        // If the dom description is provided
+        // convert it to a WSDL definition
+        if (definition == null && description != null) {
+            try {
+                definition = WSDLFactory.newInstance().newWSDLReader().readWSDL(null, description);
+            } catch (Exception e) {
+                logger.warn("Could not create wsdl definition from dom document", e);
+            }
+        }
     }
 
     /**

Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java?rev=388152&r1=388151&r2=388152&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpSpringTest.java Thu Mar 23 04:28:02 2006
@@ -17,8 +17,6 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
 
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOut;
@@ -31,13 +29,11 @@
 import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
 import org.apache.commons.httpclient.methods.multipart.Part;
 import org.apache.commons.httpclient.methods.multipart.StringPart;
-import org.apache.commons.httpclient.util.EncodingUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.client.DefaultServiceMixClient;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
-import org.apache.servicemix.soap.marshalers.SoapMarshaler;
 import org.apache.servicemix.tck.SpringTestSupport;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java?rev=388152&r1=388151&r2=388152&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java Thu Mar 23 04:28:02 2006
@@ -246,6 +246,15 @@
                 logger.warn("Could not create document from wsdl description", e);
             }
         }
+        // If the dom description is provided
+        // convert it to a WSDL definition
+        if (definition == null && description != null) {
+            try {
+                definition = WSDLFactory.newInstance().newWSDLReader().readWSDL(null, description);
+            } catch (Exception e) {
+                logger.warn("Could not create wsdl definition from dom document", e);
+            }
+        }
     }
 
     /**

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java?rev=388152&r1=388151&r2=388152&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java Thu Mar 23 04:28:02 2006
@@ -17,8 +17,10 @@
 
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import javax.jbi.component.ComponentContext;
 import javax.jbi.messaging.DeliveryChannel;
@@ -30,10 +32,13 @@
 import javax.wsdl.Definition;
 import javax.wsdl.Operation;
 import javax.wsdl.PortType;
+import javax.wsdl.WSDLException;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
 import javax.xml.namespace.QName;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.soap.marshalers.JBIMarshaler;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
 import org.w3c.dom.Document;
@@ -47,6 +52,8 @@
  */
 public class SoapHelper {
 
+    private static final Log logger = LogFactory.getLog(SoapHelper.class);
+    
     public static final URI IN_ONLY = URI.create("http://www.w3.org/2004/08/wsdl/in-only");
     public static final URI IN_OUT = URI.create("http://www.w3.org/2004/08/wsdl/in-out");
     public static final URI ROBUST_IN_ONLY = URI.create("http://www.w3.org/2004/08/wsdl/robust-in-only");
@@ -54,14 +61,12 @@
 	private SoapEndpoint endpoint;
     private List policies;
     private JBIMarshaler jbiMarshaler;
-	
-	public SoapHelper() {
-		this.policies = new ArrayList();
-        this.jbiMarshaler = new JBIMarshaler();
-	}
+    private Map definitions;
 	
 	public SoapHelper(SoapEndpoint endpoint) {
-		this();
+        this.policies = new ArrayList();
+        this.definitions = new HashMap();
+        this.jbiMarshaler = new JBIMarshaler();
 		this.endpoint = endpoint;
 	}
 	
@@ -146,22 +151,32 @@
 		if (se == null) {
 			// Get this endpoint definition
 			definition = endpoint.getDefinition();
-			if (definition == null && endpoint.getDescription() != null) {
-				// Eventually parse the definition
-	            WSDLFactory factory = WSDLFactory.newInstance();
-	            WSDLReader reader = factory.newWSDLReader();
-	            definition = reader.readWSDL(null, endpoint.getDescription());
-            	endpoint.setDefinition(definition);
-			}
 		} else {
 			// Find endpoint description from the component context
-			Document description = componentContext.getEndpointDescriptor(se);
-			if (description != null) {
-				// Parse WSDL
-				WSDLFactory factory = WSDLFactory.newInstance();
-				WSDLReader reader = factory.newWSDLReader();
-				definition = reader.readWSDL(null, description);
-			}
+            String key = se.getServiceName() + se.getEndpointName();
+            synchronized (definitions) {
+                definition = (Definition) definitions.get(key);
+                if (definition == null) {
+                    WSDLFactory factory = WSDLFactory.newInstance();
+                    Document description = componentContext.getEndpointDescriptor(se);
+                    if (description != null) {
+                        // Parse WSDL
+                        WSDLReader reader = factory.newWSDLReader();
+                        try {
+                            definition = reader.readWSDL(null, description);
+                        } catch (WSDLException e) {
+                            logger.info("Could not read wsdl from endpoint descriptor: " + e.getMessage());
+                            if (logger.isDebugEnabled()) {
+                                logger.debug("Could not read wsdl from endpoint descriptor", e);
+                            }
+                        }
+                    }
+                    if (definition == null) {
+                        definition = factory.newDefinition();
+                    }
+                    definitions.put(key, definition);
+                }
+            }
 		}
 		
 		// Find operation within description