You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ay...@apache.org on 2012/05/15 17:29:58 UTC

svn commit: r1338752 - in /cxf/trunk/rt/ws/rm/src: main/java/org/apache/cxf/ws/rm/RMUtils.java test/java/org/apache/cxf/ws/rm/RMUtilsTest.java

Author: ay
Date: Tue May 15 15:29:58 2012
New Revision: 1338752

URL: http://svn.apache.org/viewvc?rev=1338752&view=rev
Log:
fix for extracting the bus id on osgi for CXF-4270

Modified:
    cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMUtils.java
    cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMUtilsTest.java

Modified: cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMUtils.java?rev=1338752&r1=1338751&r2=1338752&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMUtils.java (original)
+++ cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMUtils.java Tue May 15 15:29:58 2012
@@ -20,6 +20,8 @@
 package org.apache.cxf.ws.rm;
 
 import java.io.OutputStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.management.JMException;
 import javax.management.ObjectName;
@@ -37,7 +39,8 @@ public final class RMUtils {
     private static final org.apache.cxf.ws.rm.v200702.ObjectFactory WSRM_FACTORY;
     private static final org.apache.cxf.ws.rm.v200502.ObjectFactory WSRM200502_FACTORY;
     private static final org.apache.cxf.ws.rm.v200502wsa15.ObjectFactory WSRM200502_WSA200508_FACTORY;
-    private static final AddressingConstants WSA_CONSTANTS; 
+    private static final AddressingConstants WSA_CONSTANTS;
+    private static final Pattern GENERATED_BUS_ID_PATTERN = Pattern.compile(Bus.DEFAULT_BUS_ID + "\\d+$");
     
     static {
         WSRM_FACTORY = new org.apache.cxf.ws.rm.v200702.ObjectFactory();        
@@ -120,12 +123,15 @@ public final class RMUtils {
 
     public static String getEndpointIdentifier(Endpoint endpoint, Bus bus) {
         String busId = null;
-        if (bus != null) {
-            busId = bus.getId();
-        }
-        if (bus == null || busId.startsWith(Bus.DEFAULT_BUS_ID)) {
-            // no bus id or a generated anonymous id needs to be mapped to the default constant 
+        if (bus == null) {
             busId = Bus.DEFAULT_BUS_ID;
+        } else {
+            busId = bus.getId();
+            // bus-ids of form cxfnnn or artifactid-cxfnnn must drop the variable part nnn
+            Matcher m = GENERATED_BUS_ID_PATTERN.matcher(busId);
+            if (m.find()) {
+                busId = busId.substring(0, m.start() + Bus.DEFAULT_BUS_ID.length());
+            }
         }
         return endpoint.getEndpointInfo().getService().getName() + "."
             + endpoint.getEndpointInfo().getName() + "@" + busId;

Modified: cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMUtilsTest.java?rev=1338752&r1=1338751&r2=1338752&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMUtilsTest.java (original)
+++ cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMUtilsTest.java Tue May 15 15:29:58 2012
@@ -63,7 +63,8 @@ public class RMUtilsTest extends Assert 
         QName sqn = new QName("ns1", "service");
         EasyMock.expect(si.getName()).andReturn(sqn);
         control.replay();
-        assertEquals("{ns1}service.{ns2}endpoint@cxf", RMUtils.getEndpointIdentifier(e));
+        assertEquals("{ns1}service.{ns2}endpoint@" + Bus.DEFAULT_BUS_ID, 
+                     RMUtils.getEndpointIdentifier(e));
 
         // a named bus
         control.reset();
@@ -84,7 +85,30 @@ public class RMUtilsTest extends Assert 
         EasyMock.expect(ei.getService()).andReturn(si);
         EasyMock.expect(si.getName()).andReturn(sqn);
         control.replay();
-        assertEquals("{ns1}service.{ns2}endpoint@cxf", 
+        assertEquals("{ns1}service.{ns2}endpoint@" + Bus.DEFAULT_BUS_ID, 
                      RMUtils.getEndpointIdentifier(e, BusFactory.getDefaultBus()));
+
+        // a generated bundle artifact bus
+        control.reset();
+        EasyMock.expect(e.getEndpointInfo()).andReturn(ei).times(2);
+        EasyMock.expect(ei.getName()).andReturn(eqn);
+        EasyMock.expect(ei.getService()).andReturn(si);
+        EasyMock.expect(si.getName()).andReturn(sqn);
+        EasyMock.expect(b.getId()).andReturn("mybus-" + Bus.DEFAULT_BUS_ID + "12345");
+        control.replay();
+        assertEquals("{ns1}service.{ns2}endpoint@mybus-" + Bus.DEFAULT_BUS_ID, 
+                     RMUtils.getEndpointIdentifier(e, b));
+
+        // look like a generated bundle artifact bus but not
+        control.reset();
+        EasyMock.expect(e.getEndpointInfo()).andReturn(ei).times(2);
+        EasyMock.expect(ei.getName()).andReturn(eqn);
+        EasyMock.expect(ei.getService()).andReturn(si);
+        EasyMock.expect(si.getName()).andReturn(sqn);
+        EasyMock.expect(b.getId()).andReturn("mybus." + Bus.DEFAULT_BUS_ID + ".foo");
+        control.replay();
+        assertEquals("{ns1}service.{ns2}endpoint@mybus." + Bus.DEFAULT_BUS_ID + ".foo", 
+                     RMUtils.getEndpointIdentifier(e, b));
+        
     } 
 }