You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ch...@apache.org on 2006/06/07 02:51:20 UTC

svn commit: r412244 - in /incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip: EIPEndpoint.java patterns/Pipeline.java patterns/WireTap.java

Author: chirino
Date: Tue Jun  6 17:51:19 2006
New Revision: 412244

URL: http://svn.apache.org/viewvc?rev=412244&view=rev
Log:
Added support for WSDL descriptor on each endpoint.  If the WSDL is not explcitly configured, some of the components
will reuse the WSDL of the target service.


Modified:
    incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java
    incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/Pipeline.java
    incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/WireTap.java

Modified: incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java?rev=412244&r1=412243&r2=412244&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java Tue Jun  6 17:51:19 2006
@@ -15,6 +15,9 @@
  */
 package org.apache.servicemix.eip;
 
+import java.net.URL;
+
+import javax.jbi.JBIException;
 import javax.jbi.component.ComponentContext;
 import javax.jbi.management.DeploymentException;
 import javax.jbi.messaging.DeliveryChannel;
@@ -24,11 +27,16 @@
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.MessageExchange.Role;
 import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
 
 import org.apache.servicemix.JbiConstants;
 import org.apache.servicemix.common.BaseLifeCycle;
 import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.ExchangeProcessor;
+import org.apache.servicemix.eip.support.ExchangeTarget;
 import org.apache.servicemix.locks.LockManager;
 import org.apache.servicemix.locks.impl.SimpleLockManager;
 import org.apache.servicemix.store.Store;
@@ -36,6 +44,8 @@
 import org.apache.servicemix.store.memory.MemoryStoreFactory;
 import org.apache.servicemix.timers.TimerManager;
 import org.apache.servicemix.timers.impl.TimerManagerImpl;
+import org.springframework.core.io.Resource;
+import org.w3c.dom.Document;
 
 /**
  * @author gnodet
@@ -45,6 +55,7 @@
 
     private ServiceEndpoint activated;
     private DeliveryChannel channel;
+    private Resource wsdlResource;
     
     /**
      * The store to keep pending exchanges
@@ -68,6 +79,11 @@
     protected MessageExchangeFactory exchangeFactory;
     
     /**
+     * The ExchangeTarget to use to get the WSDL
+     */
+    protected ExchangeTarget wsdlExchangeTarget;
+    
+    /**
      * @return Returns the exchangeFactory.
      */
     public MessageExchangeFactory getExchangeFactory() {
@@ -223,8 +239,141 @@
         }
     }
     
