servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r389216 - 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-jms/src/test/ja...
Date Mon, 27 Mar 2006 18:15:07 GMT
Author: gnodet
Date: Mon Mar 27 10:15:05 2006
New Revision: 389216

URL: http://svn.apache.org/viewcvs?rev=389216&view=rev
Log:
SM-369: add a way to alias proxied services

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/HttpXBeanDeployerTest.java
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java
    incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsXBeanDeployerTest.java
    incubator/servicemix/trunk/servicemix-jms/src/test/resources/xbean/xbean.xml
    incubator/servicemix/trunk/servicemix-soap/project.xml
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.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=389216&r1=389215&r2=389216&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
Mon Mar 27 10:15:05 2006
@@ -15,12 +15,8 @@
  */
 package org.apache.servicemix.http;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
+import java.util.Iterator;
 
-import javax.jbi.component.ComponentContext;
-import javax.jbi.messaging.MessageExchange.Role;
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
@@ -28,20 +24,11 @@
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.extensions.http.HTTPAddress;
 import javax.wsdl.extensions.soap.SOAPAddress;
-import javax.wsdl.factory.WSDLFactory;
-import javax.wsdl.xml.WSDLReader;
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.servicemix.common.ExchangeProcessor;
-import org.apache.servicemix.common.wsdl1.JbiExtension;
-import org.apache.servicemix.common.xbean.XBeanServiceUnit;
 import org.apache.servicemix.http.processors.ConsumerProcessor;
 import org.apache.servicemix.http.processors.ProviderProcessor;
 import org.apache.servicemix.soap.SoapEndpoint;
-import org.springframework.core.io.Resource;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
 
 import com.ibm.wsdl.extensions.http.HTTPAddressImpl;
 import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;
@@ -57,57 +44,8 @@
 public class HttpEndpoint extends SoapEndpoint {
 
     protected ExtensibilityElement binding;
-    protected ExchangeProcessor processor;
-    protected ServiceEndpoint activated;
-    protected Role role;
-    protected URI defaultMep;
     protected String locationURI;
-    protected boolean soap;
-    protected String soapVersion;
-    protected Resource wsdlResource;
-    protected QName defaultOperation;
     
-    /* (non-Javadoc)
-     * @see org.apache.servicemix.common.Endpoint#getProcessor()
-     */
-    public ExchangeProcessor getProcessor() {
-        return this.processor;
-    }
-
-    /* (non-Javadoc)
-     * @see org.servicemix.common.Endpoint#activate()
-     */
-    public void activate() throws Exception {
-        ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
-        loadWsdl();
-        if (getRole() == Role.PROVIDER) {
-            activated = ctx.activateEndpoint(service, endpoint);
-            processor = new ProviderProcessor(this);
-        } else {
-            activated = new HttpExternalEndpoint(this);
-            ctx.registerExternalEndpoint(activated);
-            processor = new ConsumerProcessor(this);
-        }
-        processor.start();
-    }
-
-    /* (non-Javadoc)
-     * @see org.servicemix.common.Endpoint#deactivate()
-     */
-    public void deactivate() throws Exception {
-        ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
-        if (getRole() == Role.PROVIDER) {
-            ServiceEndpoint ep = activated;
-            activated = null;
-            ctx.deactivateEndpoint(ep);
-        } else {
-            ServiceEndpoint ep = activated;
-            activated = null;
-            ctx.deregisterExternalEndpoint(ep);
-        }
-        processor.stop();
-    }
-
     public ExtensibilityElement getBinding() {
         return binding;
     }
@@ -116,38 +54,6 @@
         this.binding = binding;
     }
 
-    public Role getRole() {
-        return role;
-    }
-
-    public void setRole(Role role) {
-        this.role = role;
-    }
-    
-    /**
-     * @org.apache.xbean.Property alias="role"
-     * @param role
-     */
-    public void setRoleAsString(String role) {
-        if (role == null) {
-            throw new IllegalArgumentException("Role must be specified");
-        } else if (JbiExtension.ROLE_CONSUMER.equals(role)) {
-            setRole(Role.CONSUMER);
-        } else if (JbiExtension.ROLE_PROVIDER.equals(role)) {
-            setRole(Role.PROVIDER);
-        } else {
-            throw new IllegalArgumentException("Unrecognized role: " + role);
-        }
-    }
-
-    public void setDefaultMep(URI defaultMep) {
-        this.defaultMep = defaultMep;
-    }
-
-    public URI getDefaultMep() {
-        return defaultMep;
-    }
-
     public String getLocationURI() {
         return locationURI;
     }
