servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r399873 - in /incubator/servicemix/trunk: servicemix-common/src/main/java/org/apache/servicemix/common/ servicemix-core/src/main/java/org/apache/servicemix/jbi/container/ servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ se...
Date Thu, 04 May 2006 22:43:22 GMT
Author: gnodet
Date: Thu May  4 15:43:16 2006
New Revision: 399873

URL: http://svn.apache.org/viewcvs?rev=399873&view=rev
Log:
SM-245: Support URIs to address a JBI exchange and resolution of WS-Addressing EPR
SM-424: WS-Notification broker only creates subscriptions for endpoints in SM, should be possible
for endpoints outside SM

Modified:
    incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseLifeCycle.java
    incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
    incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/ActivationSpec.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java
    incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/support/ExchangeTarget.java
    incubator/servicemix/trunk/servicemix-eip/src/test/resources/org/apache/servicemix/eip/spring.xml
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpLifeCycle.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpResolvedEndpoint.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpSpringComponent.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
    incubator/servicemix/trunk/servicemix-wsn2005/pom.xml
    incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/jbi/JbiSubscription.java
    incubator/servicemix/trunk/servicemix-wsn2005/src/test/java/org/apache/servicemix/wsn/component/WSNComponentTest.java

Modified: incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseLifeCycle.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseLifeCycle.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseLifeCycle.java
(original)
+++ incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/BaseLifeCycle.java
Thu May  4 15:43:16 2006
@@ -26,6 +26,7 @@
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.MessageExchange.Role;
+import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.resource.spi.work.Work;
@@ -33,6 +34,7 @@
 import javax.transaction.Status;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
+import javax.xml.namespace.QName;
 
 import org.apache.commons.logging.Log;
 import org.apache.servicemix.JbiConstants;
@@ -87,6 +89,10 @@
     protected ObjectName createExtensionMBeanName() throws Exception {
         return this.context.getMBeanNames().createCustomComponentMBeanName("Configuration");
     }
+    
+    protected QName getEPRServiceName() {
+        return null;
+    }
 
     /* (non-Javadoc)
      * @see javax.jbi.component.ComponentLifeCycle#init(javax.jbi.component.ComponentContext)
@@ -363,16 +369,31 @@
             logger.debug("Received exchange: status: " + exchange.getStatus() + ", role:
" + exchange.getRole());
         }
         if (exchange.getRole() == Role.PROVIDER) {
+            boolean dynamic = false;
+            ServiceEndpoint endpoint = exchange.getEndpoint();
             String key = EndpointSupport.getKey(exchange.getEndpoint());
             Endpoint ep = (Endpoint) this.component.getRegistry().getEndpoint(key);
             if (ep == null) {
-                throw new IllegalStateException("Endpoint not found: " + key);
+                if (endpoint.getServiceName().equals(getEPRServiceName())) {
+                    ep = getResolvedEPR(exchange.getEndpoint());
+                    dynamic = true;
+                } 
+                if (ep == null) {
+                    throw new IllegalStateException("Endpoint not found: " + key);
+                }
             }
             ExchangeProcessor processor = ep.getProcessor();
             if (processor == null) {
                 throw new IllegalStateException("No processor found for endpoint: " + key);
             }
-            processor.process(exchange);
+            try {
+                processor.process(exchange);
+            } finally {
+                // If the endpoint is dynamic, deactivate it
+                if (dynamic) {
+                    ep.deactivate();
+                }
+            }
         } else {
             ExchangeProcessor processor = null;
             if (exchange.getProperty(JbiConstants.SENDER_ENDPOINT) != null) {
@@ -417,6 +438,16 @@
         String key = EndpointSupport.getKey(endpoint);
         exchange.setProperty(JbiConstants.SENDER_ENDPOINT, key);
         channel.send(exchange);
+    }
+    
+    /**
+     * Handle an exchange sent to an EPR resolved by this component
+     * @param exchange
+     * @return an endpoint to use for handling the exchange
+     * @throws Exception
+     */
+    protected Endpoint getResolvedEPR(ServiceEndpoint ep) throws Exception {
+        throw new UnsupportedOperationException("Component does not handle EPR exchanges");
     }
 
 }

