Author: ffang
Date: Mon Sep 23 04:11:12 2013
New Revision: 1525501

URL: http://svn.apache.org/r1525501
Log:
[SMX4-1547]use EndpointName + ServiceName + InterfaceName as a Key to 
distinguish a NMR destination

Modified:
    
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
    
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRTransportFactory.java
    
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java

Modified: 
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java?rev=1525501&r1=1525500&r2=1525501&view=diff
==============================================================================
--- 
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
 (original)
+++ 
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
 Mon Sep 23 04:11:12 2013
@@ -56,7 +56,7 @@ import org.apache.servicemix.nmr.api.Ser
 import org.apache.servicemix.nmr.api.Status;
 
 public class NMRDestination extends AbstractDestination implements Endpoint {
-    
+
     private static final Logger LOG = 
LogUtils.getL7dLogger(NMRDestination.class);
     private NMR nmr;
     private Channel channel;
@@ -68,23 +68,23 @@ public class NMRDestination extends Abst
         this.properties = new HashMap<String, Object>();
         String address = info.getAddress();
         if (address != null && address.indexOf(Endpoint.RUN_AS_SUBJECT) >= 0) {
-               String asSubject = 
address.substring(address.indexOf(Endpoint.RUN_AS_SUBJECT) 
-                               + Endpoint.RUN_AS_SUBJECT.length() + 1);
-               this.properties.put(Endpoint.RUN_AS_SUBJECT, asSubject);
+            String asSubject = 
address.substring(address.indexOf(Endpoint.RUN_AS_SUBJECT)
+                                                 + 
Endpoint.RUN_AS_SUBJECT.length() + 1);
+            this.properties.put(Endpoint.RUN_AS_SUBJECT, asSubject);
         }
         if (address != null && address.startsWith("nmr:")) {
-               if (address.indexOf("?") > 0) {
-                       this.properties.put(Endpoint.NAME, address.substring(4, 
address.indexOf("?")));
-               } else {
-                       this.properties.put(Endpoint.NAME, 
address.substring(4));
-               }
+            if (address.indexOf("?") > 0) {
+                this.properties.put(Endpoint.NAME, address.substring(4, 
address.indexOf("?")));
+            } else {
+                this.properties.put(Endpoint.NAME, address.substring(4));
+            }
         } else {
             this.properties.put(Endpoint.NAME, info.getName().toString());
         }
-        
+
         this.properties.put(Endpoint.SERVICE_NAME, 
info.getService().getName().toString());
         this.properties.put(Endpoint.INTERFACE_NAME, 
info.getInterface().getName().toString());
-        
+
         if (address.indexOf("?") > 0) {
             String[] props = address.substring(address.indexOf("?") + 
1).split("&");
             for (String prop : props) {
@@ -103,24 +103,23 @@ public class NMRDestination extends Abst
     public void setChannel(Channel dc) {
         this.channel = dc;
     }
-    
+
     public Channel getChannel() {
         return this.channel;
     }
-    
+
     protected Logger getLogger() {
         return LOG;
     }
-    
+
     /**
      * @param inMessage the incoming message
      * @return the inbuilt backchannel
      */
     protected Conduit getInbuiltBackChannel(Message inMessage) {
-        return new 
BackChannelConduit(EndpointReferenceUtils.getAnonymousEndpointReference(),
-                                      inMessage);
+        return new 
BackChannelConduit(EndpointReferenceUtils.getAnonymousEndpointReference(), 
inMessage);
     }
-    
+
     public void shutdown() {
     }
 
@@ -128,7 +127,7 @@ public class NMRDestination extends Abst
         nmr.getEndpointRegistry().unregister(this, properties);
     }
 
-    public void activate()  {
+    public void activate() {
         nmr.getEndpointRegistry().register(this, properties);
     }
 
@@ -148,18 +147,19 @@ public class NMRDestination extends Abst
 
             MessageImpl inMessage = new MessageImpl();
             inMessage.put(Exchange.class, exchange);
-            
+
             final InputStream in = 
NMRMessageHelper.convertMessageToInputStream(nm.getBody(Source.class));
             inMessage.setContent(InputStream.class, in);
-            //copy attachments
+            // copy attachments
             Collection<Attachment> cxfAttachmentList = new 
ArrayList<Attachment>();
             for (Map.Entry<String, Object> ent : 
nm.getAttachments().entrySet()) {
-                cxfAttachmentList.add(new AttachmentImpl(ent.getKey(), 
(DataHandler) ent.getValue()));
+                cxfAttachmentList.add(new AttachmentImpl(ent.getKey(), 
(DataHandler)ent.getValue()));
             }
             inMessage.setAttachments(cxfAttachmentList);
-            
-            //copy properties and setup the cxf protocol header
-            Map<String, List<String>> protocolHeaders = new TreeMap<String, 
List<String>>(String.CASE_INSENSITIVE_ORDER);
+
+            // copy properties and setup the cxf protocol header
+            Map<String, List<String>> protocolHeaders = new TreeMap<String, 
List<String>>(
+                                                                               
           String.CASE_INSENSITIVE_ORDER);
             inMessage.put(Message.PROTOCOL_HEADERS, protocolHeaders);
 
             for (Map.Entry<String, Object> ent : nm.getHeaders().entrySet()) {
@@ -167,35 +167,36 @@ public class NMRDestination extends Abst
                     inMessage.put(ent.getKey(), ent.getValue());
                 }
                 if (ent.getValue() instanceof String) {
-                   List<String> value = new ArrayList<String>();
-                   value.add((String)ent.getValue());
-                   protocolHeaders.put(ent.getKey(), value);
+                    List<String> value = new ArrayList<String>();
+                    value.add((String)ent.getValue());
+                    protocolHeaders.put(ent.getKey(), value);
                 }
             }
-            
-            //copy securitySubject
+
+            // copy securitySubject
             inMessage.put(NMRTransportFactory.NMR_SECURITY_SUBJECT, 
nm.getSecuritySubject());
-            
+
             inMessage.setDestination(this);
             getMessageObserver().onMessage(inMessage);
 
         } catch (Exception ex) {
-            getLogger().log(Level.SEVERE, new 
org.apache.cxf.common.i18n.Message("ERROR.PREPARE.MESSAGE", 
getLogger()).toString(), ex);
+            getLogger().log(Level.SEVERE,
+                            new 
org.apache.cxf.common.i18n.Message("ERROR.PREPARE.MESSAGE", getLogger())
+                                .toString(), ex);
             throw new ServiceMixException(ex);
         }
     }
 
