You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2009/02/05 16:30:30 UTC

svn commit: r741138 - in /servicemix/smx4/nmr/trunk/jbi/runtime: ./ src/main/java/org/apache/servicemix/jbi/runtime/impl/ src/test/java/org/apache/servicemix/jbi/runtime/

Author: gnodet
Date: Thu Feb  5 15:30:29 2009
New Revision: 741138

URL: http://svn.apache.org/viewvc?rev=741138&view=rev
Log:
SMX4KNL-65, SMX4KNL-66: refactor ServiceEndpoint implementation, switch the service name property to a string value, make public / static a few methods

Modified:
    servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DeliveryChannelImpl.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EndpointImpl.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MessageExchangeImpl.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ServiceEndpointImpl.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/ExchangeCompletedListener.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/IntegrationTest.java

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml?rev=741138&r1=741137&r2=741138&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml Thu Feb  5 15:30:29 2009
@@ -127,6 +127,23 @@
                     </instructions>
                 </configuration>
             </plugin>
+            <!-- generate the attached tests jar -->
+            <plugin>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>2.2</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <excludes>
+                        <exclude>log4j.properties</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java?rev=741138&r1=741137&r2=741138&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java Thu Feb  5 15:30:29 2009
@@ -54,13 +54,6 @@
 
 public abstract class AbstractComponentContext implements ComponentContext, MBeanNames {
 
-    public static final String JBI_NAMESPACE = "http://java.sun.com/jbi/end-point-reference";
-    public static final String JBI_PREFIX = "jbi:";
-    public static final String JBI_ENDPOINT_REFERENCE = "end-point-reference";
-    public static final String JBI_SERVICE_NAME = "service-name";
-    public static final String JBI_ENDPOINT_NAME = "end-point-name";
-    public static final String XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
-
     private static final Log LOG = LogFactory.getLog(AbstractComponentContext.class);
 
     protected DeliveryChannel dc;
@@ -83,24 +76,26 @@
             return null;
         }
         Map<String, ?> p = getNmr().getEndpointRegistry().getProperties(endpoints.get(0));