Modified: incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Endpoint.java
Thu May  4 15:43:16 2006
@@ -114,7 +114,7 @@
         return true;
     }
 
-    public abstract void activate() throws Exception ;
+    public abstract void activate() throws Exception;
     
     public abstract void deactivate() throws Exception;
 

Modified: incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
(original)
+++ incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
Thu May  4 15:43:16 2006
@@ -36,6 +36,10 @@
     public ServiceUnit() {
     }
     
+    public ServiceUnit(BaseComponent component) {
+        this.component = component;
+    }
+    
     public void start() throws Exception {
         // Activate endpoints
         List activated = new ArrayList();

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/ActivationSpec.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/ActivationSpec.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/ActivationSpec.java
(original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/ActivationSpec.java
Thu May  4 15:43:16 2006
@@ -21,6 +21,7 @@
 import org.apache.servicemix.jbi.resolver.InterfaceNameEndpointResolver;
 import org.apache.servicemix.jbi.resolver.ServiceAndEndpointNameResolver;
 import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
+import org.apache.servicemix.jbi.resolver.URIResolver;
 
 import javax.xml.namespace.QName;
 
@@ -55,6 +56,7 @@
     private SubscriptionSpec[] subscriptions = {};
     private boolean failIfNoDestinationEndpoint = true;
     private Boolean persistent;
+    private String destinationUri;
 
 
     public ActivationSpec() {
@@ -273,10 +275,10 @@
                 return new ServiceNameEndpointResolver(destinationService);
             }
         }
-        else {
-            if (destinationInterface != null) {
-                return new InterfaceNameEndpointResolver(destinationInterface);
-            }
+        else if (destinationInterface != null) {
+            return new InterfaceNameEndpointResolver(destinationInterface);
+        } else if (destinationUri != null) {
+            return new URIResolver(destinationUri);
         }
         return null;
     }
@@ -295,6 +297,20 @@
 	public void setPersistent(Boolean persistent) {
 		this.persistent = persistent;
 	}
+
+    /**
+     * @return the destinationUri
+     */
+    public String getDestinationUri() {
+        return destinationUri;
+    }
+
+    /**
+     * @param destinationUri the destinationUri to set
+     */
+    public void setDestinationUri(String destinationUri) {
+        this.destinationUri = destinationUri;
+    }
 
 
 }

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java
(original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java
Thu May  4 15:43:16 2006
@@ -46,8 +46,12 @@
 import org.apache.servicemix.jbi.servicedesc.AbstractServiceEndpoint;
 import org.apache.servicemix.jbi.servicedesc.DynamicEndpoint;
 import org.apache.servicemix.jbi.servicedesc.InternalEndpoint;
+import org.apache.servicemix.jbi.util.DOMUtil;
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
 import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
@@ -236,9 +240,87 @@
                 return new DynamicEndpoint(connector.getComponentNameSpace(), se, epr); 

             }
         }