+    /**
+     * @return Returns the description.
+     */
+    public Document getDescription() {
+        if( description == null ) {
+            definition = getDefinition();
+            if( definition!=null ) {
+                try {
+                    description = WSDLFactory.newInstance().newWSDLWriter().getDocument(definition);
+                } catch (WSDLException e) {
+                }
+            }
+        }
+        return description;
+    }
+    
+    /**
+     * If the definition is not currently set, it tries to set it using 
+     * the following sources in the order:
+     * description, wsdlResource, wsdlExchangeTarget
+     * 
+     * @return Returns the definition.
+     */
+    public Definition getDefinition() {
+        if( definition == null ) {
+            definition = getDefinitionFromDescription();
+            if( definition == null ) {
+                definition = getDefinitionFromWsdlResource();
+                if( definition == null ) {
+                    definition = getDefinitionFromWsdlExchangeTarget();
+                }
+            }
+        }
+        return definition;
+    }
+    
+    protected Definition getDefinitionFromDescription() {
+        if( description!=null ) {
+            try {
+                return WSDLFactory.newInstance().newWSDLReader().readWSDL(null, description);
+            } catch (WSDLException ignore) {
+            }
+        }
+        return null;
+    }
+
+    protected Definition getDefinitionFromWsdlResource() {
+        if( wsdlResource!=null ) {
+            try {
+                URL resource = wsdlResource.getURL();
+                WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
+                return reader.readWSDL(null, resource.toString());
+            } catch (Throwable ignore) {
+            }
+        }
+        return null;
+    }
+        
+    protected Definition getDefinitionFromWsdlExchangeTarget() {
+        if( wsdlExchangeTarget != null ) {
+            try {
+                Document description = getDescriptionForExchangeTarget(wsdlExchangeTarget);
+                return WSDLFactory.newInstance().newWSDLReader().readWSDL(null, description);
+            } catch (Throwable ignore) {
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * @return Returns the wsdl's Resource.
+     */
+    public Resource getWsdlResource() {
+        return wsdlResource;
+    }
+    public void setWsdlResource(Resource wsdlResource) {
+        this.wsdlResource = wsdlResource;
+    }
+    
+    protected Document getDescriptionForExchangeTarget(ExchangeTarget match) throws JBIException {
+        ServiceEndpoint[] endpoints = getEndpointsForExchangeTarget(match);
+        if (endpoints == null || endpoints.length == 0) {
+            return null;
+        }
+        ServiceEndpoint endpoint = chooseFirstEndpointWithDescriptor(endpoints);
+        if (endpoint == null) {
+            return null;
+        }
+        return getContext().getEndpointDescriptor(endpoint);
+    }
+    
+    /**
+     * 
+     * @param match
+     * @return an ServiceEndpoint[] of all the endpoints that matched.
+     * @throws JBIException
+     */
+    protected ServiceEndpoint[] getEndpointsForExchangeTarget(ExchangeTarget match) throws JBIException {
+        ServiceEndpoint[] endpoints;
+        if (match.getEndpoint() != null && match.getService() != null) {
+            ServiceEndpoint endpoint = getContext().getEndpoint(match.getService(), match.getEndpoint());
+            if (endpoint == null) {
+                endpoints = new ServiceEndpoint[0];
+            } else {
+                endpoints = new ServiceEndpoint[] { endpoint };
+            }
+        } else if (match.getService() != null) {
+            endpoints = getContext().getEndpointsForService(match.getService());
+        } else if (interfaceName != null) {
+            endpoints = getContext().getEndpoints(interfaceName);
+        } else {
+            throw new IllegalStateException("One of interfaceName or serviceName should be provided");
+        }
+        return endpoints;
+    }
+    
+    protected ServiceEndpoint chooseFirstEndpointWithDescriptor(ServiceEndpoint[] endpoints) throws JBIException {
+        for (int i = 0; i < endpoints.length; i++) {
+            if (getContext().getEndpointDescriptor(endpoints[i]) != null) {
+                return endpoints[i];
+            }
+        }
+        return null;
+    }
+
+
     protected abstract void processAsync(MessageExchange exchange) throws Exception;
 
     protected abstract void processSync(MessageExchange exchange) throws Exception;
-
+    
+    public ExchangeTarget getWsdlExchangeTarget() {
+        return wsdlExchangeTarget;
+    }
+    public void setWsdlExchangeTarget(ExchangeTarget wsdlExchangeTarget) {
+        this.wsdlExchangeTarget = wsdlExchangeTarget;
+    }
+    
 }

Modified: incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/Pipeline.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/Pipeline.java?rev=412244&r1=412243&r2=412244&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/Pipeline.java (original)
+++ incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/Pipeline.java Tue Jun  6 17:51:19 2006
@@ -24,6 +24,7 @@
 import javax.jbi.messaging.InOut;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.RobustInOnly;
+import javax.wsdl.Definition;
 
 import org.apache.servicemix.eip.EIPEndpoint;
 import org.apache.servicemix.eip.support.ExchangeTarget;
@@ -333,6 +334,15 @@
                 throw new IllegalStateException("Exchange from target has a " + ExchangeStatus.ACTIVE + " status but has no Fault message");
             }
         }
+    }
+    
+    protected Definition getDefinitionFromWsdlExchangeTarget() {
+        Definition rc = super.getDefinitionFromWsdlExchangeTarget();
+        if( rc !=null ) {
+            // TODO: This components wsdl is == transformer wsdl without the out message.
+            // need to massage the result wsdl so that it described an in only exchange
+        }
+        return rc;
     }
 
 }

Modified: incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/WireTap.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/WireTap.java?rev=412244&r1=412243&r2=412244&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/WireTap.java (original)
+++ incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/WireTap.java Tue Jun  6 17:51:19 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.servicemix.eip.patterns;
 
+import javax.jbi.JBIException;
 import javax.jbi.management.DeploymentException;
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOnly;
@@ -26,6 +27,7 @@
 import org.apache.servicemix.eip.support.ExchangeTarget;
 import org.apache.servicemix.eip.support.MessageUtil;
 import org.apache.servicemix.store.Store;
+import org.w3c.dom.Document;
 
 /**
  *
@@ -77,6 +79,7 @@
      */
     public void setTarget(ExchangeTarget target) {
         this.target = target;
+        this.wsdlExchangeTarget = target;
     }
 
     /**
@@ -254,5 +257,5 @@
             sendSync(dest);
         }
     }
-
+    
 }