[SMX4-1547]use EndpointName + ServiceName + InterfaceName as a Key to distinguish a NMR destination
git-svn-id: https://svn.apache.org/repos/asf/servicemix/smx4/features/trunk@1525501 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java b/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
index 4919907..805a5b0 100644
--- a/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
+++ b/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRDestination.java
@@ -56,7 +56,7 @@
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 @@
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 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 @@
nmr.getEndpointRegistry().unregister(this, properties);
}
- public void activate() {
+ public void activate() {
nmr.getEndpointRegistry().register(this, properties);
}
@@ -148,18 +147,19 @@
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 @@
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 @@
}
/**
- * 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 @@
// 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;
}
-
+
}
-
+
}
diff --git a/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRTransportFactory.java b/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRTransportFactory.java
index 7a5c9d3..b67b617 100644
--- a/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRTransportFactory.java
+++ b/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRTransportFactory.java
@@ -40,6 +40,7 @@
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 @@
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 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);
diff --git a/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java b/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
index bb34546..d1fd230 100644
--- a/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
+++ b/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRDestinationTest.java
@@ -102,7 +102,7 @@
@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 @@
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);