cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1391591 - in /cxf/trunk/services/ws-discovery: ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/ ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/ ws-discovery-service/src/main/resources/OSGI-INF/blueprint/
Date Fri, 28 Sep 2012 18:43:40 GMT
Author: dkulp
Date: Fri Sep 28 18:43:39 2012
New Revision: 1391591

URL: http://svn.apache.org/viewvc?rev=1391591&view=rev
Log:
Add some settings to control how the ws-discovery service is registered in OSGi

Modified:
    cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
    cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
    cxf/trunk/services/ws-discovery/ws-discovery-service/src/main/resources/OSGI-INF/blueprint/cxf-wsdiscovery.xml

Modified: cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java?rev=1391591&r1=1391590&r2=1391591&view=diff
==============================================================================
--- cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
(original)
+++ cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/WSDiscoveryClient.java
Fri Sep 28 18:43:39 2012
@@ -21,6 +21,9 @@ package org.apache.cxf.ws.discovery;
 
 import java.io.Closeable;
 import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
@@ -71,7 +74,6 @@ public class WSDiscoveryClient implement
     public static final QName SERVICE_QNAME 
         = new QName("http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01", "DiscoveryProxy");
     
-    
     String address = "soap.udp://239.255.255.250:3702";
     boolean adHoc = true;
     AtomicInteger msgId = new AtomicInteger(1);
@@ -88,13 +90,18 @@ public class WSDiscoveryClient implement
         this.bus = bus;
     }
     public WSDiscoveryClient(String address) {
-        this.address = address;
-        adHoc = false;
+        resetDispatch(address);
     }
     
     public String getAddress() {
         return address;
     }
+    public void setAddress(String a) {
+        if (!address.equals(a)) {
+            resetDispatch(a);
+        }
+    }
+    
     
     private synchronized JAXBContext getJAXBContext() {
         if (jaxbContext == null) {
@@ -123,6 +130,20 @@ public class WSDiscoveryClient implement
         service = null;
         dispatch = null;
         adHoc = false;
+        try {
+            URI uri = new URI(address);
+            if (StringUtils.isEmpty(uri.getHost())) {
+                adHoc = true;
+            } else {
+                InetSocketAddress isa = null;
+                isa = new InetSocketAddress(uri.getHost(), uri.getPort());
+                if (isa.getAddress().isMulticastAddress()) {
+                    adHoc = true;
+                }
+            }        
+        } catch (URISyntaxException e) {
+            //ignore
+        }
     }
     
     private synchronized Dispatch<Object> getDispatchInternal(boolean addSeq) {
@@ -215,9 +236,14 @@ public class WSDiscoveryClient implement
         unregister(bt);
     }
     
+    public List<EndpointReference> probe() {
+        return probe((QName)null);
+    }
     public List<EndpointReference> probe(QName type) {
         ProbeType p = new ProbeType();
-        p.getTypes().add(type);
+        if (type != null) {
+            p.getTypes().add(type);
+        }
         ProbeMatchesType pmt = probe(p, 1000);
         List<EndpointReference> er = new ArrayList<EndpointReference>();
         for (ProbeMatchType pm : pmt.getProbeMatch()) {
@@ -303,8 +329,7 @@ public class WSDiscoveryClient implement
             xAddrs.add(add);
         }
     }
-
-    
-
-    
+    public boolean isAdHoc() {
+        return adHoc;
+    }
 }

Modified: cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java?rev=1391591&r1=1391590&r2=1391591&view=diff
==============================================================================
--- cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
(original)
+++ cxf/trunk/services/ws-discovery/ws-discovery-api/src/main/java/org/apache/cxf/ws/discovery/internal/WSDiscoveryServiceImpl.java
Fri Sep 28 18:43:39 2012
@@ -77,7 +77,16 @@ public class WSDiscoveryServiceImpl impl
         bus = BusFactory.newInstance().createBus();
         client = new WSDiscoveryClient();
     }
+    public WSDiscoveryServiceImpl(Bus b, Map<String, Object> props) {
+        bus = b;
+        client = new WSDiscoveryClient();
+        update(props);
+    }
     
+    public final void update(Map<String, Object> props) {
+        String address = (String)props.get("org.apache.cxf.service.ws-discovery.address");
+        client.setAddress(address);
+    }
     public WSDiscoveryClient getClient() {
         return client;
     }
@@ -163,13 +172,20 @@ public class WSDiscoveryServiceImpl impl
     
     
     public synchronized void startup() {
-        if (!started) {
-            udpEndpoint = Endpoint.create(new WSDiscoveryProvider());
-            Map<String, Object> props = new HashMap<String, Object>();
-            props.put("jaxws.provider.interpretNullAsOneway", "true");
-            udpEndpoint.setProperties(props);
-            udpEndpoint.publish("soap.udp://239.255.255.250:3702");
-            started = true;
+        if (!started && client.isAdHoc()) {
+            Bus b = BusFactory.getAndSetThreadDefaultBus(bus);
+            try {
+                udpEndpoint = Endpoint.create(new WSDiscoveryProvider());
+                Map<String, Object> props = new HashMap<String, Object>();
+                props.put("jaxws.provider.interpretNullAsOneway", "true");
+                udpEndpoint.setProperties(props);
+                udpEndpoint.publish("soap.udp://239.255.255.250:3702");
+                started = true;
+            } finally {
+                if (b != bus) {
+                    BusFactory.setThreadDefaultBus(b);
+                }
+            }
         }
     }
     

Modified: cxf/trunk/services/ws-discovery/ws-discovery-service/src/main/resources/OSGI-INF/blueprint/cxf-wsdiscovery.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/services/ws-discovery/ws-discovery-service/src/main/resources/OSGI-INF/blueprint/cxf-wsdiscovery.xml?rev=1391591&r1=1391590&r2=1391591&view=diff
==============================================================================
--- cxf/trunk/services/ws-discovery/ws-discovery-service/src/main/resources/OSGI-INF/blueprint/cxf-wsdiscovery.xml
(original)
+++ cxf/trunk/services/ws-discovery/ws-discovery-service/src/main/resources/OSGI-INF/blueprint/cxf-wsdiscovery.xml
Fri Sep 28 18:43:39 2012
@@ -21,11 +21,26 @@
            xmlns:cxf="http://cxf.apache.org/blueprint/core"
            xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
 
+  	<cm:property-placeholder persistent-id="org.apache.cxf.service.ws-discovery" id="cxfWSDiscoveryProperties">
+    	<cm:default-properties>
+      		<cm:property name="org.apache.cxf.service.ws-discovery.address" value="soap.udp://239.255.255.250:3702"/>
+        </cm:default-properties>
+    </cm:property-placeholder>
+
     <cxf:bus name="cxf"/>
 
     <!-- Single discovery service to avoid lots of UDP packets, particularly on probes
-->
     <bean id="discoveryService" class="org.apache.cxf.ws.discovery.internal.WSDiscoveryServiceImpl">
         <argument ref="cxf" />
+        <argument>
+           <map>
+               <entry key="org.apache.cxf.service.ws-discovery.address" 
+                      value="${org.apache.cxf.service.ws-discovery.address}"/>
+           </map>
+        </argument>
+         
+        <cm:managed-properties persistent-id="org.apache.cxf.service.ws-discovery"
+                        update-strategy="component-managed" update-method="update"/> 
     </bean>
 
     <service ref="discoveryService" interface="org.apache.cxf.ws.discovery.WSDiscoveryService"
/>



Mime
View raw message