@@ -156,148 +62,60 @@
         this.locationURI = locationUri;
     }
 
-    public boolean isSoap() {
-        return soap;
-    }
-
-    public void setSoap(boolean soap) {
-        this.soap = soap;
-    }
-
-    public String getSoapVersion() {
-        return soapVersion;
-    }
-
-    public void setSoapVersion(String soapVersion) {
-        this.soapVersion = soapVersion;
-    }
-    
     /**
-     * Load the wsdl for this endpoint.
+     * @org.apache.xbean.Property alias="role"
+     * @param role
      */
-    protected void loadWsdl() {
-        // Load WSDL from the resource
-        if (description == null && wsdlResource != null) {
-            InputStream is = null;
-            ClassLoader cl = Thread.currentThread().getContextClassLoader();
-            try {
-                if (serviceUnit instanceof XBeanServiceUnit) {
-                    XBeanServiceUnit su = (XBeanServiceUnit) serviceUnit;
-                    Thread.currentThread().setContextClassLoader(su.getKernel().getClassLoaderFor(su.getConfiguration()));
-                }
-                is = wsdlResource.getInputStream();
-                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-                dbf.setNamespaceAware(true);
-                Definition def = WSDLFactory.newInstance().newWSDLReader().readWSDL(null,
new InputSource(is));
-                overrideDefinition(def);
-            } catch (Exception e) {
-                logger.warn("Could not load description from resource", e);
-            } finally {
-                Thread.currentThread().setContextClassLoader(cl);
-                if (is != null) {
-                    try {
-                        is.close();
-                    } catch (IOException e) {
-                        // Ignore
-                    }
-                }
-            }
-        }
-        // If the endpoint is a consumer, try to find
-        // the proxied endpoint description
-        if (description == null && definition == null && getRole() == Role.CONSUMER)
{
-            retrieveProxiedEndpointDefinition();
-        }
-        // If the wsdl definition is provided,
-        // convert it to a DOM document
-        if (description == null && definition != null) {
-            try {
-                description = WSDLFactory.newInstance().newWSDLWriter().getDocument(definition);
-            } catch (Exception e) {
-                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);
-            }
-        }
+    public void setRoleAsString(String role) {
+        super.setRoleAsString(role);
     }
 
