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/01/07 10:25:56 UTC
svn commit: r896813 - 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/ dsw/...
Author: davidb
Date: Thu Jan 7 09:24:07 2010
New Revision: 896813
URL: http://svn.apache.org/viewvc?rev=896813&view=rev
Log:
Patch discovery_startup__rsa_intents_and_property_overwrites.patch applied on behalf of Marc Schaaf.
Added:
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RenoteServiceAdminCoreTest.java (with props)
Modified:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/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/PojoConfigurationTypeHandler.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/Utils.java
Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java?rev=896813&r1=896812&r2=896813&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java Thu Jan 7 09:24:07 2010
@@ -42,60 +42,61 @@
public synchronized void start(BundleContext bc) throws Exception {
bctx = bc;
zkProperties = getCMDefaults();
-
zkd = createZooKeeperDiscovery();
- // zkd.start() is invoked via configuration update
-
-
+
cmReg = bc.registerService(ManagedService.class.getName(), this, zkProperties);
-// LOG.info("STARTING NOW");
-// updated(null);
+ LOG.info("Starting Zookeeper Discovery client with default configuration");
+ // Catch connection failures so that the bundle startup ist successful and other configuration can be
+ // received via ConfigurationAdmin
+ try {
+ zkd.start();
+ } catch (IOException e) {
+ LOG.warning("Startup with default configuration failed: " + e.getLocalizedMessage());
+ } catch (ConfigurationException e) {
+ LOG.warning("Startup with default configuration failed: " + e.getLocalizedMessage());
+ }
}
public synchronized void stop(BundleContext bc) throws Exception {
cmReg.unregister();
-
zkd.stop();
-
}
public synchronized void updated(Dictionary configuration) throws ConfigurationException {
- if (configuration == null) {
+ if (configuration == null)
+ return;
- } else {
-
- Dictionary effective = getCMDefaults();
- // apply all values on top of the defaults
- for (Enumeration e = configuration.keys(); e.hasMoreElements();) {
- Object key = e.nextElement();
- if (key != null) {
- Object val = configuration.get(key);
- effective.put(key, val);
- }
+ Dictionary effective = getCMDefaults();
+ // apply all values on top of the defaults
+ for (Enumeration e = configuration.keys(); e.hasMoreElements();) {
+ Object key = e.nextElement();
+ if (key != null) {
+ Object val = configuration.get(key);
+ effective.put(key, val);
}
+ }
- if (zkProperties.equals(effective)) {
- LOG.info("properties haven't changed ...");
- return;
- }
+ if (zkProperties.equals(effective)) {
+ LOG.info("properties haven't changed ...");
+ return;
+ }
- zkProperties = effective;
-
- synchronized (this) {
- zkd.stop();
- zkd = createZooKeeperDiscovery();
- }
+ zkProperties = effective;
+
+ synchronized (this) {
+ zkd.stop();
+ zkd = createZooKeeperDiscovery();
}
-
- // call start in any case
+
+ // call start in any case
try {
zkd.start();
} catch (IOException e) {
e.printStackTrace();
}
-
+
}
private Dictionary getCMDefaults() {
@@ -104,7 +105,7 @@
props.put("zookeeper.port", "2181");
props.put("zookeeper.host", "localhost");
props.put(Constants.SERVICE_PID, "org.apache.cxf.dosgi.discovery.zookeeper");
- return props;
+ return props;
}
// for testing
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=896813&r1=896812&r2=896813&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 Thu Jan 7 09:24:07 2010
@@ -395,6 +395,7 @@
}
try {
+ LOG.fine("Loading Intent map from "+springIntentLocations);
OsgiBundleXmlApplicationContext ctx = new OsgiBundleXmlApplicationContext(springIntentLocations
.toArray(new String[] {}));
ctx.setPublishContextAsService(false);
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=896813&r1=896812&r2=896813&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 Thu Jan 7 09:24:07 2010
@@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -29,6 +30,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.dosgi.dsw.service.Utils;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.cxf.frontend.ServerFactoryBean;
@@ -104,7 +106,7 @@
// The properties for the EndpointDescription
Map<String, Object> endpointProps = new HashMap<String, Object>();
- copyEndpointProperties(exportRegistration, endpointProps);
+ copyEndpointProperties(sd, endpointProps);
String[] sa = new String[1];
sa[0] = iClass.getName();
@@ -119,6 +121,7 @@
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));
DataBinding databinding;
String dataBindingImpl = (String)exportRegistration.getExportedService()
@@ -132,7 +135,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);
@@ -160,15 +163,17 @@
- private void copyEndpointProperties(ExportRegistrationImpl exportRegistration,
- Map<String, Object> endpointProps) {
-
- String[] keys = exportRegistration.getExportedService().getPropertyKeys();
- for (String key : keys) {
- if (!key.startsWith("."))
- endpointProps.put(key, exportRegistration.getExportedService().getProperty(key));
+ 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());
+ }
}
-
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java?rev=896813&r1=896812&r2=896813&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java Thu Jan 7 09:24:07 2010
@@ -31,6 +31,7 @@
import java.util.Set;
import java.util.logging.Logger;
+import org.apache.commons.lang.ArrayUtils;
import org.apache.cxf.dosgi.dsw.ClassUtils;
import org.apache.cxf.dosgi.dsw.Constants;
import org.apache.cxf.dosgi.dsw.handlers.ClientServiceFactory;
@@ -78,8 +79,8 @@
LOG.fine("RemoteServiceAdmin: exportService: " + sref.getClass().getName());
- // check if it is already exported ....
synchronized (exportedServices) {
+ // check if it is already exported ....
if (exportedServices.containsKey(sref)) {
LOG.fine("already exported ... " + sref.getClass().getName());
Collection<ExportRegistrationImpl> regs = exportedServices.get(sref);
@@ -118,14 +119,29 @@
|| org.osgi.framework.Constants.OBJECTCLASS.toLowerCase().equals(key)) {
LOG
.info("exportService called with additional properties map that contained illegal key: "
- + key + " Te key is ignored");
+ + key + " The key is ignored");
continue;
}
}
serviceProperties.put(e.getKey(), e.getValue());
+ LOG.fine("Overwriting property ["+e.getKey()+"] with value ["+e.getValue()+"]");
}
}
-
+
+
+
+
+
+ // Get the intents that need to be supported by the RSA
+ String[] requiredIntents = Utils.getAllRequiredIntents(serviceProperties);
+
+ { // TODO: Determine if the required intents can be provided by the RSA ....
+
+ // if not return null
+ }
+
+
+
List<String> interfaces = new ArrayList<String>(1);
{// determine which interfaces should be exported ? based on props and sRef
@@ -190,6 +206,7 @@
LinkedHashMap<String, ExportRegistrationImpl> exportRegs = new LinkedHashMap<String, ExportRegistrationImpl>(
1);
+
for (String iface : interfaces) {
LOG.info("creating initial ExportDescription for interface " + iface
+ " with configuration types " + configurationTypes);
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/Utils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/Utils.java?rev=896813&r1=896812&r2=896813&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/Utils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/Utils.java Thu Jan 7 09:24:07 2010
@@ -20,8 +20,13 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
import java.util.logging.Logger;
+import org.apache.commons.lang.ArrayUtils;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
public class Utils {
@@ -80,5 +85,55 @@
return "UNKNOWN_EVENT";
}
}
+
+
+ public static String[] getAllRequiredIntents(Map serviceProperties){
+ // Get the intents that need to be supported by the RSA
+ String[] requiredIntents = Utils.normalizeStringPlus(serviceProperties.get(RemoteConstants.SERVICE_EXPORTED_INTENTS));
+ if(requiredIntents==null){
+ requiredIntents = new String[0];
+ }
+
+ { // merge with extra intents;
+ String[] requiredExtraIntents = Utils.normalizeStringPlus(serviceProperties.get(RemoteConstants.SERVICE_EXPORTED_INTENTS_EXTRA));
+ if(requiredExtraIntents!= null && requiredExtraIntents.length>0){
+
+ requiredIntents = mergeArrays(requiredIntents, requiredExtraIntents);
+ }
+ }
+
+ return requiredIntents;
+ }
+ public static String[] getAllIntentsCombined(Map serviceProperties){
+ String[] requiredIntents = getAllRequiredIntents(serviceProperties);
+
+ // Get the Intents that are implemented by the service
+ String[] serviceIntents = Utils.normalizeStringPlus(serviceProperties.get(RemoteConstants.SERVICE_INTENTS));
+
+ if(serviceIntents!= null && serviceIntents.length>0){
+ requiredIntents = mergeArrays(requiredIntents, serviceIntents);
+ }
+
+ return requiredIntents;
+ }
+
+
+ public static String[] mergeArrays(String[] a1,String[] a2){
+ if(a1==null) return a2;
+ if(a2==null) return a1;
+
+ List<String> list = new ArrayList<String>(a1.length+a2.length);
+
+ for (String s : a1) {
+ list.add(s);
+ }
+
+ for (String s : a2) {
+ if(!list.contains(s))
+ list.add(s);
+ }
+
+ return list.toArray(new String[list.size()]);
+ }
}
Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RenoteServiceAdminCoreTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RenoteServiceAdminCoreTest.java?rev=896813&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RenoteServiceAdminCoreTest.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RenoteServiceAdminCoreTest.java Thu Jan 7 09:24:07 2010
@@ -0,0 +1,149 @@
+/**
+ * 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.service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
+import org.apache.cxf.jaxws.spring.EndpointDefinitionParser;
+import org.easymock.IMocksControl;
+import org.easymock.classextension.EasyMock;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.ImportRegistration;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class RenoteServiceAdminCoreTest {
+
+ @Test
+ public void dontExportOwnServiceProxies(){
+
+ IMocksControl c = EasyMock.createNiceControl();
+ Bundle b = c.createMock(Bundle.class);
+ BundleContext bc = c.createMock(BundleContext.class);
+
+ EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
+
+ ServiceReference sref = c.createMock(ServiceReference.class);
+ EasyMock.expect(sref.getBundle()).andReturn(b).anyTimes();
+
+ RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc);
+
+
+ c.replay();
+
+
+ // must return null as sref if from the same bundle
+ assertNull(rsaCore.exportService(sref, null));
+
+ // must be empty ...
+ assertEquals(rsaCore.getExportedServices().size(),0);
+
+ c.verify();
+
+ }
+
+
+ @Test
+ public void testImport(){
+
+ IMocksControl c = EasyMock.createNiceControl();
+ Bundle b = c.createMock(Bundle.class);
+ BundleContext bc = c.createMock(BundleContext.class);
+
+ EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
+ EasyMock.expect(b.getSymbolicName()).andReturn("BundleName").anyTimes();
+
+ RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc){
+ @Override
+ protected void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl imReg,
+ ConfigurationTypeHandler handler,
+ BundleContext requestingContext) {
+
+
+
+ }
+ };
+
+ Map p = new HashMap();
+ p.put(RemoteConstants.ENDPOINT_URI, "http://google.de");
+
+ EndpointDescription endpoint = new EndpointDescription(p);
+
+
+ c.replay();
+
+ // must be null as the endpoint doesn't contain any usable configurations
+ assertNull(rsaCore.importService(endpoint));
+ // must be empty ...
+ assertEquals(rsaCore.getImportedEndpoints().size(),0);
+
+
+ p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "org.apache.cxf.ws");
+ endpoint = new EndpointDescription(p);
+
+ // must be null as the endpoint has no interface
+ assertNull(rsaCore.importService(endpoint));
+ // must be empty ...
+ assertEquals(rsaCore.getImportedEndpoints().size(),0);
+
+
+ p.put(Constants.OBJECTCLASS, new String[] {"es.schaaf.my.class"});
+ endpoint = new EndpointDescription(p);
+
+
+ ImportRegistration ireg = rsaCore.importService(endpoint);
+ assertNotNull(ireg);
+
+ assertEquals(rsaCore.getImportedEndpoints().size(),1);
+
+
+ // lets import the same endpoint once more -> should get a copy of the ImportRegistration
+ ImportRegistration ireg2 = rsaCore.importService(endpoint);
+ assertNotNull(ireg2);
+ assertEquals(rsaCore.getImportedEndpoints().size(),1);
+
+ assertEquals(ireg,(rsaCore.getImportedEndpoints().toArray())[0]);
+
+ assertEquals(ireg.getImportReference().getImportedEndpoint(),ireg2.getImportReference().getImportedEndpoint());
+
+
+ // remove the registration ....
+
+ // first call shouldn't remove the import ...
+ ireg2.close();
+ assertEquals(1,rsaCore.getImportedEndpoints().size());
+
+ // second call should really close and remove the import ...
+ ireg.close();
+ assertEquals(0,rsaCore.getImportedEndpoints().size());
+
+
+ c.verify();
+
+
+ }
+}
Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RenoteServiceAdminCoreTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RenoteServiceAdminCoreTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date