-        return new ComponentContextImpl.SimpleServiceEndpoint(p);
+        return new ServiceEndpointImpl(p);
     }
 
     public Document getEndpointDescriptor(ServiceEndpoint endpoint) throws JBIException {
-        if (endpoint instanceof ComponentContextImpl.SimpleServiceEndpoint) {
-            Map<String, ?> props = ((ComponentContextImpl.SimpleServiceEndpoint) endpoint).getProperties();
-            String url = (String) props.get(Endpoint.WSDL_URL);
-            if (url != null) {
-                InputStream is = null;
-                try {
-                    is = new URL(url).openStream();
-                    return DOMUtil.parseDocument(is);
-                } catch (Exception e) {
-                    if (is != null) {
-                        try {
-                            is.close();
-                        } catch (IOException e2) {
-                            // Ignore
+        if (endpoint instanceof ServiceEndpointImpl) {
+            Map<String, ?> props = ((ServiceEndpointImpl) endpoint).getProperties();
+            if (props != null) {
+                String url = (String) props.get(Endpoint.WSDL_URL);
+                if (url != null) {
+                    InputStream is = null;
+                    try {
+                        is = new URL(url).openStream();
+                        return DOMUtil.parseDocument(is);
+                    } catch (Exception e) {
+                        if (is != null) {
+                            try {
+                                is.close();
+                            } catch (IOException e2) {
+                                // Ignore
+                            }
                         }
                     }
                 }
@@ -115,7 +110,7 @@
         return internalQueryEndpoints(props);
     }
 
-    protected ComponentContextImpl.SimpleServiceEndpoint[] internalQueryEndpoints(Map<String, Object> props) {
+    protected ServiceEndpointImpl[] internalQueryEndpoints(Map<String, Object> props) {
         List<Endpoint> endpoints = getNmr().getEndpointRegistry().query(props);
         List<ServiceEndpoint> ses = new ArrayList<ServiceEndpoint>();
         for (Endpoint endpoint : endpoints) {
@@ -123,10 +118,10 @@
             QName serviceName = (QName) epProps.get(Endpoint.SERVICE_NAME);
             String endpointName = (String) epProps.get(Endpoint.ENDPOINT_NAME);
             if (serviceName != null && endpointName != null) {
-                ses.add(new ComponentContextImpl.SimpleServiceEndpoint(epProps));
+                ses.add(new ServiceEndpointImpl(epProps));
             }
         }
-        return ses.toArray(new ComponentContextImpl.SimpleServiceEndpoint[ses.size()]);
+        return ses.toArray(new ServiceEndpointImpl[ses.size()]);
     }
 
     public ServiceEndpoint[] getEndpointsForService(QName serviceName) {
@@ -241,18 +236,18 @@
             }
             Element el = (Element) n;
             // Namespace should be "http://java.sun.com/jbi/end-point-reference"
-            if (el.getNamespaceURI() == null || !el.getNamespaceURI().equals(JBI_NAMESPACE)) {
+            if (el.getNamespaceURI() == null || !el.getNamespaceURI().equals(ServiceEndpointImpl.JBI_NAMESPACE)) {
                 continue;
             }
-            if (el.getLocalName() == null || !el.getLocalName().equals(JBI_ENDPOINT_REFERENCE)) {
+            if (el.getLocalName() == null || !el.getLocalName().equals(ServiceEndpointImpl.JBI_ENDPOINT_REFERENCE)) {
                 continue;
             }
-            String serviceName = el.getAttributeNS(el.getNamespaceURI(), JBI_SERVICE_NAME);
+            String serviceName = el.getAttributeNS(el.getNamespaceURI(), ServiceEndpointImpl.JBI_SERVICE_NAME);
             // Now the DOM pain-in-the-you-know-what: we need to come up with QName for this;
             // fortunately, there is only one place where the xmlns:xxx attribute could be, on
             // the end-point-reference element!
             QName serviceQName = DOMUtil.createQName(el, serviceName);
-            String endpointName = el.getAttributeNS(el.getNamespaceURI(), JBI_ENDPOINT_NAME);
+            String endpointName = el.getAttributeNS(el.getNamespaceURI(), ServiceEndpointImpl.JBI_ENDPOINT_NAME);
             return getEndpoint(serviceQName, endpointName);
         }
         return null;
@@ -338,55 +333,4 @@
         return null;
     }
 
-    protected static class SimpleServiceEndpoint implements ServiceEndpoint {
-
-        private Map<String, ?> properties;
-        private EndpointImpl endpoint;
-
-        public SimpleServiceEndpoint(Map<String, ?> properties) {
-            this.properties = properties;
-        }
-
-        public SimpleServiceEndpoint(Map<String, ?> properties, EndpointImpl endpoint) {
-            this.properties = properties;
-            this.endpoint = endpoint;
-        }
-
-        public Map<String, ?> getProperties() {
-            return properties;
-        }
-
-        public EndpointImpl getEndpoint() {
-            return endpoint;
-        }
-
-        public DocumentFragment getAsReference(QName operationName) {
-            try {
-                Document doc = DOMUtil.newDocument();
-                DocumentFragment fragment = doc.createDocumentFragment();
-                Element epr = doc.createElementNS(JBI_NAMESPACE, JBI_PREFIX + JBI_ENDPOINT_REFERENCE);
-                epr.setAttributeNS(XMLNS_NAMESPACE, "xmlns:sns", endpoint.getServiceName().getNamespaceURI());
-                epr.setAttributeNS(JBI_NAMESPACE, JBI_PREFIX + JBI_SERVICE_NAME, "sns:" + endpoint.getServiceName().getLocalPart());
-                epr.setAttributeNS(JBI_NAMESPACE, JBI_PREFIX + JBI_ENDPOINT_NAME, endpoint.getEndpointName());
-                fragment.appendChild(epr);
-                return fragment;
-            } catch (Exception e) {
-                LOG.warn("Unable to create reference for ServiceEndpoint " + endpoint, e);
-                return null;
-            }
-        }
-
-        public String getEndpointName() {
-            return (String) properties.get(Endpoint.ENDPOINT_NAME);
-        }
-
-        public QName[] getInterfaces() {
-            QName itf = (QName) properties.get(Endpoint.INTERFACE_NAME);
-            return itf != null ? new QName[] { itf } : new QName[0];
-        }
-
-        public QName getServiceName() {
-            return (QName) properties.get(Endpoint.SERVICE_NAME);
-        }
-    }
 }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java?rev=741138&r1=741137&r2=741138&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java Thu Feb  5 15:30:29 2009
@@ -19,37 +19,22 @@
 import java.io.File;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.MissingResourceException;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
-import java.util.logging.Logger;
 
 import javax.jbi.JBIException;
-import javax.jbi.management.MBeanNames;
-import javax.jbi.messaging.DeliveryChannel;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.servicedesc.ServiceEndpoint;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
 import javax.xml.namespace.QName;
 import javax.xml.transform.TransformerException;
 
 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 org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.document.DocumentRepository;
 import org.apache.servicemix.jbi.runtime.ComponentRegistry;
-import org.apache.servicemix.jbi.runtime.Environment;
 import org.apache.servicemix.jbi.runtime.ComponentWrapper;
 import org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil;
-import org.apache.servicemix.jbi.runtime.impl.utils.URIResolver;
-import org.apache.servicemix.jbi.runtime.impl.utils.WSAddressingConstants;
 import org.apache.servicemix.nmr.api.Endpoint;
 import org.apache.servicemix.nmr.api.Exchange;
 
@@ -77,7 +62,7 @@
         this.component = component;
         this.properties = properties;
         this.queue = new ArrayBlockingQueue<Exchange>(DEFAULT_QUEUE_CAPACITY);
-        this.componentEndpoint = new EndpointImpl();
+        this.componentEndpoint = new EndpointImpl(properties);
         this.componentEndpoint.setQueue(queue);
         this.componentRegistry.getNmr().getEndpointRegistry().register(componentEndpoint, properties);
         this.dc = new DeliveryChannelImpl(this, componentEndpoint.getChannel(), queue);
@@ -99,14 +84,12 @@
 
     public synchronized ServiceEndpoint activateEndpoint(QName serviceName, String endpointName) throws JBIException {
         try {
-            EndpointImpl endpoint = new EndpointImpl();
-            endpoint.setQueue(queue);
-            endpoint.setServiceName(serviceName);
-            endpoint.setEndpointName(endpointName);
             Map<String, Object> props = new HashMap<String, Object>();
             props.put(Endpoint.NAME, serviceName.toString() + ":" + endpointName);
-            props.put(Endpoint.SERVICE_NAME, serviceName);
+            props.put(Endpoint.SERVICE_NAME, serviceName.toString());
             props.put(Endpoint.ENDPOINT_NAME, endpointName);
+            EndpointImpl endpoint = new EndpointImpl(props);
+            endpoint.setQueue(queue);
             Document doc = component.getComponent().getServiceDescription(endpoint);
             if (doc != null) {
                 String data = DOMUtil.asXML(doc);
@@ -114,21 +97,15 @@
                 props.put(Endpoint.WSDL_URL, url);
             }
             componentRegistry.getNmr().getEndpointRegistry().register(endpoint,  props);
-            return new SimpleServiceEndpoint(props, endpoint);
+            return endpoint;
         } catch (TransformerException e) {
             throw new JBIException(e);
         }
     }
 
     public synchronized void deactivateEndpoint(ServiceEndpoint endpoint) throws JBIException {
-        EndpointImpl ep;
-        if (endpoint instanceof EndpointImpl) {
-            ep = (EndpointImpl) endpoint;
-        } else if (endpoint instanceof SimpleServiceEndpoint) {
-            ep = ((SimpleServiceEndpoint) endpoint).getEndpoint();
-        } else {
-            throw new IllegalArgumentException("Unrecognized endpoint");
-        }
+        // TODO: retrieve the correct endpoint if needed
+        EndpointImpl ep = (EndpointImpl) endpoint;
         componentRegistry.getNmr().getEndpointRegistry().unregister(ep, null);
     }
 

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DeliveryChannelImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DeliveryChannelImpl.java?rev=741138&r1=741137&r2=741138&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DeliveryChannelImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/DeliveryChannelImpl.java Thu Feb  5 15:30:29 2009
@@ -35,6 +35,7 @@
 import org.apache.servicemix.nmr.api.Exchange;
 import org.apache.servicemix.nmr.api.Pattern;
 import org.apache.servicemix.nmr.api.Reference;
+import org.apache.servicemix.nmr.api.NMR;
 import org.apache.servicemix.nmr.api.internal.InternalExchange;
 
 /**
@@ -152,7 +153,7 @@
         if (((InternalExchange) exchange).getDestination() != null && me.getEndpoint() == null) {
             Endpoint ep = ((InternalExchange) exchange).getDestination();
             Map<String, ?> props = context.getNmr().getEndpointRegistry().getProperties(ep);
-            QName serviceName = (QName) props.get(Endpoint.SERVICE_NAME);
+            QName serviceName = QName.valueOf((String) props.get(Endpoint.SERVICE_NAME));
             if (serviceName == null) {
                 serviceName = DEFAULT_SERVICE_NAME;
             }
@@ -167,7 +168,7 @@
 
     public void send(MessageExchange exchange) throws MessagingException {
         assert exchange != null;
-        createTarget(exchange);
+        createTarget(context.getNmr(), exchange);
         exchange.setProperty(SEND_SYNC, null);
         ((MessageExchangeImpl) exchange).afterSend();
         channel.send(((MessageExchangeImpl) exchange).getInternalExchange());
@@ -175,7 +176,7 @@
 
     public boolean sendSync(MessageExchange exchange) throws MessagingException {
         assert exchange != null;
-        createTarget(exchange);
+        createTarget(context.getNmr(), exchange);
         exchange.setProperty(SEND_SYNC, Boolean.TRUE);
         ((MessageExchangeImpl) exchange).afterSend();
         return channel.sendSync(((MessageExchangeImpl) exchange).getInternalExchange());
@@ -183,34 +184,38 @@
 
     public boolean sendSync(MessageExchange exchange, long timeout) throws MessagingException {
         assert exchange != null;
-        createTarget(exchange);
+        createTarget(context.getNmr(), exchange);
         exchange.setProperty(SEND_SYNC, Boolean.TRUE);
         ((MessageExchangeImpl) exchange).afterSend();
         return channel.sendSync(((MessageExchangeImpl) exchange).getInternalExchange(), timeout);
     }
 
-    protected void createTarget(MessageExchange messageExchange) throws MessagingException {
-        Exchange exchange = ((MessageExchangeImpl) messageExchange).getInternalExchange();
+    public static void createTarget(NMR nmr, MessageExchange messageExchange) {
+        createTarget(nmr, ((MessageExchangeImpl) messageExchange).getInternalExchange());
+    }
+
+    public static void createTarget(NMR nmr, Exchange exchange) {
         if (exchange.getTarget() == null) {
             Map<String, Object> props = new HashMap<String, Object>();
-            if (messageExchange.getEndpoint() != null) {
-                props.put(Endpoint.SERVICE_NAME, messageExchange.getEndpoint().getServiceName());
-                props.put(Endpoint.ENDPOINT_NAME, messageExchange.getEndpoint().getEndpointName());
+            ServiceEndpoint ep = MessageExchangeImpl.getEndpoint(exchange);
+            if (ep != null) {
+                props.put(Endpoint.SERVICE_NAME, ep.getServiceName().toString());
+                props.put(Endpoint.ENDPOINT_NAME, ep.getEndpointName());
             } else {
-                QName serviceName = messageExchange.getService();
+                QName serviceName = MessageExchangeImpl.getService(exchange);
                 if (serviceName != null) {
-                    props.put(Endpoint.SERVICE_NAME, serviceName);
+                    props.put(Endpoint.SERVICE_NAME, serviceName.toString());
                 } else {
-                    QName interfaceName = messageExchange.getInterfaceName();
+                    QName interfaceName = MessageExchangeImpl.getInterfaceName(exchange);
                     if (interfaceName != null) {
-                        props.put(Endpoint.INTERFACE_NAME, interfaceName);
+                        props.put(Endpoint.INTERFACE_NAME, interfaceName.toString());
                     }
                 }
             }
             if (props.isEmpty()) {
-                throw new MessagingException("No endpoint, service or interface name specified for routing");
+                throw new IllegalStateException("No endpoint, service or interface name specified for routing");
             }
-            Reference target = context.getNmr().getEndpointRegistry().lookup(props);
+            Reference target = nmr.getEndpointRegistry().lookup(props);
             exchange.setTarget(target);
         }
     }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EndpointImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EndpointImpl.java?rev=741138&r1=741137&r2=741138&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EndpointImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EndpointImpl.java Thu Feb  5 15:30:29 2009
@@ -24,17 +24,17 @@
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.xml.namespace.QName;
 import java.util.Queue;
+import java.util.Map;
 
 /**
  */
-public class EndpointImpl implements Endpoint, ServiceEndpoint {
+public class EndpointImpl extends ServiceEndpointImpl implements Endpoint {
 
     private Channel channel;
     private Queue<Exchange> queue;
-    private QName serviceName;
-    private String endpointName;
 
-    public EndpointImpl() {
+    public EndpointImpl(Map<String, ?> properties) {
+        super(properties);
     }
 
     public void process(Exchange exchange) {
@@ -44,16 +44,6 @@
         queue.offer(exchange);
     }
 
-    public DocumentFragment getAsReference(QName operationName) {
-        // TODO
-        return null;
-    }
-
-    public QName[] getInterfaces() {
-        // TODO
-        return new QName[0];
-    }
-
     public Channel getChannel() {
         return channel;
     }
@@ -70,22 +60,6 @@
         this.queue = queue;
     }
 
-    public QName getServiceName() {
-        return serviceName;
-    }
-
-    public void setServiceName(QName serviceName) {
-        this.serviceName = serviceName;
-    }
-
-    public String getEndpointName() {
-        return endpointName;
-    }
-
-    public void setEndpointName(String endpointName) {
-        this.endpointName = endpointName;
-    }
-
     public boolean equals(Object o) {
         return this == o;
     }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MessageExchangeImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MessageExchangeImpl.java?rev=741138&r1=741137&r2=741138&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MessageExchangeImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MessageExchangeImpl.java Thu Feb  5 15:30:29 2009
@@ -219,15 +219,15 @@
     }
 
     public ServiceEndpoint getEndpoint() {
-        return exchange.getProperty(SERVICE_ENDPOINT_PROP, ServiceEndpoint.class);
+        return getEndpoint(exchange);
     }
 
     public QName getInterfaceName() {
-        return exchange.getProperty(INTERFACE_NAME_PROP, QName.class);
+        return getInterfaceName(exchange);
     }
 
     public QName getService() {
-        return exchange.getProperty(SERVICE_NAME_PROP, QName.class);
+        return getService(exchange);
     }
 
     public boolean isTransacted() {
@@ -243,4 +243,16 @@
             throw new MessagingException("Can not send a terminated exchange");
         }
     }
+
+    public static ServiceEndpoint getEndpoint(Exchange exchange) {
+        return exchange.getProperty(SERVICE_ENDPOINT_PROP, ServiceEndpoint.class);
+    }
+
+    public static QName getInterfaceName(Exchange exchange) {
+        return exchange.getProperty(INTERFACE_NAME_PROP, QName.class);
+    }
+
+    public static QName getService(Exchange exchange) {
+        return exchange.getProperty(SERVICE_NAME_PROP, QName.class);
+    }
 }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ServiceEndpointImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ServiceEndpointImpl.java?rev=741138&r1=741137&r2=741138&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ServiceEndpointImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ServiceEndpointImpl.java Thu Feb  5 15:30:29 2009
@@ -16,26 +16,71 @@
  */
 package org.apache.servicemix.jbi.runtime.impl;
 
+import java.util.Map;
+
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.servicemix.nmr.api.Endpoint;
+import org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * A basic implementation of ServiceEndpoint
  */
 public class ServiceEndpointImpl implements ServiceEndpoint {
 
+    public static final String JBI_NAMESPACE = "http://java.sun.com/jbi/end-point-reference";
+    public static final String JBI_PREFIX = "jbi:";
+    public static final String JBI_ENDPOINT_REFERENCE = "end-point-reference";
+    public static final String JBI_SERVICE_NAME = "service-name";
+    public static final String JBI_ENDPOINT_NAME = "end-point-name";
+    public static final String XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
+
+    private static final Log LOG = LogFactory.getLog(ServiceEndpointImpl.class);
+
+    private final Map<String, ?> properties;
     private final QName serviceName;
     private final String endpointName;
+    private final QName[] interfaces;
+
+    public ServiceEndpointImpl(Map<String, ?> properties) {
+        this.properties = properties;
+        this.serviceName = getQName(properties.get(Endpoint.SERVICE_NAME));
+        this.endpointName = (String) properties.get(Endpoint.ENDPOINT_NAME);
+        this.interfaces = getQNames(properties.get(Endpoint.INTERFACE_NAME));
+    }
 
     public ServiceEndpointImpl(QName serviceName, String endpointName) {
         this.serviceName = serviceName;
         this.endpointName = endpointName;
+        this.interfaces = null;
+        this.properties = null;
     }
 
     public DocumentFragment getAsReference(QName operationName) {
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
+        try {
+            Document doc = DOMUtil.newDocument();
+            DocumentFragment fragment = doc.createDocumentFragment();
+            Element epr = doc.createElementNS(JBI_NAMESPACE, JBI_PREFIX + JBI_ENDPOINT_REFERENCE);
+            epr.setAttributeNS(XMLNS_NAMESPACE, "xmlns:sns", getServiceName().getNamespaceURI());
+            epr.setAttributeNS(JBI_NAMESPACE, JBI_PREFIX + JBI_SERVICE_NAME, "sns:" + getServiceName().getLocalPart());
+            epr.setAttributeNS(JBI_NAMESPACE, JBI_PREFIX + JBI_ENDPOINT_NAME, getEndpointName());
+            fragment.appendChild(epr);
+            return fragment;
+        } catch (Exception e) {
+            LOG.warn("Unable to create reference for ServiceEndpoint " + this, e);
+            return null;
+        }
+    }
+
+    public QName getServiceName() {
+        return serviceName;
     }
 
     public String getEndpointName() {
@@ -43,10 +88,37 @@
     }
 
     public QName[] getInterfaces() {
-        return new QName[0];  //To change body of implemented methods use File | Settings | File Templates.
+        return interfaces;
     }
 
-    public QName getServiceName() {
-        return serviceName;
+    public Map<String, ?> getProperties() {
+        return properties;
+    }
+
+    private static QName getQName(Object o) {
+        if (o instanceof QName) {
+            return (QName) o;
+        } else if (o instanceof String) {
+            return QName.valueOf((String) o);
+        } else {
+            return null;
+        }
+    }
+
+    private static QName[] getQNames(Object o) {
+        if (o instanceof QName[]) {
+            return (QName[]) o;
+        } else if (o instanceof QName) {
+            return new QName[] { (QName) o };
+        } else if (o instanceof String) {
+            String[] s = ((String) o).split(",");
+            QName[] q = new QName[s.length];
+            for (int i = 0; i < s.length; i++) {
+                q[i] = QName.valueOf(s[i]);
+            }
+            return q;
+        } else {
+            return null;
+        }
     }
 }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/ExchangeCompletedListener.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/ExchangeCompletedListener.java?rev=741138&r1=741137&r2=741138&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/ExchangeCompletedListener.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/ExchangeCompletedListener.java Thu Feb  5 15:30:29 2009
@@ -33,7 +33,7 @@
     private long timeout;
 
     public ExchangeCompletedListener() {
-        this(1000);
+        this(5000);
     }
 
     public ExchangeCompletedListener(long timeout) {
@@ -43,7 +43,7 @@
     public void exchangeSent(Exchange exchange) {
         synchronized (exchanges) {
             exchanges.put(exchange.getId(), exchange);
-            exchanges.notify();
+            exchanges.notifyAll();
         }
     }
 

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/IntegrationTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/IntegrationTest.java?rev=741138&r1=741137&r2=741138&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/IntegrationTest.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/IntegrationTest.java Thu Feb  5 15:30:29 2009
@@ -36,6 +36,8 @@
 import org.apache.servicemix.nmr.core.ServiceMix;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+
 public class IntegrationTest {
 
     @Test
@@ -58,7 +60,7 @@
             }
         };
         Map<String, Object> props = new HashMap<String, Object>();
-        props.put(Endpoint.SERVICE_NAME, new QName("target"));
+        props.put(Endpoint.SERVICE_NAME, new QName("target").toString());
         smx.getEndpointRegistry().register(tep, props);
 
         EIPComponent eip = new EIPComponent();
@@ -76,6 +78,10 @@
         e.getIn().setBody("<hello/>");
         e.setTarget(smx.getEndpointRegistry().lookup(ServiceHelper.createMap(Endpoint.NAME, "{uri:foo}bar:ep")));
         channel.sendSync(e);
+        if (e.getError() != null) {
+            throw e.getError();
+        }
+        assertEquals(Status.Done, e.getStatus());
     }
 
 }