+        return resolveStandardEPR(epr);
+    }
+    
+    /**
+     * Resolve a standard EPR understood by ServiceMix container.
+     * Currently, the supported syntax is the WSA one, the address uri
+     * being parsed with the following possiblities:
+     *    jbi:endpoint:service-namespace/service-name/endpoint
+     *    jbi:endpoint:service-namespace:service-name:endpoint
+     *    
+     * The full EPR will look like:
+     *   <epr xmlns:wsa="http://www.w3.org/2005/08/addressing">
+     *     <wsa:Address>jbi:endpoint:http://foo.bar.com/service/endpoint</wsa:Address>
+     *   </epr>
+     *   
+     * BCs should also be able to resolve such EPR but using their own URI parsing,
+     * for example:
+     *   <epr xmlns:wsa="http://www.w3.org/2005/08/addressing">
+     *     <wsa:Address>http://foo.bar.com/myService?http.soap=true</wsa:Address>
+     *   </epr>
+     * 
+     * or
+     *   <epr xmlns:wsa="http://www.w3.org/2005/08/addressing">
+     *     <wsa:Address>jms://activemq/queue/FOO.BAR?persistent=true</wsa:Address>
+     *   </epr>
+     *    
+     * Note that the separator should be same as the one used in the namespace
+     * depending on the namespace:
+     *     http://foo.bar.com  => '/'
+     *     urn:foo:bar         => ':' 
+     *    
+     * The syntax is the same as the one that can be used to specifiy a target
+     * for a JBI exchange with the restriction that it only allows the
+     * endpoint subprotocol to be used. 
+     * 
+     * @param epr
+     * @return
+     */
+    public ServiceEndpoint resolveStandardEPR(DocumentFragment epr) {
+        try {
+            if (epr.getChildNodes().getLength() == 1) {
+                Node child = epr.getFirstChild();
+                if (child instanceof Element) {
+                    Element elem = (Element) child;
+                    NodeList nl = elem.getElementsByTagNameNS("http://www.w3.org/2005/08/addressing",
"Address");
+                    if (nl.getLength() == 1) {
+                        Element address = (Element) nl.item(0);
+                        String uri = DOMUtil.getElementText(address);
+                        if (uri != null) {
+                            uri = uri.trim();
+                        }
+                        if (uri.startsWith("endpoint:")) {
+                            uri = uri.substring("endpoint:".length());
+                            String[] parts = split(uri);
+                            return getInternalEndpoint(new QName(parts[0], parts[1]), parts[2]);
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            // Ignored
+        }
         return null;
     }
 
+    protected String[] split(String uri) {
+        char sep;
+        uri = uri.trim();
+        if (uri.indexOf('/') > 0) {
+            sep = '/';
+        } else {
+            sep = ':';
+        }
+        int idx1 = uri.lastIndexOf(sep);
+        int idx2 = uri.lastIndexOf(sep, idx1 - 1);
+        String epName = uri.substring(idx1 + 1);
+        String svcName = uri.substring(idx2 + 1, idx1);
+        String nsUri   = uri.substring(0, idx2);
+        return new String[] { nsUri, svcName, epName };
+    }
+    
     /**
      * @param provider
      * @param externalEndpoint the external endpoint to be registered, must be non-null.

Modified: incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/support/ExchangeTarget.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/support/ExchangeTarget.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/support/ExchangeTarget.java
(original)
+++ incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/support/ExchangeTarget.java
Thu May  4 15:43:16 2006
@@ -6,7 +6,9 @@
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.xml.namespace.QName;
 
+import org.apache.servicemix.jbi.resolver.URIResolver;
 import org.springframework.beans.factory.InitializingBean;
+import org.w3c.dom.DocumentFragment;
 
 /**
  * An ExchangeTarget may be used to specify the target of an exchange,
@@ -26,20 +28,22 @@
     private QName service;
 
     private String endpoint;
+    
+    private String uri;
 
     /**
-     * @return Returns the endpointName.
+     * @return Returns the endpoint.
      */
     public String getEndpoint() {
         return endpoint;
     }
 
     /**
-     * @param endpointName
-     *            The endpointName to set.
+     * @param endpoint
+     *            The endpoint to set.
      */
-    public void setEndpoint(String endpointName) {
-        this.endpoint = endpointName;
+    public void setEndpoint(String endpoint) {
+        this.endpoint = endpoint;
     }
 
     /**
@@ -73,18 +77,32 @@
     }
 
     /**
-     * @return Returns the serviceName.
+     * @return Returns the service.
      */
     public QName getService() {
         return service;
     }
 
     /**
-     * @param serviceName
-     *            The serviceName to set.
+     * @param service
+     *            The service to set.
      */
-    public void setService(QName serviceName) {
-        this.service = serviceName;
+    public void setService(QName service) {
+        this.service = service;
+    }
+
+    /**
+     * @return the uri
+     */
+    public String getUri() {
+        return uri;
+    }
+
+    /**
+     * @param uri the uri to set
+     */
+    public void setUri(String uri) {
+        this.uri = uri;
     }
 
     /**
@@ -93,8 +111,33 @@
      * @throws MessagingException if the target could not be configured
      */
     public void configureTarget(MessageExchange exchange, ComponentContext context) throws
MessagingException {
-        if (_interface == null && service == null) {
-            throw new MessagingException("interfaceName or serviceName should be specified");
+        if (_interface == null && service == null && uri == null) {
+            throw new MessagingException("interface, service or uri should be specified");
+        }
+        if (uri != null) {
+            if (uri.startsWith("interface:")) {
+                String uri = this.uri.substring(10);
+                String[] parts = URIResolver.split2(uri);
+                exchange.setInterfaceName(new QName(parts[0], parts[1]));
+            } else if (uri.startsWith("operation:")) {
+                String uri = this.uri.substring(10);
+                String[] parts = URIResolver.split3(uri);
+                exchange.setInterfaceName(new QName(parts[0], parts[1]));
+                exchange.setOperation(new QName(parts[0], parts[2]));
+            } else if (uri.startsWith("service:")) {
+                String uri = this.uri.substring(8);
+                String[] parts = URIResolver.split2(uri);
+                exchange.setService(new QName(parts[0], parts[1]));
+            } else if (uri.startsWith("endpoint:")) {
+                String uri = this.uri.substring(9);
+                String[] parts = URIResolver.split3(uri);
+                ServiceEndpoint se = context.getEndpoint(new QName(parts[0], parts[1]), parts[2]);
+                exchange.setEndpoint(se);
+            } else {
+                DocumentFragment epr = URIResolver.createWSAEPR(uri);
+                ServiceEndpoint se = context.resolveEndpointReference(epr);
+                exchange.setEndpoint(se);
+            }
         }
         if (_interface != null) {
             exchange.setInterfaceName(_interface);
@@ -115,8 +158,8 @@
      * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
      */
     public void afterPropertiesSet() throws Exception {
-        if (_interface == null && service == null) {
-            throw new MessagingException("interfaceName or serviceName should be specified");
+        if (_interface == null && service == null && uri == null) {
+            throw new MessagingException("interface, service or uri should be specified");
         }
     }
 

Modified: incubator/servicemix/trunk/servicemix-eip/src/test/resources/org/apache/servicemix/eip/spring.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/test/resources/org/apache/servicemix/eip/spring.xml?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/test/resources/org/apache/servicemix/eip/spring.xml
(original)
+++ incubator/servicemix/trunk/servicemix-eip/src/test/resources/org/apache/servicemix/eip/spring.xml
Thu May  4 15:43:16 2006
@@ -32,7 +32,7 @@
               <eip:xpath-splitter service="test:xpathSplitter" endpoint="endpoint" 
                                   xpath="/*/*" namespaceContext="#nsContext">
                 <eip:target>
-                  <eip:exchange-target service="test:router" />
+                  <eip:exchange-target uri="service:http://test/router" />
                 </eip:target>
               </eip:xpath-splitter>
               <!-- END SNIPPET: xpath-splitter -->
@@ -45,7 +45,7 @@
                       <eip:xpath-predicate xpath="count(/test:echo) = 1" namespaceContext="#nsContext"
/>
                     </eip:predicate>
                     <eip:target>
-                      <eip:exchange-target service="test:pipeline" />
+                      <eip:exchange-target uri="endpoint:http://test/pipeline/endpoint"
/>
                     </eip:target>
                   </eip:routing-rule>
                   <eip:routing-rule>

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
Thu May  4 15:43:16 2006
@@ -21,10 +21,7 @@
 import org.apache.servicemix.common.BaseLifeCycle;
 import org.apache.servicemix.common.BaseServiceUnitManager;
 import org.apache.servicemix.common.Deployer;
-import org.apache.servicemix.jbi.util.DOMUtil;
 import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
 
 public class HttpComponent extends BaseComponent {
 
@@ -47,18 +44,7 @@
      * @see javax.jbi.component.Component#resolveEndpointReference(org.w3c.dom.DocumentFragment)
      */
     public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
-        if (epr.getChildNodes().getLength() == 1) {
-            Node child = epr.getFirstChild();
-            if (child instanceof Element) {
-                Element elem = (Element) child;
-                String nsUri = elem.getNamespaceURI();
-                String name = elem.getLocalName();
-                if (HttpResolvedEndpoint.EPR_URI.equals(nsUri) && HttpResolvedEndpoint.EPR_NAME.equals(name))
{
-                    return new HttpResolvedEndpoint(epr, DOMUtil.getElementText(elem));
-                }
-            }
-        }
-        return null;
+        return HttpResolvedEndpoint.resolveEndpoint(epr);
     }
     
 }

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpLifeCycle.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpLifeCycle.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpLifeCycle.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpLifeCycle.java
Thu May  4 15:43:16 2006
@@ -15,11 +15,22 @@
  */
 package org.apache.servicemix.http;
 
+import java.net.URI;
+import java.util.Map;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+
+import org.apache.activemq.util.IntrospectionSupport;
+import org.apache.activemq.util.URISupport;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
 import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
 import org.apache.servicemix.common.BaseComponent;
 import org.apache.servicemix.common.BaseLifeCycle;
+import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.common.ServiceUnit;
 
 public class HttpLifeCycle extends BaseLifeCycle {
 
@@ -102,6 +113,30 @@
     protected void doStop() throws Exception {
         super.doStop();
         server.stop();
+    }
+    
+    protected QName getEPRServiceName() {
+        return HttpResolvedEndpoint.EPR_SERVICE;
+    }
+    
+    protected Endpoint getResolvedEPR(ServiceEndpoint ep) throws Exception {
+        // We receive an exchange for an EPR that has not been used yet.
+        // Register a provider endpoint and restart processing.
+        HttpEndpoint httpEp = new HttpEndpoint();
+        httpEp.setServiceUnit(new ServiceUnit(component));
+        httpEp.setService(ep.getServiceName());
+        httpEp.setEndpoint(ep.getEndpointName());
+        httpEp.setRole(MessageExchange.Role.PROVIDER);
+        URI uri = new URI(ep.getEndpointName());
+        Map map = URISupport.parseQuery(uri.getQuery());
+        if( IntrospectionSupport.setProperties(httpEp, map, "http.") ) {
+            uri = URISupport.createRemainingURI(uri, map);
+        }
+        if (httpEp.getLocationURI() == null) {
+            httpEp.setLocationURI(uri.toString());
+        }
+        httpEp.activateDynamic();
+        return httpEp;
     }
 
 }

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpResolvedEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpResolvedEndpoint.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpResolvedEndpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpResolvedEndpoint.java
Thu May  4 15:43:16 2006
@@ -18,11 +18,16 @@
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.xml.namespace.QName;
 
+import org.apache.servicemix.jbi.util.DOMUtil;
 import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 public class HttpResolvedEndpoint implements ServiceEndpoint {
 
     public final static String EPR_URI = "urn:servicemix:http";
+    public final static QName EPR_SERVICE = new QName(EPR_URI, "HttpComponent");
     public final static String EPR_NAME = "epr";
     
     private DocumentFragment reference;
@@ -30,6 +35,7 @@
     
     public HttpResolvedEndpoint(DocumentFragment epr, String epName) {
         this.reference = epr;
+        this.epName = epName;
     }
 
     public DocumentFragment getAsReference(QName operationName) {
@@ -45,7 +51,36 @@
     }
 
     public QName getServiceName() {
-        return new QName("urn:servicemix:http", "HttpComponent");
+        return EPR_SERVICE;
+    }
+    
+    public static ServiceEndpoint resolveEndpoint(DocumentFragment epr) {
+        if (epr.getChildNodes().getLength() == 1) {
+            Node child = epr.getFirstChild();
+            if (child instanceof Element) {
+                Element elem = (Element) child;
+                String nsUri = elem.getNamespaceURI();
+                String name = elem.getLocalName();
+                // Check simple endpoints
+                if (HttpResolvedEndpoint.EPR_URI.equals(nsUri) && HttpResolvedEndpoint.EPR_NAME.equals(name))
{
+                    return new HttpResolvedEndpoint(epr, DOMUtil.getElementText(elem));
+                // Check WSA endpoints
+                } else {
+                    NodeList nl = elem.getElementsByTagNameNS("http://www.w3.org/2005/08/addressing",
"Address");
+                    if (nl.getLength() == 1) {
+                        Element address = (Element) nl.item(0);
+                        String uri = DOMUtil.getElementText(address);
+                        if (uri != null) {
+                            uri = uri.trim();
+                            if (uri.startsWith("http://") || uri.startsWith("https://"))
{
+                                return new HttpResolvedEndpoint(epr, uri);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return null;
     }
     
 }

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpSpringComponent.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpSpringComponent.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpSpringComponent.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpSpringComponent.java
Thu May  4 15:43:16 2006
@@ -20,10 +20,7 @@
 import org.apache.servicemix.common.BaseComponent;
 import org.apache.servicemix.common.BaseLifeCycle;
 import org.apache.servicemix.common.ServiceUnit;
-import org.apache.servicemix.jbi.util.DOMUtil;
 import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
 
 /**
  * 
@@ -47,18 +44,7 @@
      * @see javax.jbi.component.Component#resolveEndpointReference(org.w3c.dom.DocumentFragment)
      */
     public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
-        if (epr.getChildNodes().getLength() == 1) {
-            Node child = epr.getFirstChild();
-            if (child instanceof Element) {
-                Element elem = (Element) child;
-                String nsUri = elem.getNamespaceURI();
-                String name = elem.getLocalName();
-                if (HttpResolvedEndpoint.EPR_URI.equals(nsUri) && HttpResolvedEndpoint.EPR_NAME.equals(name))
{
-                    return new HttpResolvedEndpoint(epr, DOMUtil.getElementText(elem));
-                }
-            }
-        }
-        return null;
+        return HttpResolvedEndpoint.resolveEndpoint(epr);
     }
     
     public HttpEndpoint[] getEndpoints() {

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=399873&r1=399872&r2=399873&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
Thu May  4 15:43:16 2006
@@ -295,20 +295,31 @@
         }
         processor.start();
     }
+    
+    public void activateDynamic() throws Exception {
+        if (getRole() == Role.PROVIDER) {
+            processor = createProviderProcessor();
+        } else {
+            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);
+        if (activated != null) {
+            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();
     }

Modified: incubator/servicemix/trunk/servicemix-wsn2005/pom.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/pom.xml?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/pom.xml (original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/pom.xml Thu May  4 15:43:16 2006
@@ -50,6 +50,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>servicemix-http</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>quartz</groupId>
       <artifactId>quartz</artifactId>
       <scope>test</scope>

Modified: incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/jbi/JbiSubscription.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/jbi/JbiSubscription.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/jbi/JbiSubscription.java
(original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/jbi/JbiSubscription.java
Thu May  4 15:43:16 2006
@@ -23,7 +23,10 @@
 import javax.jbi.messaging.MessageExchangeFactory;
 import javax.jbi.messaging.NormalizedMessage;
 import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.bind.JAXBContext;
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.dom.DOMSource;
 
 import org.apache.commons.logging.Log;
@@ -41,7 +44,10 @@
 import org.apache.servicemix.wsn.jms.JmsSubscription;
 import org.oasis_open.docs.wsn.b_2.Subscribe;
 import org.oasis_open.docs.wsn.b_2.SubscribeCreationFailedFaultType;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 public class JbiSubscription extends JmsSubscription {
 
@@ -64,13 +70,40 @@
 	@Override
 	protected void validateSubscription(Subscribe subscribeRequest) throws InvalidFilterFault,
InvalidMessageContentExpressionFault, InvalidProducerPropertiesExpressionFault, InvalidTopicExpressionFault,
SubscribeCreationFailedFault, TopicExpressionDialectUnknownFault, TopicNotSupportedFault,
UnacceptableInitialTerminationTimeFault {
 		super.validateSubscription(subscribeRequest);
-        String[] parts = split(consumerReference.getAddress().getValue().trim());
-        endpoint = getContext().getEndpoint(new QName(parts[0], parts[1]), parts[2]);
+        try {
+            endpoint = resolveConsumer(subscribeRequest);
+        } catch (Exception e) {
+            SubscribeCreationFailedFaultType fault = new SubscribeCreationFailedFaultType();
+            throw new SubscribeCreationFailedFault("Unable to resolve consumer reference
endpoint", fault, e);
+        }
         if (endpoint == null) {
             SubscribeCreationFailedFaultType fault = new SubscribeCreationFailedFaultType();
             throw new SubscribeCreationFailedFault("Unable to resolve consumer reference
endpoint", fault);
         }
 	}
+    
+    protected ServiceEndpoint resolveConsumer(Subscribe subscribeRequest) throws Exception
{
+        // Try to resolve the WSA endpoint
+        JAXBContext ctx = JAXBContext.newInstance(Subscribe.class);
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        Document doc = db.newDocument();
+        ctx.createMarshaller().marshal(subscribeRequest, doc);
+        NodeList nl = doc.getDocumentElement().getElementsByTagNameNS("http://docs.oasis-open.org/wsn/b-2",
"ConsumerReference");
+        if (nl.getLength() != 1) {
+            throw new Exception("Subscribe request must have exactly one ConsumerReference
node");
+        }
+        Element el = (Element) nl.item(0);
+        DocumentFragment epr = doc.createDocumentFragment();
+        epr.appendChild(el);
+        ServiceEndpoint endpoint = getContext().resolveEndpointReference(epr);
+        if (endpoint == null) {
+            String[] parts = split(subscribeRequest.getConsumerReference().getAddress().getValue().trim());
+            endpoint = getContext().getEndpoint(new QName(parts[0], parts[1]), parts[2]);
+        }
+        return endpoint;
+    }
 
     protected String[] split(String uri) {
 		char sep;

Modified: incubator/servicemix/trunk/servicemix-wsn2005/src/test/java/org/apache/servicemix/wsn/component/WSNComponentTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/src/test/java/org/apache/servicemix/wsn/component/WSNComponentTest.java?rev=399873&r1=399872&r2=399873&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/src/test/java/org/apache/servicemix/wsn/component/WSNComponentTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/src/test/java/org/apache/servicemix/wsn/component/WSNComponentTest.java
Thu May  4 15:43:16 2006
@@ -31,9 +31,12 @@
 
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
+import org.apache.servicemix.http.HttpEndpoint;
+import org.apache.servicemix.http.HttpSpringComponent;
 import org.apache.servicemix.jbi.container.ActivationSpec;
 import org.apache.servicemix.jbi.container.JBIContainer;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.soap.SoapHelper;
 import org.apache.servicemix.tck.Receiver;
 import org.apache.servicemix.tck.ReceiverComponent;
 import org.apache.servicemix.wsn.client.AbstractWSAClient;
@@ -325,6 +328,40 @@
         Thread.sleep(50);
         receiver.getMessageList().assertMessagesReceived(1);
         receiver.getMessageList().flushMessages();
+    }
+    
+    public void testDynamicSubscription() throws Exception {
+        HttpSpringComponent httpComponent = new HttpSpringComponent();
+        
+        HttpEndpoint httpWSNBroker = new HttpEndpoint();
+        httpWSNBroker.setService(new QName("http://servicemix.org/wsnotification", "NotificationBroker"));
+        httpWSNBroker.setEndpoint("Broker");
+        httpWSNBroker.setRoleAsString("consumer");
+        httpWSNBroker.setLocationURI("http://localhost:8192/WSNBroker/");
+        httpWSNBroker.setSoap(true);
+        
+        HttpEndpoint httpReceiver = new HttpEndpoint();
+        httpReceiver.setService(new QName("receiver"));
+        httpReceiver.setEndpoint("endpoint");
+        httpReceiver.setLocationURI("http://localhost:8192/Receiver/");
+        httpReceiver.setDefaultMep(SoapHelper.IN_ONLY);
+        httpReceiver.setSoap(true);
+        
+        httpComponent.setEndpoints(new HttpEndpoint[] { httpWSNBroker, httpReceiver });
+        jbi.activateComponent(new ActivationSpec("servicemix-http", httpComponent));
+        
+        ReceiverComponent receiver = new ReceiverComponent();
+        receiver.setService(new QName("receiver"));
+        receiver.setEndpoint("endpoint");
+        jbi.activateComponent(new ActivationSpec("receiver", receiver));
+        
+        EndpointReferenceType epr = new EndpointReferenceType();
+        epr.setAddress(new AttributedURIType());
+        epr.getAddress().setValue("http://localhost:8192/Receiver/?http.soap=true");
+        wsnBroker.subscribe(epr, "myTopic", null);
+        wsnBroker.notify("myTopic", parse("<hello>world</hello>"));
+        
+        receiver.getMessageList().assertMessagesReceived(1);
     }
 	
 	protected Element parse(String txt) throws Exception {



Mime
View raw message