-    /**
-     * Create a wsdl definition for a consumer endpoint.
-     * Loads the target endpoint definition and add http binding
-     * informations to it.
-     */
-    protected void retrieveProxiedEndpointDefinition() {
-        try {
-            if (service != null && endpoint != null) {
-                ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
-                ServiceEndpoint se = ctx.getEndpoint(service, endpoint);
-                if (se != null) {
-                    Document doc = ctx.getEndpointDescriptor(se);
-                    if (doc != null) {
-                        WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
-                        Definition def = reader.readWSDL(null, doc);
-                        if (def != null) {
-                            overrideDefinition(def);
-                        }
-                    }
-                }
+    protected void overrideDefinition(Definition def) {
+        Service svc = null;
+        Port port = null;
+        if (targetService != null && targetEndpoint != null) {
+            svc = def.getService(targetService);
+            port = (svc != null) ? svc.getPort(targetEndpoint) : null;
+        } else if (targetInterfaceName != null) {
+            Iterator it = def.getServices().values().iterator();
+            svc = it .hasNext() ? (Service) it.next() : null;
+            if (svc != null) {
+                it = svc.getPorts().values().iterator();
+                port = (it.hasNext()) ? (Port) it.next() : null;
             }
-        } catch (Exception e) {
-            logger.debug("Unable to retrieve target endpoint descriptor", e);
+        } else {
+            svc = def.getService(service);
+            port = (svc != null) ? svc.getPort(endpoint) : null;
         }
-    }
-    
-    protected void overrideDefinition(Definition def) {
-        Service svc = def.getService(service);
-        if (svc != null) {
-            Port port = svc.getPort(endpoint);
-            if (port != null) {
-                port.getExtensibilityElements().clear();
-                if (isSoap()) {
-                    SOAPAddress address = new SOAPAddressImpl();
-                    address.setLocationURI(getLocationURI());
-                    port.addExtensibilityElement(address);
-                    def.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
-                } else {
-                    HTTPAddress address = new HTTPAddressImpl();
-                    address.setLocationURI(getLocationURI());
-                    port.addExtensibilityElement(address);
-                    def.addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/");
-                }
-                svc.getPorts().clear();
-                svc.addPort(port);
-                definition = def;
+        if (port != null) {
+            port.getExtensibilityElements().clear();
+            if (isSoap()) {
+                SOAPAddress address = new SOAPAddressImpl();
+                address.setLocationURI(getLocationURI());
+                port.addExtensibilityElement(address);
+                def.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
+            } else {
+                HTTPAddress address = new HTTPAddressImpl();
+                address.setLocationURI(getLocationURI());
+                port.addExtensibilityElement(address);
+                def.addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/");
             }
+            svc.getPorts().clear();
+            svc.addPort(port);
+            definition = def;
         }
     }
 
-    public Resource getWsdlResource() {
-        return wsdlResource;
+    protected ExchangeProcessor createProviderProcessor() {
+        return new ProviderProcessor(this);
     }
 
-    public void setWsdlResource(Resource wsdlResource) {
-        this.wsdlResource = wsdlResource;
+    protected ExchangeProcessor createConsumerProcessor() {
+        return new ConsumerProcessor(this);
     }
 
-    /**
-     * @return Returns the defaultOperation.
-     */
-    public QName getDefaultOperation() {
-        return defaultOperation;
-    }
-
-    /**
-     * @param defaultOperation The defaultOperation to set.
-     */
-    public void setDefaultOperation(QName defaultOperation) {
-        this.defaultOperation = defaultOperation;
+    protected ServiceEndpoint createExternalEndpoint() {
+        return new HttpExternalEndpoint(this);
     }
 
 }

Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpXBeanDeployerTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpXBeanDeployerTest.java?rev=389216&r1=389215&r2=389216&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpXBeanDeployerTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpXBeanDeployerTest.java
Mon Mar 27 10:15:05 2006
@@ -122,7 +122,7 @@
                 container.getRegistry().getExternalEndpointsForService(
                         new QName("http://test", "MySoapService"))[0]));
         
-        // Test
+        // Test 
         DefaultServiceMixClient client = new DefaultServiceMixClient(container);
         InOut me = client.createInOutExchange();
         me.setService(new QName("http://test", "MyProviderService"));

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=389216&r1=389215&r2=389216&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
Mon Mar 27 10:15:05 2006
@@ -15,29 +15,16 @@
  */
 package org.apache.servicemix.jms;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
+import java.util.Iterator;
 
-import javax.jbi.component.ComponentContext;
-import javax.jbi.messaging.MessageExchange.Role;
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
 import javax.wsdl.Service;
-import javax.wsdl.factory.WSDLFactory;
-import javax.wsdl.xml.WSDLReader;
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.servicemix.common.ExchangeProcessor;
-import org.apache.servicemix.common.wsdl1.JbiExtension;
-import org.apache.servicemix.common.xbean.XBeanServiceUnit;
 import org.apache.servicemix.jms.wsdl.JmsBinding;
 import org.apache.servicemix.soap.SoapEndpoint;
-import org.springframework.core.io.Resource;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
 
 /**
  * 
@@ -49,17 +36,7 @@
  */
 public class JmsEndpoint extends SoapEndpoint {
     
-    protected QName targetServiceName;
-    protected String targetEndpointName;
     protected JmsBinding binding;
-    protected ExchangeProcessor processor;
-    protected ServiceEndpoint activated;
-    protected Role role;
-    protected URI defaultMep;
-    protected boolean soap;
-    protected String soapVersion;
-    protected Resource wsdlResource;
-    protected QName defaultOperation;
     // Jms informations
     protected String initialContextFactory;
     protected String jndiProviderURL;
@@ -83,246 +60,6 @@
     public void setBinding(JmsBinding binding) {
         this.binding = binding;
     }
-    /**
-     * @return Returns the soap.
-     */
-    public boolean isSoap() {
-        return soap;
-    }
-    /**
-     * @param soap The soap to set.
-     */
-    public void setSoap(boolean soap) {
-        this.soap = soap;
-    }
-    
-    public String toString() {
-        return "JMSEndpoint[service: " + service + ", " + 
-                "endpoint: " + endpoint + ", " + 
-                "address: " + jndiDestinationName + "(" + destinationStyle + "), " + 
-                "soap: " + soap + "]";
-    }
-
-    public ExchangeProcessor getProcessor() {
-        return this.processor;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.servicemix.common.Endpoint#activate()
-     */
-    public void activate() throws Exception {
-        ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
-        loadWsdl();
-        if (getRole() == Role.PROVIDER) {
-            activated = ctx.activateEndpoint(service, endpoint);
-            processor = new MultiplexingProviderProcessor(this);
-        } else {
-            activated = new JmsExternalEndpoint(this);
-            ctx.registerExternalEndpoint(activated);
-            processor = new MultiplexingConsumerProcessor(this);
-        }
-        processor.start();
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.servicemix.common.Endpoint#deactivate()
-     */
-    public void deactivate() throws Exception {
-        ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
-        if (getRole() == Role.PROVIDER) {
-            ServiceEndpoint ep = activated;
-            activated = null;
-            ctx.deactivateEndpoint(ep);
-        } else {
-            ServiceEndpoint ep = activated;
-            activated = null;
-            ctx.deregisterExternalEndpoint(ep);
-        }
-        processor.stop();
-    }
-
-    public Role getRole() {
-        return this.role;
-    }
-
-    public void setRole(Role role) {
-        this.role = role;
-    }
-
-    /**
-     * @org.apache.xbean.Property alias="role"
-     * @param role
-     */
-    public void setRoleAsString(String role) {
-        if (role == null) {
-            throw new IllegalArgumentException("Role must be specified");
-        } else if (JbiExtension.ROLE_CONSUMER.equals(role)) {
-            setRole(Role.CONSUMER);
-        } else if (JbiExtension.ROLE_PROVIDER.equals(role)) {
-            setRole(Role.PROVIDER);
-        } else {
-            throw new IllegalArgumentException("Unrecognized role: " + role);
-        }
-    }
-
-    public void setDefaultMep(URI defaultMep) {
-        this.defaultMep = defaultMep;
-    }
-
-    public URI getDefaultMep() {
-        return defaultMep;
-    }
-
-    /**
-     * @return Returns the defaultOperation.
-     */
-    public QName getDefaultOperation() {
-        return defaultOperation;
-    }
-
-    /**
-     * @param defaultOperation The defaultOperation to set.
-     */
-    public void setDefaultOperation(QName defaultOperation) {
-        this.defaultOperation = defaultOperation;
-    }
-
-    /**
-     * @return Returns the soapVersion.
-     */
-    public String getSoapVersion() {
-        return soapVersion;
-    }
-
-    /**
-     * @param soapVersion The soapVersion to set.
-     */
-    public void setSoapVersion(String soapVersion) {
-        this.soapVersion = soapVersion;
-    }
-
-    /**
-     * Load the wsdl for this endpoint.
-     */
-    protected void loadWsdl() {
-        // Load WSDL from the resource
-        if (description == null && wsdlResource != null) {
-            InputStream is = null;
-            ClassLoader cl = Thread.currentThread().getContextClassLoader();
-            try {
-                if (serviceUnit instanceof XBeanServiceUnit) {
-                    XBeanServiceUnit su = (XBeanServiceUnit) serviceUnit;
-                    Thread.currentThread().setContextClassLoader(su.getKernel().getClassLoaderFor(su.getConfiguration()));
-                }
-                is = wsdlResource.getInputStream();
-                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-                dbf.setNamespaceAware(true);
-                Definition def = WSDLFactory.newInstance().newWSDLReader().readWSDL(null,
new InputSource(is));
-                overrideDefinition(def);
-            } catch (Exception e) {
-                logger.warn("Could not load description from resource", e);
-            } finally {
-                Thread.currentThread().setContextClassLoader(cl);
-                if (is != null) {
-                    try {
-                        is.close();
-                    } catch (IOException e) {
-                        // Ignore
-                    }
-                }
-            }
-        }
-        // If the endpoint is a consumer, try to find
-        // the proxied endpoint description
-        if (description == null && definition == null && getRole() == Role.CONSUMER)
{
-            retrieveProxiedEndpointDefinition();
-        }
-        // If the wsdl definition is provided,
-        // convert it to a DOM document
-        if (description == null && definition != null) {
-            try {
-                description = WSDLFactory.newInstance().newWSDLWriter().getDocument(definition);
-            } catch (Exception e) {
-                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);
-            }
-        }
-    }
-
-    /**
-     * Create a wsdl definition for a consumer endpoint.
-     * Loads the target endpoint definition and add http binding
-     * informations to it.
-     */
-    protected void retrieveProxiedEndpointDefinition() {
-        try {
-            if (service != null && endpoint != null) {
-                ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
-                ServiceEndpoint se = ctx.getEndpoint(service, endpoint);
-                if (se != null) {
-                    Document doc = ctx.getEndpointDescriptor(se);
-                    if (doc != null) {
-                        WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
-                        Definition def = reader.readWSDL(null, doc);
-                        if (def != null) {
-                            overrideDefinition(def);
-                        }
-                    }
-                }
-            }
-        } catch (Exception e) {
-            logger.debug("Unable to retrieve target endpoint descriptor", e);
-        }
-    }
-    
-    protected void overrideDefinition(Definition def) {
-        Service svc = def.getService(service);
-        if (svc != null) {
-            Port port = svc.getPort(endpoint);
-            if (port != null) {
-                port.getExtensibilityElements().clear();
-                /*
-                if (isSoap()) {
-                    SOAPAddress address = new SOAPAddressImpl();
-                    address.setLocationURI(getLocationURI());
-                    port.addExtensibilityElement(address);
-                    def.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
-                } else {
-                    HTTPAddress address = new HTTPAddressImpl();
-                    address.setLocationURI(getLocationURI());
-                    port.addExtensibilityElement(address);
-                    def.addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/");
-                }
-                */
-                // TODO: add binding information
-                svc.getPorts().clear();
-                svc.addPort(port);
-                definition = def;
-            }
-        }
-    }
-
-    /**
-     * @return Returns the wsdlResource.
-     */
-    public Resource getWsdlResource() {
-        return wsdlResource;
-    }
-
-    /**
-     * @param wsdlResource The wsdlResource to set.
-     */
-    public void setWsdlResource(Resource wsdlResource) {
-        this.wsdlResource = wsdlResource;
-    }
 
     /**
      * @return Returns the initialContextFactory.
@@ -409,31 +146,68 @@
     }
 
     /**
-     * @return Returns the localEndpointName.
+     * @org.apache.xbean.Property alias="role"
+     * @param role
      */
-    public String getTargetEndpointName() {
-        return targetEndpointName;
+    public void setRoleAsString(String role) {
+        super.setRoleAsString(role);
     }
 
-    /**
-     * @param localEndpointName The localEndpointName to set.
-     */
-    public void setTargetEndpointName(String localEndpointName) {
-        this.targetEndpointName = localEndpointName;
+    protected ExchangeProcessor createProviderProcessor() {
+        return new MultiplexingProviderProcessor(this);
     }
 
-    /**
-     * @return Returns the localServiceName.
-     */
-    public QName getTargetServiceName() {
-        return targetServiceName;
+    protected ExchangeProcessor createConsumerProcessor() {
+        return new MultiplexingConsumerProcessor(this);
     }
 
-    /**
-     * @param localServiceName The localServiceName to set.
-     */
-    public void setTargetServiceName(QName localServiceName) {
-        this.targetServiceName = localServiceName;
+    protected ServiceEndpoint createExternalEndpoint() {
+        return new JmsExternalEndpoint(this);
     }
 
+    protected void overrideDefinition(Definition def) {
+        Service svc = null;
+        Port port = null;
+        if (targetService != null && targetEndpoint != null) {
+            svc = def.getService(targetService);
+            port = (svc != null) ? svc.getPort(targetEndpoint) : null;
+        } else if (targetInterfaceName != null) {
+            Iterator it = def.getServices().values().iterator();
+            svc = it .hasNext() ? (Service) it.next() : null;
+            if (svc != null) {
+                it = svc.getPorts().values().iterator();
+                port = (it.hasNext()) ? (Port) it.next() : null;
+            }
+        } else {
+            svc = def.getService(service);
+            port = (svc != null) ? svc.getPort(endpoint) : null;
+        }
+        if (port != null) {
+            port.getExtensibilityElements().clear();
+            /*
+            if (isSoap()) {
+                SOAPAddress address = new SOAPAddressImpl();
+                address.setLocationURI(getLocationURI());
+                port.addExtensibilityElement(address);
+                def.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
+            } else {
+                HTTPAddress address = new HTTPAddressImpl();
+                address.setLocationURI(getLocationURI());
+                port.addExtensibilityElement(address);
+                def.addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/");
+            }
+            */
+            // TODO: add binding information
+            svc.getPorts().clear();
+            svc.addPort(port);
+            definition = def;
+        }
+    }
+
+    public String toString() {
+        return "JMSEndpoint[service: " + service + ", " + 
+                "endpoint: " + endpoint + ", " + 
+                "address: " + jndiDestinationName + "(" + destinationStyle + "), " + 
+                "soap: " + soap + "]";
+    }
 }

Modified: incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsXBeanDeployerTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsXBeanDeployerTest.java?rev=389216&r1=389215&r2=389216&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsXBeanDeployerTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsXBeanDeployerTest.java
Mon Mar 27 10:15:05 2006
@@ -98,6 +98,7 @@
                     type.setUndefined(false);
                     type.setQName(new QName("http://test", "MyConsumerInterface"));
                     Binding binding = def.createBinding();
+                    binding.setQName(new QName("http://test", "MyConsumerBinding"));
                     binding.setUndefined(false);
                     binding.setPortType(type);
                     Service svc = def.createService();
@@ -176,7 +177,7 @@
                     binding.setUndefined(false);
                     binding.setPortType(type);
                     Service svc = def.createService();
-                    svc.setQName(new QName("http://test", "MySoapConsumerService"));
+                    svc.setQName(new QName("http://test", "MyConsumerService"));
                     Port port = def.createPort();
                     port.setBinding(binding);
                     port.setName("myConsumer");
@@ -194,7 +195,7 @@
             }
         });
         asEcho.setEndpoint("myConsumer");
-        asEcho.setService(new QName("http://test", "MySoapConsumerService"));
+        asEcho.setService(new QName("http://test", "MyConsumerService"));
         container.activateComponent(asEcho);
         
         // Start container
@@ -210,12 +211,12 @@
         // Test wsdls
         assertNotNull(container.getRegistry().getEndpointDescriptor(
                 container.getRegistry().getExternalEndpointsForService(
-                        new QName("http://test", "MySoapConsumerService"))[0]));
+                        new QName("http://test", "MyConsumerService"))[0]));
         
         // Test
         DefaultServiceMixClient client = new DefaultServiceMixClient(container);
         InOut me = client.createInOutExchange();
-        me.setService(new QName("http://test", "MySoapProviderService"));
+        me.setService(new QName("http://test", "MyProviderService"));
         me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
         client.sendSync(me);
         if (me.getStatus() == ExchangeStatus.ERROR) {

Modified: incubator/servicemix/trunk/servicemix-jms/src/test/resources/xbean/xbean.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-jms/src/test/resources/xbean/xbean.xml?rev=389216&r1=389215&r2=389216&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/test/resources/xbean/xbean.xml (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/test/resources/xbean/xbean.xml Mon Mar 27
10:15:05 2006
@@ -10,7 +10,9 @@
 
     <!-- START SNIPPET: consumer -->
     <jms:endpoint service="test:MyConsumerService"
-                  endpoint="myConsumer"
+                  endpoint="jms"
+                  targetService="test:MyConsumerService"
+                  targetEndpoint="myConsumer"
                   role="consumer" 
                   destinationStyle="queue"
                   jmsProviderDestinationName="queue/A"
@@ -19,8 +21,9 @@
                   defaultOperation="test:Echo" />
     <!-- END SNIPPET: consumer -->
 
-    <jms:endpoint service="test:MySoapConsumerService"
-                  endpoint="myConsumer"
+    <jms:endpoint service="test:MyConsumerService"
+                  endpoint="jms+soap"
+                  targetInterfaceName="test:MyConsumerInterface"
                   role="consumer"
                   destinationStyle="queue"
                   jmsProviderDestinationName="queue/A/Soap"

Modified: incubator/servicemix/trunk/servicemix-soap/project.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/project.xml?rev=389216&r1=389215&r2=389216&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/project.xml (original)
+++ incubator/servicemix/trunk/servicemix-soap/project.xml Mon Mar 27 10:15:05 2006
@@ -65,6 +65,26 @@
           <eclipse.dependency>true</eclipse.dependency>
         </properties>
       </dependency>
+      <dependency>
+        <groupId>org.apache.xbean</groupId>
+        <artifactId>xbean-spring</artifactId>
+        <version>${xbean_version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.xbean</groupId>
+        <artifactId>xbean-server</artifactId>
+        <version>${xbean_version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.xbean</groupId>
+        <artifactId>xbean-kernel</artifactId>
+        <version>${xbean_version}</version>
+      </dependency>
+      <dependency>
+        <groupId>springframework</groupId>
+        <artifactId>spring</artifactId>
+        <version>${spring_version}</version>
+      </dependency>
       
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java?rev=389216&r1=389215&r2=389216&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
Mon Mar 27 10:15:05 2006
@@ -15,16 +15,310 @@
  */
 package org.apache.servicemix.soap;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.MessageExchange.Role;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.wsdl.Definition;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.common.ExchangeProcessor;
+import org.apache.servicemix.common.wsdl1.JbiExtension;
+import org.apache.servicemix.common.xbean.XBeanServiceUnit;
+import org.springframework.core.io.Resource;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
 
 public abstract class SoapEndpoint extends Endpoint {
 
-	public abstract URI getDefaultMep();
+    protected ServiceEndpoint activated;
+    protected ExchangeProcessor processor;
+    protected Role role;
+    protected URI defaultMep;
+    protected boolean soap;
+    protected String soapVersion;
+    protected Resource wsdlResource;
+    protected QName defaultOperation;
+    protected QName targetInterfaceName;
+    protected QName targetService;
+    protected String targetEndpoint;
+    
+    /**
+     * @return Returns the defaultMep.
+     */
+    public URI getDefaultMep() {
+        return defaultMep;
+    }
+    /**
+     * @param defaultMep The defaultMep to set.
+     */
+    public void setDefaultMep(URI defaultMep) {
+        this.defaultMep = defaultMep;
+    }
+    /**
+     * @return Returns the defaultOperation.
+     */
+    public QName getDefaultOperation() {
+        return defaultOperation;
+    }
+    /**
+     * @param defaultOperation The defaultOperation to set.
+     */
+    public void setDefaultOperation(QName defaultOperation) {
+        this.defaultOperation = defaultOperation;
+    }
+    /**
+     * @return Returns the role.
+     */
+    public Role getRole() {
+        return role;
+    }
+    /**
+     * @param role The role to set.
+     */
+    public void setRole(Role role) {
+        this.role = role;
+    }
+    /**
+     * @return Returns the soap.
+     */
+    public boolean isSoap() {
+        return soap;
+    }
+    /**
+     * @param soap The soap to set.
+     */
+    public void setSoap(boolean soap) {
+        this.soap = soap;
+    }
+    /**
+     * @return Returns the soapVersion.
+     */
+    public String getSoapVersion() {
+        return soapVersion;
+    }
+    /**
+     * @param soapVersion The soapVersion to set.
+     */
+    public void setSoapVersion(String soapVersion) {
+        this.soapVersion = soapVersion;
+    }
+    /**
+     * @return Returns the targetEndpoint.
+     */
+    public String getTargetEndpoint() {
+        return targetEndpoint;
+    }
+    /**
+     * @param targetEndpoint The targetEndpoint to set.
+     */
+    public void setTargetEndpoint(String targetEndpoint) {
+        this.targetEndpoint = targetEndpoint;
+    }
+    /**
+     * @return Returns the targetInterfaceName.
+     */
+    public QName getTargetInterfaceName() {
+        return targetInterfaceName;
+    }
+    /**
+     * @param targetInterfaceName The targetInterfaceName to set.
+     */
+    public void setTargetInterfaceName(QName targetInterfaceName) {
+        this.targetInterfaceName = targetInterfaceName;
+    }
+    /**
+     * @return Returns the targetServiceName.
+     */
+    public QName getTargetService() {
+        return targetService;
+    }
+    /**
+     * @param targetServiceName The targetServiceName to set.
+     */
+    public void setTargetService(QName targetServiceName) {
+        this.targetService = targetServiceName;
+    }
+    /**
+     * @return Returns the wsdlResource.
+     */
+    public Resource getWsdlResource() {
+        return wsdlResource;
+    }
+    /**
+     * @param wsdlResource The wsdlResource to set.
+     */
+    public void setWsdlResource(Resource wsdlResource) {
+        this.wsdlResource = wsdlResource;
+    }
+    /**
+     * @org.apache.xbean.Property alias="role"
+     * @param role
+     */
+    public void setRoleAsString(String role) {
+        if (role == null) {
+            throw new IllegalArgumentException("Role must be specified");
+        } else if (JbiExtension.ROLE_CONSUMER.equals(role)) {
+            setRole(Role.CONSUMER);
+        } else if (JbiExtension.ROLE_PROVIDER.equals(role)) {
+            setRole(Role.PROVIDER);
+        } else {
+            throw new IllegalArgumentException("Unrecognized role: " + role);
+        }
+    }
+
+    /**
+     * Load the wsdl for this endpoint.
+     */
+    protected void loadWsdl() {
+        // Load WSDL from the resource
+        if (description == null && wsdlResource != null) {
+            InputStream is = null;
+            ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            try {
+                if (serviceUnit instanceof XBeanServiceUnit) {
+                    XBeanServiceUnit su = (XBeanServiceUnit) serviceUnit;
+                    Thread.currentThread().setContextClassLoader(su.getKernel().getClassLoaderFor(su.getConfiguration()));
+                }
+                is = wsdlResource.getInputStream();
+                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+                dbf.setNamespaceAware(true);
+                Definition def = WSDLFactory.newInstance().newWSDLReader().readWSDL(null,
new InputSource(is));
+                overrideDefinition(def);
+            } catch (Exception e) {
+                logger.warn("Could not load description from resource", e);
+            } finally {
+                Thread.currentThread().setContextClassLoader(cl);
+                if (is != null) {
+                    try {
+                        is.close();
+                    } catch (IOException e) {
+                        // Ignore
+                    }
+                }
+            }
+        }
+        // If the endpoint is a consumer, try to find
+        // the proxied endpoint description
+        if (description == null && definition == null && getRole() == Role.CONSUMER)
{
+            retrieveProxiedEndpointDefinition();
+        }
+        // If the wsdl definition is provided,
+        // convert it to a DOM document
+        if (description == null && definition != null) {
+            try {
+                description = WSDLFactory.newInstance().newWSDLWriter().getDocument(definition);
+            } catch (Exception e) {
+                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);
+            }
+        }
+    }
+
+    /**
+     * Create a wsdl definition for a consumer endpoint.
+     * Loads the target endpoint definition and add http binding
+     * informations to it.
+     */
+    protected void retrieveProxiedEndpointDefinition() {
+        try {
+            ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
+            ServiceEndpoint ep = null;
+            if (targetService != null && targetEndpoint != null) {
+                ep = ctx.getEndpoint(targetService, targetEndpoint);
+            }
+            if (ep == null && targetService != null) {
+                ServiceEndpoint[] eps = ctx.getEndpointsForService(targetService);
+                if (eps != null && eps.length > 0) {
+                    ep = eps[0];
+                }
+            }
+            if (ep == null && targetInterfaceName != null) {
+                ServiceEndpoint[] eps = ctx.getEndpoints(targetInterfaceName);
+                if (eps != null && eps.length > 0) {
+                    ep = eps[0];
+                }
+            }
+            if (ep == null && service != null && endpoint != null) {
+                ep = ctx.getEndpoint(service, endpoint);
+            }
+            if (ep != null) {
+                Document doc = ctx.getEndpointDescriptor(ep);
+                if (doc != null) {
+                    WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
+                    Definition def = reader.readWSDL(null, doc);
+                    if (def != null) {
+                        overrideDefinition(def);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            logger.debug("Unable to retrieve target endpoint descriptor", e);
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.common.Endpoint#getProcessor()
+     */
+    public ExchangeProcessor getProcessor() {
+        return this.processor;
+    }
+
+    /* (non-Javadoc)
+     * @see org.servicemix.common.Endpoint#activate()
+     */
+    public void activate() throws Exception {
+        ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
+        loadWsdl();
+        if (getRole() == Role.PROVIDER) {
+            activated = ctx.activateEndpoint(service, endpoint);
+            processor = createProviderProcessor();
+        } else {
+            activated = createExternalEndpoint();
+            ctx.registerExternalEndpoint(activated);
+            processor = createConsumerProcessor();
+        }
+        processor.start();
+    }
+
+    /* (non-Javadoc)
+     * @see org.servicemix.common.Endpoint#deactivate()
+     */
+    public void deactivate() throws Exception {
+        ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
+        if (getRole() == Role.PROVIDER) {
+            ServiceEndpoint ep = activated;
+            activated = null;
+            ctx.deactivateEndpoint(ep);
+        } else {
+            ServiceEndpoint ep = activated;
+            activated = null;
+            ctx.deregisterExternalEndpoint(ep);
+        }
+        processor.stop();
+    }
+
+    protected abstract void overrideDefinition(Definition def);
+    
+    protected abstract ExchangeProcessor createProviderProcessor();
+    
+    protected abstract ExchangeProcessor createConsumerProcessor();
+    
+    protected abstract ServiceEndpoint createExternalEndpoint();
     
-    public abstract QName getDefaultOperation();
-	
 }

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=389216&r1=389215&r2=389216&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
Mon Mar 27 10:15:05 2006
@@ -82,9 +82,20 @@
         } else {
             context.setProperty(Context.OPERATION, message.getBodyName());
         }
-		context.setProperty(Context.INTERFACE, endpoint.getInterfaceName());
-		context.setProperty(Context.SERVICE, endpoint.getService());
-		context.setProperty(Context.ENDPOINT, endpoint.getEndpoint());
+        // If no target endpoint / service / interface is defined
+        // we assume we use the same informations has defined on the
+        // external endpoint
+        if (endpoint.getTargetInterfaceName() == null && 
+            endpoint.getTargetService() == null &&
+            endpoint.getTargetEndpoint() == null) {
+    		context.setProperty(Context.INTERFACE, endpoint.getInterfaceName());
+    		context.setProperty(Context.SERVICE, endpoint.getService());
+    		context.setProperty(Context.ENDPOINT, endpoint.getEndpoint());
+        } else {
+            context.setProperty(Context.INTERFACE, endpoint.getTargetInterfaceName());
+            context.setProperty(Context.SERVICE, endpoint.getTargetService());
+            context.setProperty(Context.ENDPOINT, endpoint.getTargetEndpoint());
+        }
 		return context;
 	}
 	



Mime
View raw message