You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2010/03/01 15:06:35 UTC
svn commit: r917537 [1/3] - in /cxf/dosgi/trunk:
discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers...
Author: davidb
Date: Mon Mar 1 14:06:34 2010
New Revision: 917537
URL: http://svn.apache.org/viewvc?rev=917537&view=rev
Log:
Applying DOSGI-13 handlers_and_tck.patch on behalf or Marc Schaaf.
This patch contains the following:
* TCK: DSW: import / export calls now return empty lists instead of null
* TCK: DSW: Fixed some issues with the handling of intents
* Changed the testServiceExport() test case of the Topology manager from a thread.sleep to a lock based mechanism
* DSW: Re-enabled most of the old handlers and their corresponding test cases. However most of them are not yet complete (impl + tests).
* Did some minor refactoring and some cleanup
* Made a minor addition to the Zookeeper discovery to better support String[] and List<String> however a more decent format is necessary see DOSGI-61
* DSW: Fixed an issue with the unimport of a service that was referenced more than once
* DSW: Cleaned some redundant code from shutdown procedure
Modified:
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/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/Utils.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ExportServiceTest.java
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=917537&r1=917536&r2=917537&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 Mon Mar 1 14:06:34 2010
@@ -53,7 +53,7 @@
private ZooKeeperDiscovery discovery;
private BundleContext bctx;
-
+
private List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
private boolean closed = false;
@@ -139,8 +139,6 @@
}
}
-
-
private static void ensurePath(String path, ZooKeeper zk) throws KeeperException, InterruptedException {
StringBuilder current = new StringBuilder();
@@ -169,20 +167,26 @@
// 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());
}
}
- {
- String[] oc = (String[])serviceProps.get(Constants.OBJECTCLASS);
- if (oc.length > 0)
- p.put(Constants.OBJECTCLASS, oc[0]);
- }
-
- // Marc: FIXME: What is/was ths good for ??!?!?
- // copyProperty(ServicePublication.ENDPOINT_SERVICE_ID, sr, p, host);
- // copyProperty(ServicePublication.ENDPOINT_LOCATION, sr, p, host);
-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
p.store(baos, "");
return baos.toByteArray();
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=917537&r1=917536&r2=917537&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 Mon Mar 1 14:06:34 2010
@@ -72,8 +72,17 @@
p.load(new ByteArrayInputStream(data));
Map<String, Object> m = new HashMap<String, Object>();
- for (Map.Entry<Object, Object> entry : p.entrySet()) {
- m.put(entry.getKey().toString(), entry.getValue());
+ 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
@@ -129,7 +138,7 @@
// Collections.singleton(interFace), DiscoveredServiceNotification.MODIFIED, sed);
// discoveredServiceTracker.serviceChanged(dsn);
-
+ // TODO
}
}
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=917537&r1=917536&r2=917537&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 Mon Mar 1 14:06:34 2010
@@ -1,21 +1,21 @@
/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.cxf.dosgi.discovery.zookeeper;
import java.util.Arrays;
@@ -23,22 +23,44 @@
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")
static Collection<String> getMultiValueProperty(Object property) {
if (property instanceof Collection) {
- return (Collection<String>) property;
- } else if (property instanceof String []) {
- return Arrays.asList((String []) property);
+ return (Collection<String>)property;
+ } else if (property instanceof String[]) {
+ return Arrays.asList((String[])property);
} else if (property == null) {
return Collections.emptySet();
} else {
return Collections.singleton(property.toString());
}
}
-
+
static String getZooKeeperPath(String name) {
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/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java Mon Mar 1 14:06:34 2010
@@ -111,22 +111,6 @@
rsaFactoryReg.unregister();
decoratorReg.unregister();
- for (Object o : rsaFactory.getRsaCore().getExportedServices()) {
- if (o instanceof ExportRegistrationImpl) {
- LOG.fine("closing Export");
- ExportRegistrationImpl er = (ExportRegistrationImpl)o;
- er.close();
- }
- }
-
- for (Object o : rsaFactory.getRsaCore().getImportedEndpoints()) {
- if (o instanceof ImportRegistrationImpl) {
- LOG.fine("closing Import");
- ImportRegistrationImpl er = (ImportRegistrationImpl)o;
- er.close();
- }
- }
-
// shutdown the CXF Bus -> Causes also the shutdown of the embedded HTTP server
Bus b = BusFactory.getDefaultBus();
if (b != null) {
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java Mon Mar 1 14:06:34 2010
@@ -54,6 +54,8 @@
public final class OsgiUtils {
+ // TODO: cleanup old code fragments !!!
+
private static final Logger LOG = Logger.getLogger(OsgiUtils.class.getName());
private static final String REMOTE_SERVICES_HEADER_NAME = "Remote-Service";
@@ -66,16 +68,16 @@
private static final String SERVICE_DESCRIPTION_ELEMENT = "service-description";
- private static final String PROVIDE_INTERFACE_ELEMENT = "provide";
- private static final String PROVIDE_INTERFACE_NAME_ATTRIBUTE = "interface";
+// private static final String PROVIDE_INTERFACE_ELEMENT = "provide";
+// private static final String PROVIDE_INTERFACE_NAME_ATTRIBUTE = "interface";
- private static final String PROPERTY_ELEMENT = "property";
- private static final String PROPERTY_NAME_ATTRIBUTE = "name";
- private static final String PROPERTY_VALUE_ATTRIBUTE = "value";
- private static final String PROPERTY_INTERFACE_ATTRIBUTE = "interface";
+// private static final String PROPERTY_ELEMENT = "property";
+// private static final String PROPERTY_NAME_ATTRIBUTE = "name";
+// private static final String PROPERTY_VALUE_ATTRIBUTE = "value";
+// private static final String PROPERTY_INTERFACE_ATTRIBUTE = "interface";
- private static final String INTERFACE_WILDCARD = "*";
- private static final String INTERFACE_SEPARATOR = ":";
+// private static final String INTERFACE_WILDCARD = "*";
+// private static final String INTERFACE_SEPARATOR = ":";
private OsgiUtils() {
}
@@ -163,19 +165,19 @@
// return list;
// }
- private static Map<String, Object> excludeProperty(Map properties, String... excludes) {
- Collection<String> exList = Arrays.asList(excludes);
-
- Map<String, Object> pruned = new HashMap<String, Object>();
- for (Object key : properties.keySet()) {
- if (exList.contains(key)) {
- // exclude
- } else {
- pruned.put((String)key, properties.get(key));
- }
- }
- return pruned;
- }
+// private static Map<String, Object> excludeProperty(Map properties, String... excludes) {
+// Collection<String> exList = Arrays.asList(excludes);
+//
+// Map<String, Object> pruned = new HashMap<String, Object>();
+// for (Object key : properties.keySet()) {
+// if (exList.contains(key)) {
+// // exclude
+// } else {
+// pruned.put((String)key, properties.get(key));
+// }
+// }
+// return pruned;
+// }
@SuppressWarnings("unchecked")
public static List<Element> getAllDescriptionElements(Bundle b) {
@@ -209,47 +211,47 @@
return elements;
}
- private static void setAdditionalProperties(ServiceReference sref, Map<String, Object> props) {
- BundleContext bc = sref.getBundle().getBundleContext();
- ServiceReference[] refs;
- try {
- refs = bc.getServiceReferences(ServiceDecorator.class.getName(), null);
- } catch (InvalidSyntaxException e) {
- // should never happen, filter is null
- return;
- }
- if (refs == null) {
- return;
- }
-
- for (ServiceReference ref : refs) {
- Object svc = bc.getService(ref);
- if (svc instanceof ServiceDecorator) {
- ((ServiceDecorator)svc).decorate(sref, props);
- }
- }
- }
+// private static void setAdditionalProperties(ServiceReference sref, Map<String, Object> props) {
+// BundleContext bc = sref.getBundle().getBundleContext();
+// ServiceReference[] refs;
+// try {
+// refs = bc.getServiceReferences(ServiceDecorator.class.getName(), null);
+// } catch (InvalidSyntaxException e) {
+// // should never happen, filter is null
+// return;
+// }
+// if (refs == null) {
+// return;
+// }
+//
+// for (ServiceReference ref : refs) {
+// Object svc = bc.getService(ref);
+// if (svc instanceof ServiceDecorator) {
+// ((ServiceDecorator)svc).decorate(sref, props);
+// }
+// }
+// }
- private static boolean serviceNamesMatch(String[] names, List<String> iNames, boolean matchAllNames) {
- if (names == null || names.length == 0) {
- return false;
- }
- if (matchAllNames) {
- for (String name : names) {
- if (!iNames.contains(name)) {
- return false;
- }
- }
- return true;
- } else {
- for (String name : names) {
- if (iNames.contains(name)) {
- return true;
- }
- }
- return false;
- }
- }
+// private static boolean serviceNamesMatch(String[] names, List<String> iNames, boolean matchAllNames) {
+// if (names == null || names.length == 0) {
+// return false;
+// }
+// if (matchAllNames) {
+// for (String name : names) {
+// if (!iNames.contains(name)) {
+// return false;
+// }
+// }
+// return true;
+// } else {
+// for (String name : names) {
+// if (iNames.contains(name)) {
+// return true;
+// }
+// }
+// return false;
+// }
+// }
/*
* // TODO : consider creating a new List rather than modifyiing the existing one public static void
@@ -319,41 +321,41 @@
return sb.toString();
}
- private static Map<String, Object> getProperties(List<Element> elements) {
- Map<String, Object> props = new HashMap<String, Object>();
- addProperties(props, elements);
- return props;
- }
-
- private static void addProperties(Map<String, Object> props, List<Element> elements) {
- for (Element p : elements) {
- String key = p.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
- String value = p.getAttributeValue(PROPERTY_VALUE_ATTRIBUTE);
- if (value == null) {
- value = p.getTextTrim();
- }
-
- String iface = p.getAttributeValue(PROPERTY_INTERFACE_ATTRIBUTE);
- if (key != null) {
- props.put(iface == null || iface.length() == 0 ? key : key + INTERFACE_SEPARATOR + iface,
- value);
- }
- }
- }
-
- private static List<String> getProvidedInterfaces(List<Element> elements) {
-
- List<String> names = new ArrayList<String>();
+// private static Map<String, Object> getProperties(List<Element> elements) {
+// Map<String, Object> props = new HashMap<String, Object>();
+// addProperties(props, elements);
+// return props;
+// }
- for (Element p : elements) {
- String name = p.getAttributeValue(PROVIDE_INTERFACE_NAME_ATTRIBUTE);
- if (name != null) {
- names.add(name);
- }
- }
+// private static void addProperties(Map<String, Object> props, List<Element> elements) {
+// for (Element p : elements) {
+// String key = p.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
+// String value = p.getAttributeValue(PROPERTY_VALUE_ATTRIBUTE);
+// if (value == null) {
+// value = p.getTextTrim();
+// }
+//
+// String iface = p.getAttributeValue(PROPERTY_INTERFACE_ATTRIBUTE);
+// if (key != null) {
+// props.put(iface == null || iface.length() == 0 ? key : key + INTERFACE_SEPARATOR + iface,
+// value);
+// }
+// }
+// }
- return names;
- }
+// private static List<String> getProvidedInterfaces(List<Element> elements) {
+//
+// List<String> names = new ArrayList<String>();
+//
+// for (Element p : elements) {
+// String name = p.getAttributeValue(PROVIDE_INTERFACE_NAME_ATTRIBUTE);
+// if (name != null) {
+// names.add(name);
+// }
+// }
+//
+// return names;
+// }
@SuppressWarnings("unchecked")
public static <T> OsgiService<T> getOsgiService(BundleContext bc, Class<T> serviceClass) {
@@ -442,8 +444,8 @@
// TODO : move these property helpers into PropertyUtils ?
- public static boolean getBooleanProperty(EndpointDescription sd, String name) {
- Object value = sd.getProperties().get(name);
+ public static boolean getBooleanProperty(Map sd, String name) {
+ Object value = sd.get(name);
return toBoolean(value);
}
@@ -543,30 +545,30 @@
// return publishableInterfaces;
// }
- private static String[] tokenize(String str, String delim) {
- StringTokenizer tokenizer = new StringTokenizer(str, delim);
- String[] tokens = new String[tokenizer.countTokens()];
- for (int i = 0; tokenizer.hasMoreTokens(); i++) {
- tokens[i] = tokenizer.nextToken();
- }
- return tokens;
- }
-
- private static boolean contains(String[] list, String member) {
- boolean found = false;
- for (int i = 0; i < list.length && !found; i++) {
- found = member.equals(list[i]);
- }
- return found;
- }
+// private static String[] tokenize(String str, String delim) {
+// StringTokenizer tokenizer = new StringTokenizer(str, delim);
+// String[] tokens = new String[tokenizer.countTokens()];
+// for (int i = 0; tokenizer.hasMoreTokens(); i++) {
+// tokens[i] = tokenizer.nextToken();
+// }
+// return tokens;
+// }
+//
+// private static boolean contains(String[] list, String member) {
+// boolean found = false;
+// for (int i = 0; i < list.length && !found; i++) {
+// found = member.equals(list[i]);
+// }
+// return found;
+// }
/**
- * Tries to retrive the version of iClass via the PackageAdmin
+ * Tries to retrieve the version of iClass via the PackageAdmin
*
* @param iClass - The interface for which the version should be found
* @param bc - any valid BundleContext
* @return the version of the interface or "0.0.0" if no version information could be found or an error
- * occured duriung the retrival
+ * occurred during the retrieval
*/
public static String getVersion(Class<?> iClass, BundleContext bc) {
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java Mon Mar 1 14:06:34 2010
@@ -1,55 +1,61 @@
/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.cxf.dosgi.dsw.handlers;
import java.lang.reflect.Proxy;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
import org.apache.cxf.dosgi.dsw.Constants;
import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.apache.cxf.dosgi.dsw.service.Utils;
import org.osgi.framework.BundleContext;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
public abstract class AbstractConfigurationHandler implements ConfigurationTypeHandler {
-
+
+ private static final Logger LOG = Logger.getLogger(AbstractConfigurationHandler.class.getName());
+
final Map<String, Object> handlerProps;
protected BundleContext bundleContext;
-
- protected AbstractConfigurationHandler(BundleContext dswBC,
- Map<String, Object> handlerProps) {
- this.bundleContext = dswBC;
+
+ protected AbstractConfigurationHandler(BundleContext dswBC, Map<String, Object> handlerProps) {
+ this.bundleContext = dswBC;
this.handlerProps = handlerProps;
}
-
- protected String getDefaultAddress(Class<?> type) {
+
+ protected String getDefaultAddress(Class<?> type) {
Object h = handlerProps.get(Constants.DEFAULT_HOST_CONFIG);
if (h == null) {
h = "localhost";
}
String host = h.toString();
-
+
Object p = handlerProps.get(Constants.DEFAULT_PORT_CONFIG);
if (p == null) {
p = "9000";
}
String port = p.toString();
-
- return getAddress("http", host, port, "/" + type.getName().replace('.', '/'));
+
+ return getAddress("http", host, port, "/" + type.getName().replace('.', '/'));
}
protected String getAddress(String scheme, String host, String port, String context) {
@@ -57,25 +63,93 @@
buf.append(scheme).append("://").append(host).append(':').append(port).append(context);
return buf.toString();
}
-
+
protected boolean useMasterMap() {
-
+
Object value = handlerProps.get(Constants.USE_MASTER_MAP);
if (value == null) {
return true;
}
-
- return OsgiUtils.toBoolean(value);
+
+ return OsgiUtils.toBoolean(value);
}
-
-
+
protected Object getProxy(Object serviceProxy, Class<?> iType) {
- return Proxy.newProxyInstance(iType.getClassLoader(),
- new Class[] {iType},
- new ServiceInvocationHandler(serviceProxy, iType));
- }
-
- protected BundleContext getBundleContext(){
+ return Proxy.newProxyInstance(iType.getClassLoader(), new Class[] {
+ iType
+ }, new ServiceInvocationHandler(serviceProxy, iType));
+ }
+
+ protected BundleContext getBundleContext() {
return bundleContext;
}
+
+ protected Map<String, Object> createEndpointProps(Map sd, Class<?> iClass, String[] importedConfigs,
+ String address, String[] intents) {
+ Map<String, Object> props = new HashMap<String, Object>();
+
+ copyEndpointProperties(sd, props);
+
+ String[] sa = new String[1];
+ sa[0] = iClass.getName();
+
+ props.put(org.osgi.framework.Constants.OBJECTCLASS, sa);
+ // endpointProps.put(RemoteConstants.SERVICE_IMPORTED, "someValue;-)"); // should be done when the
+ // service is imported
+ // endpointProps.put(RemoteConstants.SERVICE_REMOTE_ID, "TODO");
+
+ // FIXME: This key is not defined in the spec but is required by the EndpointDescription !!!!!
+ props.put(RemoteConstants.ENDPOINT_SERVICE_ID, 123L);
+
+ props.put(RemoteConstants.ENDPOINT_FRAMEWORK_UUID, OsgiUtils.getUUID(getBundleContext()));
+ props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, importedConfigs);
+ props.put(RemoteConstants.ENDPOINT_PACKAGE_VERSION_ + sa[0], OsgiUtils.getVersion(iClass,
+ getBundleContext()));
+
+ for (String configurationType : importedConfigs) {
+ if(Constants.WS_CONFIG_TYPE.equals(configurationType))
+ props.put(Constants.WS_ADDRESS_PROPERTY, address);
+ else if(Constants.RS_CONFIG_TYPE.equals(configurationType))
+ props.put(Constants.RS_ADDRESS_PROPERTY, address);
+ else if(Constants.WS_CONFIG_TYPE_OLD.equals(configurationType)){
+ props.put(Constants.WS_ADDRESS_PROPERTY_OLD, address);
+ props.put(Constants.WS_ADDRESS_PROPERTY, address);
+ }
+ }
+
+ {
+ String[] allIntents = Utils.mergeArrays(intents, Utils.getInetntsImplementedByTheService(sd));
+ props.put(RemoteConstants.SERVICE_INTENTS, allIntents);
+ }
+
+ // for (String cfg : importedConfigs) {
+ // props.put(cfg + ".stuff", "unused");
+ // }
+
+ // make sure that the Endpoint contains the address that was actualy used
+ addAddressProperty(props, address);
+
+ return props;
+
+ }
+
+ private void copyEndpointProperties(Map sd, Map<String, Object> endpointProps) {
+ Set<Map.Entry> keys = sd.entrySet();
+ for (Map.Entry entry : keys) {
+ try {
+ String skey = (String)entry.getKey();
+ if (!skey.startsWith("."))
+ endpointProps.put(skey, entry.getValue());
+ } catch (ClassCastException e) {
+ LOG.warning("ServiceProperties Map contained non String key. Skipped " + entry + " "
+ + e.getLocalizedMessage());
+ }
+ }
+ }
+
+ protected void addAddressProperty(Map props, String address) {
+ if (props != null) {
+ props.put(RemoteConstants.ENDPOINT_ID, address);
+ }
+ }
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java Mon Mar 1 14:06:34 2010
@@ -188,9 +188,9 @@
private static String[] getRequestedIntents(Map sd) {
Collection<String> intents = Arrays.asList(
- OsgiUtils.parseIntents(OsgiUtils.getProperty(sd, Constants.EXPORTED_INTENTS)));
+ OsgiUtils.parseIntents(OsgiUtils.getProperty(sd, RemoteConstants.SERVICE_EXPORTED_INTENTS)));
Collection<String> extraIntents = Arrays.asList(
- OsgiUtils.parseIntents(OsgiUtils.getProperty(sd, Constants.EXPORTED_INTENTS_EXTRA)));
+ OsgiUtils.parseIntents(OsgiUtils.getProperty(sd, RemoteConstants.SERVICE_EXPORTED_INTENTS)));
Collection<String> oldIntents = Arrays.asList(
OsgiUtils.parseIntents(OsgiUtils.getProperty(sd, Constants.EXPORTED_INTENTS_OLD)));
@@ -225,9 +225,5 @@
return intentMap;
}
- protected void addAddressProperty(Map props, String address) {
- if (props != null) {
- props.put(RemoteConstants.ENDPOINT_ID, address);
- }
- }
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java Mon Mar 1 14:06:34 2010
@@ -42,23 +42,9 @@
public ConfigurationTypeHandler getHandler(BundleContext dswBC, List<String> configurationTypes,
Map serviceProperties, Map<String, Object> props) {
- // Marc FIXME: write test case !!!
-
- // EndpointDescription sd =null;
-
- // Collection<String> types = configurationTypes;
- // //OsgiUtils.getMultiValueProperty(sd.getProperties().get(Constants.EXPORTED_CONFIGS));
- // if (types == null) {
- // types = OsgiUtils.getMultiValueProperty(sd.getProperties().get(Constants.EXPORTED_CONFIGS_OLD));
- // }
-
if (configurationTypes.contains(Constants.WS_CONFIG_TYPE)
|| configurationTypes.contains(Constants.WS_CONFIG_TYPE_OLD) || configurationTypes.contains(Constants.RS_CONFIG_TYPE)) {
-// if (types == null) {
-// LOG.info("Defaulting to pojo configuration type ");
-// }
-
boolean jaxrs = isJaxrsRequested(configurationTypes, serviceProperties);
if (OsgiUtils.getProperty(serviceProperties, Constants.WS_HTTP_SERVICE_CONTEXT) != null
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java Mon Mar 1 14:06:34 2010
@@ -1,21 +1,21 @@
/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.cxf.dosgi.dsw.handlers;
import java.net.InetAddress;
@@ -49,12 +49,12 @@
public class HttpServiceConfigurationTypeHandler extends AbstractPojoConfigurationTypeHandler {
private static final Logger LOG = Logger.getLogger(HttpServiceConfigurationTypeHandler.class.getName());
- Set<ServiceReference> httpServiceReferences = new CopyOnWriteArraySet<ServiceReference>();
-
+ Set<ServiceReference> httpServiceReferences = new CopyOnWriteArraySet<ServiceReference>();
+
protected HttpServiceConfigurationTypeHandler(BundleContext dswBC,
-
- Map<String, Object> handlerProps) {
- super(dswBC, handlerProps);
+
+ Map<String, Object> handlerProps) {
+ super(dswBC, handlerProps);
ServiceTracker st = new ServiceTracker(dswBC, HttpService.class.getName(), null) {
@Override
@@ -67,94 +67,104 @@
public void removedService(ServiceReference reference, Object service) {
httpServiceReferences.remove(reference);
super.removedService(reference, service);
- }
+ }
};
st.open();
}
- public Object createProxy(ServiceReference serviceReference,
- BundleContext dswContext, BundleContext callingContext,
- Class<?> iClass, EndpointDescription sd) {
+ public Object createProxy(ServiceReference serviceReference, BundleContext dswContext,
+ BundleContext callingContext, Class<?> iClass, EndpointDescription sd) {
// This handler doesn't make sense on the client side
return null;
}
- public void createServer(ExportRegistrationImpl exportRegistration,
- BundleContext dswContext,
- BundleContext callingContext,
- Map sd,
- Class<?> iClass,
- Object serviceBean) {
-// final String contextRoot = getServletContextRoot(sd, iClass);
-// if (contextRoot == null) {
-// LOG.warning("Remote address is unavailable");
-// return null;
-// }
-//
-// CXFNonSpringServlet cxf = new CXFNonSpringServlet();
-// HttpService httpService = getHttpService();
-// try {
-// httpService.registerServlet(contextRoot, cxf, new Hashtable<String, String>(), null);
-// LOG.info("Successfully registered CXF DOSGi servlet at " + contextRoot);
-// } catch (Exception e) {
-// throw new ServiceException("CXF DOSGi: problem registering CXF HTTP Servlet", e);
-// }
-// Bus bus = cxf.getBus();
-// DataBinding databinding;
-// String dataBindingImpl = (String) serviceReference.getProperty(Constants.WS_DATABINDING_PROP_KEY);
-// if("jaxb".equals(dataBindingImpl)) {
-// databinding = new JAXBDataBinding();
-// } else {
-// databinding = new AegisDatabinding();
-// }
-// String frontEndImpl = (String) serviceReference.getProperty(Constants.WS_FRONTEND_PROP_KEY);
-// ServerFactoryBean factory = createServerFactoryBean(frontEndImpl);
-// String address = constructAddress(dswContext, contextRoot);
-// factory.setBus(bus);
-// factory.setServiceClass(iClass);
-// factory.setAddress("/");
-// factory.getServiceFactory().setDataBinding(databinding);
-// factory.setServiceBean(serviceBean);
-//
-// ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
-// try {
-// String [] intents =
-// applyIntents(dswContext, callingContext, factory.getFeatures(), factory, sd);
-//
-// Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
-// Server server = factory.create();
-// registerStopHook(bus, httpService, server, contextRoot, Constants.WS_HTTP_SERVICE_CONTEXT);
-// //MARC: FIXME !!!! getDistributionProvider().addExposedService(serviceReference, registerPublication(server, intents, address));
-// addAddressProperty(sd.getProperties(), address);
-// return server;
-// } catch (IntentUnsatifiedException iue) {
-// //MARC: FIXME !!!! getDistributionProvider().intentsUnsatisfied(serviceReference);
-// throw iue;
-// } finally {
-// Thread.currentThread().setContextClassLoader(oldClassLoader);
-// }
- throw new RuntimeException("Marc: Implement me !!!!");
+ public void createServer(ExportRegistrationImpl exportRegistration, BundleContext dswContext,
+ BundleContext callingContext, Map sd, Class<?> iClass, Object serviceBean) {
+ final String contextRoot = getServletContextRoot(sd, iClass);
+ if (contextRoot == null) {
+ LOG.warning("Remote address is unavailable");
+ return;
+ }
+
+ CXFNonSpringServlet cxf = new CXFNonSpringServlet();
+ HttpService httpService = getHttpService();
+ try {
+ httpService.registerServlet(contextRoot, cxf, new Hashtable<String, String>(), null);
+ LOG.info("Successfully registered CXF DOSGi servlet at " + contextRoot);
+ } catch (Exception e) {
+ throw new ServiceException("CXF DOSGi: problem registering CXF HTTP Servlet", e);
+ }
+ Bus bus = cxf.getBus();
+ DataBinding databinding;
+ String dataBindingImpl = (String)exportRegistration.getExportedService()
+ .getProperty(Constants.WS_DATABINDING_PROP_KEY);
+ if ("jaxb".equals(dataBindingImpl)) {
+ databinding = new JAXBDataBinding();
+ } else {
+ databinding = new AegisDatabinding();
+ }
+ String frontEndImpl = (String)exportRegistration.getExportedService()
+ .getProperty(Constants.WS_FRONTEND_PROP_KEY);
+ ServerFactoryBean factory = createServerFactoryBean(frontEndImpl);
+ String address = constructAddress(dswContext, contextRoot);
+ factory.setBus(bus);
+ factory.setServiceClass(iClass);
+ factory.setAddress("/");
+ factory.getServiceFactory().setDataBinding(databinding);
+ factory.setServiceBean(serviceBean);
+
+
+
+
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ String[] intents = applyIntents(dswContext, callingContext, factory.getFeatures(), factory, sd);
+
+ // The properties for the EndpointDescription
+ Map<String, Object> endpointProps = createEndpointProps(sd, iClass, new String[] {
+ Constants.WS_CONFIG_TYPE
+ }, address,intents);
+ EndpointDescription endpdDesc = null;
+
+ Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
+ Server server = factory.create();
+
+ // TODO: does this still make sense ?!?
+ registerStopHook(bus, httpService, server, contextRoot, Constants.WS_HTTP_SERVICE_CONTEXT);
+
+ endpdDesc = new EndpointDescription(endpointProps);
+ exportRegistration.setServer(server);
+
+ // add the information on the new Endpoint to the export registration
+ exportRegistration.setEndpointdescription(endpdDesc);
+ } catch (IntentUnsatifiedException iue) {
+ exportRegistration.setException(iue);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
+ }
+
+
}
-
+
protected Map<String, String> registerPublication(Server server, String[] intents, String address) {
Map<String, String> publicationProperties = super.registerPublication(server, intents);
publicationProperties.put(Constants.WS_ADDRESS_PROPERTY, address);
return publicationProperties;
- }
+ }
protected String constructAddress(BundleContext ctx, String contextRoot) {
String port = null;
boolean https = false;
if ("true".equalsIgnoreCase(ctx.getProperty("org.osgi.service.http.secure.enabled"))) {
https = true;
- port = ctx.getProperty("org.osgi.service.http.port.secure");
+ port = ctx.getProperty("org.osgi.service.http.port.secure");
} else {
- port = ctx.getProperty("org.osgi.service.http.port");
+ port = ctx.getProperty("org.osgi.service.http.port");
}
if (port == null) {
port = "8080";
}
-
+
String hostName = null;
try {
hostName = InetAddress.getLocalHost().getHostName();
@@ -169,29 +179,28 @@
for (ServiceReference sr : httpServiceReferences) {
Object svc = bundleContext.getService(sr);
if (svc instanceof HttpService) {
- return (HttpService) svc;
+ return (HttpService)svc;
}
}
throw new ServiceException("CXF DOSGi: No HTTP Service could be found to publish CXF endpoint in.");
}
- protected String getServletContextRoot(EndpointDescription sd, Class<?> iClass) {
+ protected String getServletContextRoot(Map sd, Class<?> iClass) {
String context = OsgiUtils.getProperty(sd, Constants.WS_HTTP_SERVICE_CONTEXT);
if (context == null) {
- context = OsgiUtils.getProperty(sd, Constants.WS_HTTP_SERVICE_CONTEXT_OLD);
+ context = OsgiUtils.getProperty(sd, Constants.WS_HTTP_SERVICE_CONTEXT_OLD);
}
-
+
if (context == null) {
context = "/" + iClass.getName().replace('.', '/');
LOG.info("Using a default address : " + context);
}
return context;
}
-
- protected void registerStopHook(Bus bus, final HttpService httpService,
- Server theServer, final String contextRoot,
- final String propertyName) {
- if(bus != null) {
+
+ protected void registerStopHook(Bus bus, final HttpService httpService, Server theServer,
+ final String contextRoot, final String propertyName) {
+ if (bus != null) {
theServer.getEndpoint().put(propertyName, contextRoot);
ServerLifeCycleListener stopHook = new ServerLifeCycleListener() {
public void stopServer(Server s) {
@@ -200,6 +209,7 @@
httpService.unregister(contextRoot);
}
}
+
public void startServer(Server s) {
}
};
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java Mon Mar 1 14:06:34 2010
@@ -1,21 +1,21 @@
/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.cxf.dosgi.dsw.handlers;
import java.util.Hashtable;
@@ -28,6 +28,7 @@
import org.apache.cxf.Bus;
import org.apache.cxf.dosgi.dsw.Constants;
import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.apache.cxf.dosgi.dsw.service.ExportRegistrationImpl;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
@@ -40,26 +41,25 @@
import org.osgi.service.remoteserviceadmin.EndpointDescription;
public class JaxRSHttpServiceConfigurationTypeHandler extends HttpServiceConfigurationTypeHandler {
- private static final Logger LOG = Logger.getLogger(JaxRSHttpServiceConfigurationTypeHandler.class.getName());
+ private static final Logger LOG = Logger.getLogger(JaxRSHttpServiceConfigurationTypeHandler.class
+ .getName());
- Set<ServiceReference> httpServiceReferences = new CopyOnWriteArraySet<ServiceReference>();
+ Set<ServiceReference> httpServiceReferences = new CopyOnWriteArraySet<ServiceReference>();
protected JaxRSHttpServiceConfigurationTypeHandler(BundleContext dswBC,
-
- Map<String, Object> handlerProps) {
+
+ Map<String, Object> handlerProps) {
super(dswBC, handlerProps);
}
- public Server createServer(ServiceReference serviceReference,
- BundleContext dswContext,
- BundleContext callingContext,
- EndpointDescription sd,
- Class<?> iClass,
- Object serviceBean) {
+ @Override
+ public void createServer(ExportRegistrationImpl exportRegistration, BundleContext dswContext,
+ BundleContext callingContext, Map sd, Class<?> iClass, Object serviceBean) {
+
String contextRoot = getServletContextRoot(sd, iClass);
if (contextRoot == null) {
LOG.warning("Remote address is unavailable");
- return null;
+ return;
}
CXFNonSpringServlet cxf = new CXFNonSpringServlet();
@@ -69,12 +69,12 @@
LOG.info("Successfully registered CXF DOSGi servlet at " + contextRoot);
} catch (Exception e) {
throw new ServiceException("CXF DOSGi: problem registering CXF HTTP Servlet", e);
- }
+ }
Bus bus = cxf.getBus();
-
+
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setBus(bus);
-
+
List<UserResource> resources = JaxRSUtils.getModel(callingContext, iClass);
if (resources != null) {
factory.setModelBeansWithServiceClass(resources, iClass);
@@ -83,41 +83,57 @@
factory.setServiceClass(iClass);
factory.setResourceProvider(iClass, new SingletonResourceProvider(serviceBean));
}
-
+
factory.setAddress("/");
List<Object> providers = JaxRSUtils.getProviders(callingContext, dswContext, sd);
if (providers != null && providers.size() > 0) {
- factory.setProviders(providers);
+ factory.setProviders(providers);
}
-
+
String address = constructAddress(dswContext, contextRoot);
+
+
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
- String [] intents = new String[] {"HTTP"};
+ String[] intents = new String[] {
+ "HTTP"
+ };
+
+ // The properties for the EndpointDescription
+ Map<String, Object> endpointProps = createEndpointProps(sd, iClass, new String[] {
+ Constants.RS_CONFIG_TYPE
+ }, address,intents);
+ EndpointDescription endpdDesc = null;
+
+
Thread.currentThread().setContextClassLoader(JAXRSServerFactoryBean.class.getClassLoader());
Server server = factory.create();
registerStopHook(bus, httpService, server, contextRoot, Constants.RS_HTTP_SERVICE_CONTEXT);
- //MARC: FIXME !!!! getDistributionProvider().addExposedService(serviceReference, registerPublication(server, intents, address));
- addAddressProperty(sd.getProperties(), address);
- return server;
+
+ endpdDesc = new EndpointDescription(endpointProps);
+ exportRegistration.setServer(server);
+
+ // add the information on the new Endpoint to the export registration
+ exportRegistration.setEndpointdescription(endpdDesc);
} catch (IntentUnsatifiedException iue) {
- //MARC: FIXME !!!! getDistributionProvider().intentsUnsatisfied(serviceReference);
- throw iue;
+ exportRegistration.setException(iue);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
- }
+ }
+
+
}
-
+
@Override
- protected String getServletContextRoot(EndpointDescription sd, Class<?> iClass) {
+ protected String getServletContextRoot(Map sd, Class<?> iClass) {
String context = OsgiUtils.getProperty(sd, Constants.RS_HTTP_SERVICE_CONTEXT);
-
+
if (context == null) {
context = "/" + iClass.getName().replace('.', '/');
LOG.info("Using a default address : " + context);
}
return context;
}
-
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java Mon Mar 1 14:06:34 2010
@@ -1,21 +1,21 @@
/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.cxf.dosgi.dsw.handlers;
import java.util.List;
@@ -27,6 +27,7 @@
import org.apache.cxf.dosgi.dsw.Constants;
import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.apache.cxf.dosgi.dsw.service.ExportRegistrationImpl;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
@@ -39,107 +40,116 @@
public class JaxRSPojoConfigurationTypeHandler extends PojoConfigurationTypeHandler {
private static final Logger LOG = Logger.getLogger(JaxRSPojoConfigurationTypeHandler.class.getName());
- Set<ServiceReference> httpServiceReferences = new CopyOnWriteArraySet<ServiceReference>();
+ Set<ServiceReference> httpServiceReferences = new CopyOnWriteArraySet<ServiceReference>();
protected JaxRSPojoConfigurationTypeHandler(BundleContext dswBC,
-
- Map<String, Object> handlerProps) {
+
+ Map<String, Object> handlerProps) {
super(dswBC, handlerProps);
}
- public Object createProxy(ServiceReference serviceReference,
- BundleContext dswContext, BundleContext callingContext,
- Class<?> iClass, EndpointDescription sd) {
- String address = getPojoAddress(sd, iClass);
-
- if (address == null) {
- LOG.warning("Remote address is unavailable");
- return null;
- }
-
- LOG.info("Creating a " + sd.getInterfaces().toArray()[0]
- + " client, endpoint address is " + address);
-
- ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
- try {
- JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
- bean.setAddress(address);
-
- List<UserResource> resources = JaxRSUtils.getModel(callingContext, iClass);
- if (resources != null) {
- bean.setModelBeansWithServiceClass(resources, iClass);
- } else {
- bean.setServiceClass(iClass);
- }
- List<Object> providers = JaxRSUtils.getProviders(callingContext, dswContext, sd);
- if (providers != null && providers.size() > 0) {
- bean.setProviders(providers);
- }
- Thread.currentThread().setContextClassLoader(JAXRSClientFactoryBean.class.getClassLoader());
- Object proxy = getProxy(bean.create(), iClass);
- //MARC: FIXME !!!! getDistributionProvider().addRemoteService(serviceReference);
- return proxy;
- } catch (Exception e) {
- LOG.log(Level.WARNING, "proxy creation failed", e);
- } finally {
- Thread.currentThread().setContextClassLoader(oldClassLoader);
- }
- return null;
- }
-
-
- public Server createServer(ServiceReference serviceReference,
- BundleContext dswContext,
- BundleContext callingContext,
- EndpointDescription sd,
- Class<?> iClass,
- Object serviceBean) {
- String address = getPojoAddress(sd, iClass);
+ @Override
+ public Object createProxy(ServiceReference serviceReference, BundleContext dswContext,
+ BundleContext callingContext, Class<?> iClass, EndpointDescription sd)
+ throws IntentUnsatifiedException {
+
+ String address = getPojoAddress(sd, iClass);
if (address == null) {
LOG.warning("Remote address is unavailable");
return null;
}
-
- LOG.info("Creating a " + sd.getInterfaces().toArray()[0]
- + " endpoint from CXF PublishHook, address is " + address);
-
+
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+ bean.setAddress(address);
+
+ List<UserResource> resources = JaxRSUtils.getModel(callingContext, iClass);
+ if (resources != null) {
+ bean.setModelBeansWithServiceClass(resources, iClass);
+ } else {
+ bean.setServiceClass(iClass);
+ }
+ List<Object> providers = JaxRSUtils.getProviders(callingContext, dswContext, sd.getProperties());
+ if (providers != null && providers.size() > 0) {
+ bean.setProviders(providers);
+ }
+ Thread.currentThread().setContextClassLoader(JAXRSClientFactoryBean.class.getClassLoader());
+ Object proxy = getProxy(bean.create(), iClass);
+ return proxy;
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "proxy creation failed", e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
+ }
+ return null;
+
+ }
+
+ @Override
+ public void createServer(ExportRegistrationImpl exportRegistration, BundleContext dswContext,
+ BundleContext callingContext, Map sd, Class<?> iClass, Object serviceBean)
+ throws IntentUnsatifiedException {
+
+ String address = getPojoAddress(sd, iClass);
+ if (address == null) {
+ LOG.warning("Remote address is unavailable");
+ exportRegistration.setException(new Throwable("Remote address is unavailable"));
+ return;
+ }
+
+ LOG.info("Creating a " + iClass.getName()
+ + " endpoint via JaxRSPojoConfigurationTypeHandler, address is " + address);
+
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
-
+
List<UserResource> resources = JaxRSUtils.getModel(callingContext, iClass);
if (resources != null) {
- factory.setModelBeansWithServiceClass(resources, iClass);
- factory.setServiceBeans(serviceBean);
+ factory.setModelBeansWithServiceClass(resources, iClass);
+ factory.setServiceBeans(serviceBean);
} else {
factory.setServiceClass(iClass);
factory.setResourceProvider(iClass, new SingletonResourceProvider(serviceBean));
}
-
+
factory.setAddress(address);
List<Object> providers = JaxRSUtils.getProviders(callingContext, dswContext, sd);
if (providers != null && providers.size() > 0) {
- factory.setProviders(providers);
+ factory.setProviders(providers);
}
-
+
+
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
- String [] intents = new String[]{"HTTP"};
+ String[] intents = new String[] {
+ "HTTP"
+ };
+
+ // The properties for the EndpointDescription
+ Map<String, Object> endpointProps = createEndpointProps(sd, iClass, new String[] {
+ Constants.RS_CONFIG_TYPE
+ }, address,intents);
+ EndpointDescription endpdDesc = null;
Thread.currentThread().setContextClassLoader(JAXRSServerFactoryBean.class.getClassLoader());
Server server = factory.create();
- //MARC: FIXME !!!! getDistributionProvider().addExposedService(serviceReference, registerPublication(server, intents));
- addAddressProperty(sd.getProperties(), address);
- return server;
+ exportRegistration.setServer(server);
+ endpdDesc = new EndpointDescription(endpointProps);
+
+ // add the information on the new Endpoint to the export registration
+ exportRegistration.setEndpointdescription(endpdDesc);
} catch (IntentUnsatifiedException iue) {
- //MARC: FIXME !!!! getDistributionProvider().intentsUnsatisfied(serviceReference);
- throw iue;
+ exportRegistration.setException(iue);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
- }
+ }
+
+
}
protected String getPojoAddress(EndpointDescription sd, Class<?> iClass) {
String address = OsgiUtils.getProperty(sd, Constants.RS_ADDRESS_PROPERTY);
-
+
if (address == null) {
address = getDefaultAddress(iClass);
if (address != null) {
@@ -148,6 +158,5 @@
}
return address;
}
-
-
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java Mon Mar 1 14:06:34 2010
@@ -1,21 +1,21 @@
/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.cxf.dosgi.dsw.handlers;
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import java.util.logging.Logger;
import org.apache.cxf.dosgi.dsw.OsgiUtils;
@@ -37,114 +38,113 @@
public class JaxRSUtils {
- private static final Logger LOG = Logger.getLogger(JaxRSUtils.class.getName());
-
- public final static String MODEL_FOLDER = "/OSGI-INF/cxf/jaxrs/";
- public final static String DEFAULT_MODEL = "/OSGI-INF/cxf/jaxrs/model.xml";
- public final static String PROVIDERS_FILTER =
- "(|"
- + "(" + Constants.OBJECTCLASS + "=javax.ws.rs.ext.MessageBodyReader" + ")"
- + "(" + Constants.OBJECTCLASS + "=javax.ws.rs.ext.MessageBodyWriter" + ")"
- + "(" + Constants.OBJECTCLASS + "=javax.ws.rs.ext.ExceptionMapper" + ")"
- + "(" + Constants.OBJECTCLASS + "=org.apache.cxf.jaxrs.ext.RequestHandler" + ")"
- + "(" + Constants.OBJECTCLASS + "=org.apache.cxf.jaxrs.ext.ResponseHandler" + ")"
- + "(" + Constants.OBJECTCLASS + "=org.apache.cxf.jaxrs.ext.ParameterHandler" + ")"
- + ")";
-
- public static List<Object> getProviders(BundleContext callingContext,
- BundleContext dswBC,
- EndpointDescription sd) {
-
- List<Object> providers = new ArrayList<Object>();
- if ("aegis".equals(sd.getProperties().get(org.apache.cxf.dosgi.dsw.Constants.RS_DATABINDING_PROP_KEY))) {
- providers.add(new AegisElementProvider());
+ private static final Logger LOG = Logger.getLogger(JaxRSUtils.class.getName());
+
+ public final static String MODEL_FOLDER = "/OSGI-INF/cxf/jaxrs/";
+ public final static String DEFAULT_MODEL = "/OSGI-INF/cxf/jaxrs/model.xml";
+ public final static String PROVIDERS_FILTER = "(|" + "(" + Constants.OBJECTCLASS
+ + "=javax.ws.rs.ext.MessageBodyReader" + ")" + "("
+ + Constants.OBJECTCLASS
+ + "=javax.ws.rs.ext.MessageBodyWriter" + ")" + "("
+ + Constants.OBJECTCLASS
+ + "=javax.ws.rs.ext.ExceptionMapper" + ")" + "("
+ + Constants.OBJECTCLASS
+ + "=org.apache.cxf.jaxrs.ext.RequestHandler" + ")" + "("
+ + Constants.OBJECTCLASS
+ + "=org.apache.cxf.jaxrs.ext.ResponseHandler" + ")" + "("
+ + Constants.OBJECTCLASS
+ + "=org.apache.cxf.jaxrs.ext.ParameterHandler" + ")" + ")";
+
+ public static List<Object> getProviders(BundleContext callingContext, BundleContext dswBC, Map sd) {
+
+ List<Object> providers = new ArrayList<Object>();
+ if ("aegis".equals(sd.get(org.apache.cxf.dosgi.dsw.Constants.RS_DATABINDING_PROP_KEY))) {
+ providers.add(new AegisElementProvider());
}
- Object serviceProviders =
- sd.getProperties().get(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_PROP_KEY);
+ Object serviceProviders = sd.get(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_PROP_KEY);
if (serviceProviders != null) {
- if (serviceProviders.getClass().isArray()) {
- if (serviceProviders.getClass().getComponentType() == String.class) {
- loadProviders(callingContext, providers, (String[])serviceProviders);
- } else {
- providers.addAll(Arrays.asList((Object[])serviceProviders));
- }
- } else {
- String[] classNames = serviceProviders.toString().split(",");
- loadProviders(callingContext, providers, classNames);
- }
- }
-
- Object globalQueryProp =
- sd.getProperties().get(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_GLOBAL_PROP_KEY);
- boolean globalQueryRequired = globalQueryProp == null || OsgiUtils.toBoolean(globalQueryProp);
+ if (serviceProviders.getClass().isArray()) {
+ if (serviceProviders.getClass().getComponentType() == String.class) {
+ loadProviders(callingContext, providers, (String[])serviceProviders);
+ } else {
+ providers.addAll(Arrays.asList((Object[])serviceProviders));
+ }
+ } else {
+ String[] classNames = serviceProviders.toString().split(",");
+ loadProviders(callingContext, providers, classNames);
+ }
+ }
+
+ Object globalQueryProp = sd.get(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_GLOBAL_PROP_KEY);
+ boolean globalQueryRequired = globalQueryProp == null || OsgiUtils.toBoolean(globalQueryProp);
if (!globalQueryRequired) {
- return providers;
+ return providers;
+ }
+
+ boolean cxfProvidersOnly = OsgiUtils
+ .getBooleanProperty(sd, org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_EXPECTED_PROP_KEY);
+
+ try {
+ ServiceReference[] refs = callingContext.getServiceReferences(null, PROVIDERS_FILTER);
+ if (refs != null) {
+ for (ServiceReference ref : refs) {
+ if (!cxfProvidersOnly
+ || cxfProvidersOnly
+ && OsgiUtils.toBoolean(ref
+ .getProperty(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_PROP_KEY))) {
+ providers.add(callingContext.getService(ref));
+ }
+ }
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ LOG.fine("Problems finding JAXRS providers " + ex.getMessage());
}
-
- boolean cxfProvidersOnly = OsgiUtils.getBooleanProperty(sd,
- org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_EXPECTED_PROP_KEY);
-
- try {
- ServiceReference[] refs = callingContext.getServiceReferences(null, PROVIDERS_FILTER);
- if (refs != null) {
- for (ServiceReference ref : refs) {
- if (!cxfProvidersOnly || cxfProvidersOnly
- && OsgiUtils.toBoolean(
- ref.getProperty(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_PROP_KEY))) {
- providers.add(callingContext.getService(ref));
- }
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- LOG.fine("Problems finding JAXRS providers " + ex.getMessage());
- }
- return providers;
+ return providers;
}
-
- private static void loadProviders(BundleContext callingContext,
- List<Object> providers,
- String[] classNames) {
- for (String className : classNames) {
- try {
- String realName = className.trim();
- if (realName.length() > 0) {
- Class<?> pClass = callingContext.getBundle().loadClass(realName);
- providers.add(pClass.newInstance());
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- LOG.warning("JAXRS Provider " + className.trim() + " can not be loaded or created");
- }
- }
- }
-
- public static List<UserResource> getModel(BundleContext callingContext, Class<?> iClass) {
- String classModel = MODEL_FOLDER + iClass.getSimpleName() + "-model.xml";
- List<UserResource> list = getModel(callingContext, iClass, classModel);
- return list != null ? list : getModel(callingContext, iClass, DEFAULT_MODEL);
+
+ private static void loadProviders(BundleContext callingContext, List<Object> providers,
+ String[] classNames) {
+ for (String className : classNames) {
+ try {
+ String realName = className.trim();
+ if (realName.length() > 0) {
+ Class<?> pClass = callingContext.getBundle().loadClass(realName);
+ providers.add(pClass.newInstance());
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ LOG.warning("JAXRS Provider " + className.trim() + " can not be loaded or created");
+ }
+ }
+ }
+
+ public static List<UserResource> getModel(BundleContext callingContext, Class<?> iClass) {
+ String classModel = MODEL_FOLDER + iClass.getSimpleName() + "-model.xml";
+ List<UserResource> list = getModel(callingContext, iClass, classModel);
+ return list != null ? list : getModel(callingContext, iClass, DEFAULT_MODEL);
}
-
- public static List<UserResource> getModel(BundleContext callingContext, Class<?> iClass, String name) {
- InputStream r = iClass.getClassLoader().getResourceAsStream(name);
- if (r == null) {
- URL u = callingContext.getBundle().getResource(name);
- if (u != null) {
- try {
- r = u.openStream();
- } catch (Exception ex) {
- LOG.info("Problems opening a user model resource at " + u.toString());
- }
- }
- }
- if (r != null) {
- try {
- return ResourceUtils.getUserResources(r);
- } catch (Exception ex) {
- LOG.info("Problems reading a user model, it will be ignored");
- }
- }
- return null;
+
+ public static List<UserResource> getModel(BundleContext callingContext, Class<?> iClass, String name) {
+ InputStream r = iClass.getClassLoader().getResourceAsStream(name);
+ if (r == null) {
+ URL u = callingContext.getBundle().getResource(name);
+ if (u != null) {
+ try {
+ r = u.openStream();
+ } catch (Exception ex) {
+ LOG.info("Problems opening a user model resource at " + u.toString());
+ }
+ }
+ }
+ if (r != null) {
+ try {
+ return ResourceUtils.getUserResources(r);
+ } catch (Exception ex) {
+ LOG.info("Problems reading a user model, it will be ignored");
+ }
+ }
+ return null;
}
-
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java Mon Mar 1 14:06:34 2010
@@ -18,6 +18,10 @@
*/
package org.apache.cxf.dosgi.dsw.handlers;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -57,6 +61,7 @@
String address = getPojoAddress(sd.getProperties(), iClass);
if (address == null) {
LOG.warning("Remote address is unavailable");
+ // TODO: fire Event
return null;
}
@@ -103,30 +108,6 @@
LOG.info("Creating a " + iClass.getName() + " endpoint from CXF PublishHook, address is " + address);
- // The properties for the EndpointDescription
- Map<String, Object> endpointProps = new HashMap<String, Object>();
-
- copyEndpointProperties(sd, endpointProps);
-
-
-
- String[] sa = new String[1];
- sa[0] = iClass.getName();
- endpointProps.put(org.osgi.framework.Constants.OBJECTCLASS, sa);
- // endpointProps.put(RemoteConstants.SERVICE_IMPORTED, "someValue;-)"); // should be done when the
- // service is imported
- // endpointProps.put(RemoteConstants.SERVICE_REMOTE_ID, "TODO");
-
- // FIXME: This key is not defined in the spec but is required by the EndpointDescription !!!!!
- endpointProps.put(RemoteConstants.ENDPOINT_SERVICE_ID, 123L);
-
- endpointProps.put(RemoteConstants.ENDPOINT_FRAMEWORK_UUID, OsgiUtils.getUUID(getBundleContext()));
- endpointProps.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, Constants.WS_CONFIG_TYPE);
- endpointProps.put(RemoteConstants.ENDPOINT_PACKAGE_VERSION_ + sa[0], OsgiUtils.getVersion(iClass, dswContext));
- endpointProps.put(RemoteConstants.SERVICE_INTENTS, Utils.getAllIntentsCombined(sd));
- // make sure that the Endpoint contains the address that was actualy used
- addAddressProperty(endpointProps, address);
-
DataBinding databinding;
String dataBindingImpl = (String)exportRegistration.getExportedService()
.getProperty(Constants.WS_DATABINDING_PROP_KEY);
@@ -139,7 +120,7 @@
.getProperty(Constants.WS_FRONTEND_PROP_KEY);
ServerFactoryBean factory = createServerFactoryBean(frontEndImpl);
- factory.setServiceClass(iClass);
+ factory.setServiceClass(iClass);
factory.setAddress(address);
factory.getServiceFactory().setDataBinding(databinding);
factory.setServiceBean(serviceBean);
@@ -148,57 +129,62 @@
try {
String[] intents = applyIntents(dswContext, callingContext, factory.getFeatures(), factory, sd);
+ // The properties for the EndpointDescription
+ Map<String, Object> endpointProps = createEndpointProps(sd, iClass, new String[]{Constants.WS_CONFIG_TYPE}, address,intents);
+
Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
Server server = factory.create();
-
exportRegistration.setServer(server);
-
+
+ // add the information on the new Endpoint to the export registration
+ EndpointDescription ed = new EndpointDescription(endpointProps);
+ exportRegistration.setEndpointdescription(ed);
+
} catch (IntentUnsatifiedException iue) {
exportRegistration.setException(iue);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
- // add the information on the new Endpoint to the export registration
- EndpointDescription ed = new EndpointDescription(endpointProps);
- exportRegistration.setEndpointdescription(ed);
- }
-
-
-
- private void copyEndpointProperties(Map sd, Map<String, Object> endpointProps) {
- Set<Map.Entry> keys = sd.entrySet();
- for (Map.Entry entry : keys) {
- try{
- String skey = (String)entry.getKey();
- if (!skey.startsWith("."))
- endpointProps.put(skey, entry.getValue());
- }catch (ClassCastException e) {
- LOG.warning("ServiceProperties Map contained non String key. Skipped "+entry + " "+e.getLocalizedMessage());
- }
- }
+
}
-// @Override
-// Map<String, String> registerPublication(Server server, String[] intents) {
-// Map<String, String> publicationProperties = super.registerPublication(server, intents);
-// publicationProperties.put(Constants.WS_ADDRESS_PROPERTY, server.getDestination().getAddress()
-// .getAddress().getValue());
-//
-// return publicationProperties;
-// }
-
protected String getPojoAddress(Map sd, Class<?> iClass) {
String address = OsgiUtils.getProperty(sd, RemoteConstants.ENDPOINT_ID);
+ if(address == null && sd.get(RemoteConstants.ENDPOINT_ID)!=null ){
+ LOG.severe("Could not use address property " + RemoteConstants.ENDPOINT_ID );
+ return null;
+ }
+
+
if (address == null) {
address = OsgiUtils.getProperty(sd, Constants.WS_ADDRESS_PROPERTY);
}
+ if(address == null && sd.get(Constants.WS_ADDRESS_PROPERTY)!=null ){
+ LOG.severe("Could not use address property " + Constants.WS_ADDRESS_PROPERTY );
+ return null;
+ }
+
if (address == null) {
address = OsgiUtils.getProperty(sd, Constants.WS_ADDRESS_PROPERTY_OLD);
}
+ if(address == null && sd.get(Constants.WS_ADDRESS_PROPERTY_OLD)!=null ){
+ LOG.severe("Could not use address property " + Constants.WS_ADDRESS_PROPERTY_OLD);
+ return null;
+ }
+
+ if (address == null) {
+ address = OsgiUtils.getProperty(sd, Constants.RS_ADDRESS_PROPERTY);
+ }
+ if(address == null && sd.get(Constants.RS_ADDRESS_PROPERTY)!=null ){
+ LOG.severe("Could not use address property " + Constants.RS_ADDRESS_PROPERTY);
+ return null;
+ }
+
+
if (address == null) {
address = getDefaultAddress(iClass);
if (address != null) {
@@ -208,4 +194,5 @@
return address;
}
+
}