Author: mschaaf
Date: Tue Apr 13 13:42:25 2010
New Revision: 933601
URL: http://svn.apache.org/viewvc?rev=933601&view=rev
Log:
changed the discovery format to the standardized XML format used by the local
discovery which has full support for all required data types
Modified:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/pom.xml
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerImpl.java
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java
Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/pom.xml?rev=933601&r1=933600&r2=933601&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/pom.xml (original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/pom.xml Tue Apr 13
13:42:25 2010
@@ -61,6 +61,13 @@
<artifactId>cxf-dosgi-ri-discovery-distributed-zookeeper-wrapper</artifactId>
<version>${pom.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.cxf.dosgi</groupId>
+ <artifactId>cxf-dosgi-ri-discovery-local</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
<!-- This is a zookeeper dependency that we apparently have to list
here -->
<dependency>
@@ -96,6 +103,7 @@
<Bundle-Activator>org.apache.cxf.dosgi.discovery.zookeeper.Activator</Bundle-Activator>
<Import-Package>
org.apache.zookeeper.*;version="[3.0.0,4.0.0)",
+ org.apache.cxf.dosgi.discovery.local.*,
org.osgi.framework;version="[1.4.0,2.0.0)",
org.osgi.service.remoteserviceadmin;version="${remote.service.admin.interfaces.version}",
org.osgi.util.tracker;version="[1.3.0,2.0.0)",
Modified:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerImpl.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerImpl.java?rev=933601&r1=933600&r2=933601&view=diff
==============================================================================
---
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerImpl.java
(original)
+++
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/EndpointListenerImpl.java
Tue Apr 13 13:42:25 2010
@@ -18,34 +18,24 @@
*/
package org.apache.cxf.dosgi.discovery.zookeeper;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Hashtable;
import java.util.List;
-import java.util.Map;
-import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import org.apache.cxf.dosgi.discovery.local.LocalDiscoveryUtils;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooDefs.Ids;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
import org.osgi.service.remoteserviceadmin.EndpointListener;
-import org.osgi.service.remoteserviceadmin.RemoteConstants;
public class EndpointListenerImpl implements EndpointListener {
@@ -157,39 +147,8 @@ public class EndpointListenerImpl implem
}
static byte[] getData(EndpointDescription sr) throws IOException {
- Properties p = new Properties();
-
- Map<String, Object> serviceProps = (Map<String,
Object>)sr.getProperties();
- if (serviceProps != null) {
- for (Map.Entry<String, Object> prop : serviceProps.entrySet()) {
- Object val = prop.getValue();
- if (val == null) {
- // null values are not allowed
- continue;
- }
-
- if (val instanceof String[]) {
- String[] sa = (String[])val;
- val = Util.convertStringArrayToString(sa);
- }
-
- if (val instanceof Collection) {
- Collection sc = (Collection)val;
- try{
- String[] sa = (String[])sc.toArray();
- val = Util.convertStringArrayToString(sa);
- }catch (ClassCastException e) {
- e.printStackTrace();
- }
- }
-
- p.setProperty(prop.getKey(), val.toString());
- }
- }
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- p.store(baos, "");
- return baos.toByteArray();
+ String s =
LocalDiscoveryUtils.getEndpointDescriptionXML(sr.getProperties());
+ return s.getBytes();
}
static String getKey(String endpoint) throws UnknownHostException,
URISyntaxException {
Modified:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java?rev=933601&r1=933600&r2=933601&view=diff
==============================================================================
---
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
(original)
+++
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
Tue Apr 13 13:42:25 2010
@@ -26,7 +26,13 @@ import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.cxf.dosgi.discovery.local.LocalDiscovery;
+import org.apache.cxf.dosgi.discovery.local.LocalDiscoveryUtils;
import org.apache.zookeeper.ZooKeeper;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
@@ -68,56 +74,19 @@ public class InterfaceDataMonitorListene
byte[] data = zookeeper.getData(znode + '/' + child, false,
null);
LOG.info("Child: " + znode + "/" + child);
- Properties p = new Properties();
- p.load(new ByteArrayInputStream(data));
-
- Map<String, Object> m = new HashMap<String, Object>();
- for (Map.Entry<Object, Object> entry : p.entrySet()) {
- Object value = entry.getValue();
-
- if (value instanceof String) {
- String s = (String)value;
- if(Util.isStringArray(s)){
- value = Util.convertStringToStringArray(s);
- }
- }
-
- m.put(entry.getKey().toString(),value);
- }
-
-// // Put in some reasonable defaults, if not specified
-// if (!m.containsKey("service.exported.configs")) {
-// m.put("service.exported.configs", "org.apache.cxf.ws");
-// }
-// if
(Util.getMultiValueProperty(m.get("service.exported.configs")).contains("org.apache.cxf.ws")
&&
-// !m.containsKey("org.apache.cxf.ws.address")) {
-// m.put("org.apache.cxf.ws.address",
m.get(ServicePublication.ENDPOINT_LOCATION));
-// }
-
-
-
- if(m.get(Constants.OBJECTCLASS) instanceof String){
- String s = (String)m.get(Constants.OBJECTCLASS);
- String[] a = new String[1];
- a[0] = s;
- m.put(Constants.OBJECTCLASS,a);
- LOG.fine("OBJECTCLASS: "+s);
- }
-
-
- // the Endpoint.id must be a Long and can't be a string ....
- if(m.get(RemoteConstants.ENDPOINT_SERVICE_ID) instanceof
String){
- String s =
(String)m.get(RemoteConstants.ENDPOINT_SERVICE_ID);
- Long l = Long.parseLong(s);
- m.put(RemoteConstants.ENDPOINT_SERVICE_ID, l);
+ List<Element> elements = LocalDiscoveryUtils.getElements(new
ByteArrayInputStream(data));
+ EndpointDescription epd = null;
+ if(elements.size()>0)
+ epd =
LocalDiscoveryUtils.getEndpointDescription(elements.get(0));
+ else{
+ LOG.warning("No Discovery information found for node:
"+znode + "/" + child);
+ continue;
}
+
+ LOG.finest("Properties: "+epd.getProperties());
-
- LOG.finest("Properties: "+m);
-
- newNodes.put(child, m);
+ newNodes.put(child, epd.getProperties());
Map<String, Object> prevVal = prevNodes.remove(child);
- EndpointDescription epd = new EndpointDescription(m);
if (prevVal == null) {
// This guy is new
@@ -131,7 +100,7 @@ public class InterfaceDataMonitorListene
epl.endpointAdded(epd, scope);
}
}
- } else if (!prevVal.equals(m)){
+ } else if (!prevVal.equals(epd.getProperties())){
// There's been a modification
// ServiceEndpointDescriptionImpl sed = new
ServiceEndpointDescriptionImpl(Collections.singletonList(interFace), m);
// DiscoveredServiceNotification dsn = new
DiscoveredServiceNotificationImpl(Collections.emptyList(),
Modified:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java?rev=933601&r1=933600&r2=933601&view=diff
==============================================================================
---
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java
(original)
+++
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Util.java
Tue Apr 13 13:42:25 2010
@@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Collections;
public class Util {
- private static final String DISCOVERY_STRINGARRAY_ID =
"DISCOVERY_STRINGARRAY_TO_STRING;";
static final String PATH_PREFIX = "/osgi/service_registry/";
@SuppressWarnings("unchecked")
@@ -43,24 +42,4 @@ public class Util {
return PATH_PREFIX + name.replace('.', '/');
}
- public static String convertStringArrayToString(String[] intents) {
- String ret = DISCOVERY_STRINGARRAY_ID;
- for (String s : intents) {
- ret += s + ";";
- }
- return ret;
- }
-
- public static String[] convertStringToStringArray(String intents) {
- if (intents == null)
- return null;
- intents = intents.substring(DISCOVERY_STRINGARRAY_ID.length());
-
- String[] arr = intents.split(";");
- return arr;
- }
-
- public static boolean isStringArray(String in) {
- return in != null && in.startsWith(DISCOVERY_STRINGARRAY_ID);
- }
}
Modified:
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java?rev=933601&r1=933600&r2=933601&view=diff
==============================================================================
---
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java
(original)
+++
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/LocalDiscoveryUtils.java
Tue Apr 13 13:42:25 2010
@@ -18,6 +18,8 @@
*/
package org.apache.cxf.dosgi.discovery.local;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.net.URL;
@@ -37,6 +39,7 @@ import java.util.logging.Logger;
import org.jdom.Document;
import org.jdom.Element;
+import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
@@ -94,7 +97,7 @@ public final class LocalDiscoveryUtils {
}
@SuppressWarnings("unchecked")
- private static EndpointDescription getEndpointDescription(Element
endpointDescriptionElement) {
+ public static EndpointDescription getEndpointDescription(Element
endpointDescriptionElement) {
Map<String, Object> map = new HashMap<String, Object>();
List<Element> properties =
endpointDescriptionElement.getChildren(PROPERTY_ELEMENT,
@@ -370,14 +373,7 @@ public final class LocalDiscoveryUtils {
while (urls.hasMoreElements()) {
URL resourceURL = (URL) urls.nextElement();
try {
- Document d = new SAXBuilder().build(resourceURL.openStream());
- if
(d.getRootElement().getNamespaceURI().equals(REMOTE_SERVICES_ADMIN_NS)) {
-
elements.addAll(d.getRootElement().getChildren(ENDPOINT_DESCRIPTION_ELEMENT,
- Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS)));
- }
-
- Namespace nsOld = Namespace.getNamespace(REMOTE_SERVICES_NS);
-
elements.addAll(d.getRootElement().getChildren(SERVICE_DESCRIPTION_ELEMENT,
nsOld));
+ elements.addAll(getElements(resourceURL.openStream()));
} catch (Exception ex) {
LOG.log(Level.WARNING, "Problem parsing: " + resourceURL, ex);
}
@@ -562,5 +558,21 @@ public final class LocalDiscoveryUtils {
dataType = dataType.substring("java.lang.".length());
}
propEl.setAttribute("value-type", dataType);
+ }
+
+ public static List<Element> getElements(InputStream in) throws
JDOMException, IOException {
+
+ List<Element> elements = new ArrayList<Element>();
+
+ Document d = new SAXBuilder().build(in);
+ if
(d.getRootElement().getNamespaceURI().equals(REMOTE_SERVICES_ADMIN_NS)) {
+
elements.addAll(d.getRootElement().getChildren(ENDPOINT_DESCRIPTION_ELEMENT,
+ Namespace.getNamespace(REMOTE_SERVICES_ADMIN_NS)));
+ }
+
+ Namespace nsOld = Namespace.getNamespace(REMOTE_SERVICES_NS);
+
elements.addAll(d.getRootElement().getChildren(SERVICE_DESCRIPTION_ELEMENT,
nsOld));
+
+ return elements;
}
}