Hi Everybody,

I took a stab at adding better wsdl support for the EIP patterns
component.  Every endpoint can now be configured with a wsdlResource
which is a Spring Resource.  Also the wire tap and pipeline components
reuse the WSDL for the target service that they configured with.

Unfortunately, my servicemix tests have not been passing due to the
following error (I'm on a mac):
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.apache.servicemix.eip.StaticRoutingSlipTxTest
log4j:WARN No appenders could be found for logger
(org.apache.activemq.broker.BrokerService).
log4j:WARN Please initialize the log4j system properly.
[Fatal Error] :-1:-1: Invalid encoding name "MACROMAN".
[Fatal Error] :-1:-1: Invalid encoding name "MACROMAN".
[Fatal Error] :-1:-1: Invalid encoding name "MACROMAN".


So I don't want to commit this change unless someone tests it out for
me.  Could I have someone else double check it for me?  I'm pasting
the patch in bellow:

Index: 
servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/Pipeline.java
===================================================================
--- 
servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/Pipeline.java   
    (revision
411946)
+++ 
servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/Pipeline.java   
    (working
copy)
@@ -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;
@@ -334,5 +335,14 @@
            }
        }
    }
+
+    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;
+    }

}
Index: 
servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/WireTap.java
===================================================================
--- 
servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/WireTap.java    
    (revision
411946)
+++ 
servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/WireTap.java    
    (working
copy)
@@ -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);
        }
    }
-
+
}
Index: servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java
===================================================================
--- servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java     
(revision
411946)
+++ servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java     
(working
copy)
@@ -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;
+    }
+
}


--
Regards,
Hiram

Reply via email to