-
     protected class BackChannelConduit extends AbstractConduit {
-        
+
         protected Message inMessage;
         protected NMRDestination nmrDestination;
-                
+
         BackChannelConduit(EndpointReferenceType ref, Message message) {
             super(ref);
             inMessage = message;
         }
-        
+
         /**
          * Register a message observer for incoming messages.
          * 
@@ -206,8 +207,8 @@ public class NMRDestination extends Abst
         }
 
         /**
-         * Send an outbound message, assumed to contain all the name-value
-         * mappings of the corresponding input message (if any). 
+         * Send an outbound message, assumed to contain all the name-value 
mappings of the corresponding input
+         * message (if any).
          * 
          * @param message the message to be sent.
          */
@@ -215,15 +216,15 @@ public class NMRDestination extends Abst
             // setup the message to be send back
             Channel dc = channel;
             message.put(Exchange.class, inMessage.get(Exchange.class));
-            NMRTransportFactory.removeUnusedInterceptprs(message);    
+            NMRTransportFactory.removeUnusedInterceptprs(message);
             message.setContent(OutputStream.class, new 
NMRDestinationOutputStream(inMessage, message, dc));
-            
-        }        
+
+        }
 
         protected Logger getLogger() {
             return LOG;
         }
-        
+
     }
-    
+
 }

Modified: 
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRTransportFactory.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRTransportFactory.java?rev=1525501&r1=1525500&r2=1525501&view=diff
==============================================================================
--- 
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRTransportFactory.java
 (original)
+++ 
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRTransportFactory.java
 Mon Sep 23 04:11:12 2013
@@ -40,6 +40,7 @@ import org.apache.cxf.transport.Destinat
 import org.apache.cxf.transport.DestinationFactory;
 import org.apache.cxf.transport.DestinationFactoryManager;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.servicemix.nmr.api.Endpoint;
 import org.apache.servicemix.nmr.api.NMR;
 import org.apache.servicemix.nmr.api.ServiceMixException;
 
@@ -116,8 +117,21 @@ public class NMRTransportFactory extends
         if (null != configurer) {
             configurer.configureBean(destination);
         }
+        String address = ei.getAddress();
+        String endpointName = "";
+        if (address != null && address.startsWith("nmr:")) {
+            if (address.indexOf("?") > 0) {
+                endpointName = address.substring(4, address.indexOf("?"));
+            } else {
+                endpointName = address.substring(4);
+            }
+        } else {
+            endpointName = ei.getName().toString();
+        }
+
+        
         try {
-            putDestination(ei.getService().getName().toString()
+            putDestination(endpointName + ei.getService().getName().toString()
                 + ei.getInterface().getName().toString(), destination);
         } catch (ServiceMixException e) {
             throw new IOException(e.getMessage());
@@ -127,7 +141,7 @@ public class NMRTransportFactory extends
     
     public void putDestination(String epName, NMRDestination destination) 
throws ServiceMixException {
         if (destinationMap.containsKey(epName)) {
-            throw new ServiceMixException("JBIDestination for Endpoint "
+            throw new ServiceMixException("NMRDestination for Endpoint "
                                    + epName + " already be created");
         } else {
             destinationMap.put(epName, destination);

Modified: 
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java?rev=1525501&r1=1525500&r2=1525501&view=diff
==============================================================================
--- 
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
 (original)
+++ 
servicemix/smx4/features/trunk/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
 Mon Sep 23 04:11:12 2013
@@ -102,7 +102,7 @@ public class NMRDestinationTest extends 
     @Test
     public void testNMRDestination() throws Exception {
         EndpointInfo ei = new EndpointInfo();
-        ei.setAddress("nmr://dumy");
+        ei.setAddress("nmr:dummy");
         ei.setName(new QName("http://test";, "endpoint"));
         ServiceInfo si = new ServiceInfo();
         si.setName(new QName("http://test";, "service"));
@@ -113,7 +113,7 @@ public class NMRDestinationTest extends 
         nmrTransportFactory.setNmr(nmr);
         NMRDestination destination = (NMRDestination) 
nmrTransportFactory.getDestination(ei);
         assertNotNull(destination);
-        String destName = ei.getService().getName().toString()
+        String destName = "dummy" + ei.getService().getName().toString()
         + ei.getInterface().getName().toString();
         try {
             nmrTransportFactory.putDestination(destName, destination);


Reply via email to