http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/common/src/test/java/org/apache/cxf/dosgi/common/qos/IntentMapTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/qos/IntentMapTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/qos/IntentMapTest.java new file mode 100644 index 0000000..1bda059 --- /dev/null +++ b/common/src/test/java/org/apache/cxf/dosgi/common/qos/IntentMapTest.java @@ -0,0 +1,42 @@ +/** + * 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.common.qos; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.cxf.dosgi.common.intent.IntentMap; +import org.junit.Assert; +import org.junit.Test; + +public class IntentMapTest { + + @Test + public void inheritanceTest() { + Map<String, Object> defaultMap = new HashMap<String, Object>(); + defaultMap.put("key1", "defaultValue"); + IntentMap intentMap = new IntentMap(defaultMap); + Assert.assertEquals("defaultValue", intentMap.get("key1")); + intentMap.put("key1", "overridden"); + Assert.assertEquals("overridden", intentMap.get("key1")); + Object curValue = intentMap.remove("key1"); + Assert.assertEquals("overridden", curValue); + Assert.assertEquals("defaultValue", intentMap.get("key1")); + } +}
http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/common/src/test/java/org/apache/cxf/dosgi/common/qos/IntentTrackerTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/qos/IntentTrackerTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/qos/IntentTrackerTest.java new file mode 100644 index 0000000..b1efd62 --- /dev/null +++ b/common/src/test/java/org/apache/cxf/dosgi/common/qos/IntentTrackerTest.java @@ -0,0 +1,82 @@ +/** + * 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.common.qos; + +import static org.easymock.EasyMock.expect; + +import org.apache.cxf.dosgi.common.intent.IntentManager; +import org.apache.cxf.dosgi.common.intent.IntentMap; +import org.apache.cxf.dosgi.common.intent.IntentTracker; +import org.apache.cxf.feature.AbstractFeature; +import org.easymock.Capture; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; +import org.junit.Assert; +import org.junit.Test; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Filter; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; + +public class IntentTrackerTest { + + private static final String MY_INTENT_NAME = "myIntent"; + + @Test + public void testIntentAsService() throws InvalidSyntaxException { + IMocksControl c = EasyMock.createControl(); + BundleContext bc = c.createMock(BundleContext.class); + Filter filter = c.createMock(Filter.class); + expect(bc.createFilter(EasyMock.<String>anyObject())).andReturn(filter); + final Capture<ServiceListener> capturedListener = EasyMock.newCapture(); + bc.addServiceListener(EasyMock.capture(capturedListener), EasyMock.<String>anyObject()); + EasyMock.expectLastCall().atLeastOnce(); + expect(bc.getServiceReferences(EasyMock.<String>anyObject(), + EasyMock.<String>anyObject())).andReturn(new ServiceReference[]{}); + IntentMap intentMap = new IntentMap(); + + // Create a custom intent + @SuppressWarnings("unchecked") + ServiceReference<AbstractFeature> reference = c.createMock(ServiceReference.class); + expect(reference.getProperty(IntentManager.INTENT_NAME_PROP)).andReturn(MY_INTENT_NAME); + AbstractFeature testIntent = new AbstractFeature() { + }; + expect(bc.getService(reference)).andReturn(testIntent).atLeastOnce(); + + c.replay(); + + IntentTracker tracker = new IntentTracker(bc, intentMap); + tracker.open(); + + Assert.assertFalse("IntentMap should not contain " + MY_INTENT_NAME, intentMap.containsKey(MY_INTENT_NAME)); + ServiceListener listener = capturedListener.getValue(); + + // Simulate adding custom intent service + ServiceEvent event = new ServiceEvent(ServiceEvent.REGISTERED, reference); + listener.serviceChanged(event); + + // our custom intent should now be available + Assert.assertTrue("IntentMap should contain " + MY_INTENT_NAME, intentMap.containsKey(MY_INTENT_NAME)); + Assert.assertEquals(testIntent, intentMap.get(MY_INTENT_NAME)); + + c.verify(); + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/common/src/test/java/org/apache/cxf/dosgi/common/util/ClassUtilsTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/util/ClassUtilsTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/util/ClassUtilsTest.java new file mode 100644 index 0000000..233a18a --- /dev/null +++ b/common/src/test/java/org/apache/cxf/dosgi/common/util/ClassUtilsTest.java @@ -0,0 +1,114 @@ +/** + * 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.common.util; + +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.easymock.EasyMock; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; + +import junit.framework.TestCase; + +public class ClassUtilsTest extends TestCase { + + public void testLoadProvidersAsString() throws Exception { + BundleContext bc = mockBundleContext(); + Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", Provider.class.getName()); + List<Object> providers = ClassUtils.loadProviderClasses(bc, sd, "providers"); + assertEquals(1, providers.size()); + assertTrue(providers.get(0) instanceof Provider); + } + + public void testLoadProvidersAsStringArray() throws Exception { + BundleContext bc = mockBundleContext(); + Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", + new String[]{Provider.class.getName()}); + List<Object> providers = ClassUtils.loadProviderClasses(bc, sd, "providers"); + assertEquals(1, providers.size()); + assertTrue(providers.get(0) instanceof Provider); + } + + public void testLoadProvidersAsObject() throws Exception { + Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", new Provider()); + List<Object> providers = ClassUtils.loadProviderClasses(null, sd, "providers"); + assertEquals(1, providers.size()); + assertTrue(providers.get(0) instanceof Provider); + } + + public void testLoadProvidersAsObjectArray() throws Exception { + Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", new Object[]{new Provider()}); + List<Object> providers = ClassUtils.loadProviderClasses(null, sd, "providers"); + assertEquals(1, providers.size()); + assertTrue(providers.get(0) instanceof Provider); + } + + public void testLoadProvidersAsObjectList() throws Exception { + List<Object> list = new LinkedList<Object>(); + list.add(new Provider()); + Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", list); + List<Object> providers = ClassUtils.loadProviderClasses(null, sd, "providers"); + assertEquals(1, providers.size()); + assertTrue(providers.get(0) instanceof Provider); + } + + public void testLoadProvidersAsStringList() throws Exception { + List<Object> list = new LinkedList<Object>(); + list.add(Provider.class.getName()); + Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", list); + List<Object> providers = ClassUtils.loadProviderClasses(mockBundleContext(), sd, "providers"); + assertEquals(1, providers.size()); + assertTrue(providers.get(0) instanceof Provider); + } + + private BundleContext mockBundleContext() throws Exception { + BundleContext bc = EasyMock.createMock(BundleContext.class); + Bundle bundle = EasyMock.createMock(Bundle.class); + bc.getBundle(); + EasyMock.expectLastCall().andReturn(bundle); + bundle.loadClass(Provider.class.getName()); + EasyMock.expectLastCall().andReturn(Provider.class); + EasyMock.replay(bc, bundle); + return bc; + } + + @SuppressWarnings({ "serial", "rawtypes" }) + private static class MyMapSubclass extends HashMap { + } + + @SuppressWarnings("serial") + static class MySubclassOne extends MyMapSubclass { + } + + @SuppressWarnings("serial") + static class MySubclassTwo extends MySubclassOne { + } + + @SuppressWarnings("serial") + static class MySubclassThree extends MySubclassTwo { + } + + @SuppressWarnings("serial") + static class MySubclassFour extends MySubclassThree { + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/common/src/test/java/org/apache/cxf/dosgi/common/util/OsgiUtilsTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/util/OsgiUtilsTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/util/OsgiUtilsTest.java new file mode 100644 index 0000000..9aabeef --- /dev/null +++ b/common/src/test/java/org/apache/cxf/dosgi/common/util/OsgiUtilsTest.java @@ -0,0 +1,70 @@ +/** + * 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.common.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.osgi.service.remoteserviceadmin.EndpointDescription; +import org.osgi.service.remoteserviceadmin.RemoteConstants; + +import junit.framework.TestCase; + +public class OsgiUtilsTest extends TestCase { + + public void testMultiValuePropertyAsString() { + assertEquals(Collections.singleton("hi"), + OsgiUtils.getMultiValueProperty("hi")); + } + + public void testMultiValuePropertyAsArray() { + assertEquals(Arrays.asList("a", "b"), + OsgiUtils.getMultiValueProperty(new String[] {"a", "b"})); + } + + public void testMultiValuePropertyAsCollection() { + List<String> list = new ArrayList<String>(); + list.add("1"); + list.add("2"); + list.add("3"); + assertEquals(list, OsgiUtils.getMultiValueProperty(list)); + } + + public void testMultiValuePropertyNull() { + assertNull(OsgiUtils.getMultiValueProperty(null)); + } + + public void testGetProperty() { + Map<String, Object> p = new HashMap<String, Object>(); + p.put(RemoteConstants.ENDPOINT_ID, "http://google.de"); + p.put("notAString", new Object()); + p.put(org.osgi.framework.Constants.OBJECTCLASS, new String[]{"my.class"}); + p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, new String[]{"my.config"}); + + EndpointDescription endpoint = new EndpointDescription(p); + + assertNull(OsgiUtils.getProperty(endpoint, "unknownProp")); + assertEquals(p.get(RemoteConstants.ENDPOINT_ID), OsgiUtils.getProperty(endpoint, RemoteConstants.ENDPOINT_ID)); + assertEquals(null, OsgiUtils.getProperty(endpoint, "notAString")); + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/common/src/test/java/org/apache/cxf/dosgi/common/util/Provider.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/util/Provider.java b/common/src/test/java/org/apache/cxf/dosgi/common/util/Provider.java new file mode 100644 index 0000000..baec66d --- /dev/null +++ b/common/src/test/java/org/apache/cxf/dosgi/common/util/Provider.java @@ -0,0 +1,23 @@ +/** + * 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.common.util; + + +public class Provider { +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/bnd.bnd ---------------------------------------------------------------------- diff --git a/cxf-dsw/bnd.bnd b/cxf-dsw/bnd.bnd index b0ee3dc..017457a 100644 --- a/cxf-dsw/bnd.bnd +++ b/cxf-dsw/bnd.bnd @@ -1,3 +1,2 @@ Import-Package: javax.servlet;version='[2,4)', javax.servlet.http;version='[2,4)', * -Private-Package: org.apache.cxf.dosgi.dsw.* -Bundle-Activator: org.apache.cxf.dosgi.dsw.osgi.Activator + http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/pom.xml ---------------------------------------------------------------------- diff --git a/cxf-dsw/pom.xml b/cxf-dsw/pom.xml index 091dce9..d3f54aa 100644 --- a/cxf-dsw/pom.xml +++ b/cxf-dsw/pom.xml @@ -37,6 +37,12 @@ <dependencies> <dependency> + <groupId>org.apache.cxf.dosgi</groupId> + <artifactId>cxf-dosgi-ri-common</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-core</artifactId> <version>${cxf.version}</version> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java index 638e6ca..49ee272 100644 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java @@ -18,10 +18,14 @@ */ package org.apache.cxf.dosgi.dsw.handlers; +import static org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED; +import static org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_INTENTS_SUPPORTED; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Dictionary; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -30,47 +34,84 @@ import java.util.Set; import org.apache.aries.rsa.spi.DistributionProvider; import org.apache.aries.rsa.spi.Endpoint; import org.apache.aries.rsa.spi.IntentUnsatisfiedException; +import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.common.intent.IntentManager; +import org.apache.cxf.dosgi.common.util.OsgiUtils; +import org.apache.cxf.dosgi.common.util.StringPlus; import org.apache.cxf.dosgi.dsw.handlers.pojo.PojoConfigurationTypeHandler; import org.apache.cxf.dosgi.dsw.handlers.pojo.WsdlConfigurationTypeHandler; import org.apache.cxf.dosgi.dsw.handlers.rest.JaxRSPojoConfigurationTypeHandler; -import org.apache.cxf.dosgi.dsw.httpservice.HttpServiceManager; import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.apache.cxf.dosgi.dsw.qos.IntentManager; -import org.apache.cxf.dosgi.dsw.util.OsgiUtils; -import org.apache.cxf.dosgi.dsw.util.StringPlus; import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.osgi.service.remoteserviceadmin.EndpointDescription; import org.osgi.service.remoteserviceadmin.RemoteConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +@Component(configurationPid = "cxf-dsw", property = // +{// + REMOTE_CONFIGS_SUPPORTED + "=" + Constants.WS_CONFIG_TYPE, + REMOTE_CONFIGS_SUPPORTED + "=" + Constants.WSDL_CONFIG_TYPE, + REMOTE_CONFIGS_SUPPORTED + "=" + Constants.RS_CONFIG_TYPE, + REMOTE_CONFIGS_SUPPORTED + "=" + Constants.WS_CONFIG_TYPE_OLD, + REMOTE_INTENTS_SUPPORTED + "=" +}) public class CXFDistributionProvider implements DistributionProvider { + public static final String[] SUPPORTED_CONFIGS = new String[] // + {// + Constants.WS_CONFIG_TYPE, Constants.WSDL_CONFIG_TYPE, Constants.RS_CONFIG_TYPE, + Constants.WS_CONFIG_TYPE_OLD + }; protected static final String DEFAULT_CONFIGURATION_TYPE = Constants.WS_CONFIG_TYPE; private static final Logger LOG = LoggerFactory.getLogger(CXFDistributionProvider.class); - // protected because of tests - protected final String[] supportedConfigurationTypes; private IntentManager intentManager; private PojoConfigurationTypeHandler pojoConfigurationTypeHandler; private JaxRSPojoConfigurationTypeHandler jaxRsPojoConfigurationTypeHandler; private WsdlConfigurationTypeHandler wsdlConfigurationTypeHandler; private Set<String> configTypesSet; + private HttpServiceManager httpServiceManager; + + public CXFDistributionProvider() { + configTypesSet = new HashSet<>(Arrays.asList(SUPPORTED_CONFIGS)); + } - public CXFDistributionProvider(BundleContext bc, IntentManager intentManager, - HttpServiceManager httpServiceManager) { + @Reference + public void setHttpServiceManager(HttpServiceManager httpServiceManager) { + this.httpServiceManager = httpServiceManager; + } + + @Reference + public void setIntentManager(IntentManager intentManager) { this.intentManager = intentManager; + } + + @SuppressWarnings("unchecked") + @Activate + public synchronized void activate(ComponentContext compContext) { + Dictionary<String, Object> config = compContext.getProperties(); + init(compContext.getBundleContext(), config); + // String[] supportedIntents = intentMap.keySet().toArray(new String[] {}); + // props.put(Constants.REMOTE_INTENTS_SUPPORTED, supportedIntents); + } + + void init(BundleContext bc, Dictionary<String, Object> config) { + // Disable the fast infoset as it's not compatible (yet) with OSGi + System.setProperty("org.apache.cxf.nofastinfoset", "true"); + LOG.debug("RemoteServiceAdmin Implementation is starting up with {}", config); + System.setProperty("org.apache.cxf.nofastinfoset", "true"); this.pojoConfigurationTypeHandler = new PojoConfigurationTypeHandler(bc, intentManager, httpServiceManager); this.jaxRsPojoConfigurationTypeHandler = new JaxRSPojoConfigurationTypeHandler(bc, intentManager, httpServiceManager); this.wsdlConfigurationTypeHandler = new WsdlConfigurationTypeHandler(bc, intentManager, httpServiceManager); - supportedConfigurationTypes = new String[] {Constants.WS_CONFIG_TYPE, - Constants.WSDL_CONFIG_TYPE, - Constants.RS_CONFIG_TYPE, - Constants.WS_CONFIG_TYPE_OLD}; - configTypesSet = new HashSet<>(Arrays.asList(supportedConfigurationTypes)); } @SuppressWarnings("rawtypes") @@ -164,7 +205,7 @@ public class CXFDistributionProvider implements DistributionProvider { List<String> remoteConfigurationTypes = endpoint.getConfigurationTypes(); List<String> usableConfigurationTypes = new ArrayList<String>(); - for (String ct : supportedConfigurationTypes) { + for (String ct : SUPPORTED_CONFIGS) { if (remoteConfigurationTypes.contains(ct)) { usableConfigurationTypes.add(ct); } @@ -176,7 +217,7 @@ public class CXFDistributionProvider implements DistributionProvider { } public String[] getSupportedTypes() { - return supportedConfigurationTypes; + return SUPPORTED_CONFIGS; } } http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/AbstractPojoConfigurationTypeHandler.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/AbstractPojoConfigurationTypeHandler.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/AbstractPojoConfigurationTypeHandler.java index aa543e0..50baf0a 100644 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/AbstractPojoConfigurationTypeHandler.java +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/AbstractPojoConfigurationTypeHandler.java @@ -20,6 +20,8 @@ package org.apache.cxf.dosgi.dsw.handlers.pojo; import java.lang.reflect.Proxy; import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -30,14 +32,13 @@ import org.apache.aries.rsa.spi.Endpoint; import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; import org.apache.cxf.common.util.PackageUtils; -import org.apache.cxf.dosgi.dsw.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.common.intent.IntentManager; +import org.apache.cxf.dosgi.common.util.ClassUtils; +import org.apache.cxf.dosgi.common.util.OsgiUtils; +import org.apache.cxf.dosgi.common.util.ServerWrapper; +import org.apache.cxf.dosgi.common.util.StringPlus; import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.apache.cxf.dosgi.dsw.qos.IntentManager; -import org.apache.cxf.dosgi.dsw.qos.IntentUtils; -import org.apache.cxf.dosgi.dsw.util.ClassUtils; -import org.apache.cxf.dosgi.dsw.util.OsgiUtils; -import org.apache.cxf.dosgi.dsw.util.ServerWrapper; -import org.apache.cxf.dosgi.dsw.util.StringPlus; import org.apache.cxf.endpoint.AbstractEndpointFactory; import org.apache.cxf.endpoint.Server; import org.apache.cxf.feature.AbstractFeature; @@ -84,11 +85,30 @@ public abstract class AbstractPojoConfigurationTypeHandler implements Distributi } } String[] sIntents = StringPlus.normalize(props.get(RemoteConstants.SERVICE_INTENTS)); - String[] allIntents = IntentUtils.mergeArrays(intents, sIntents); + String[] allIntents = mergeArrays(intents, sIntents); props.put(RemoteConstants.SERVICE_INTENTS, allIntents); props.put(RemoteConstants.ENDPOINT_ID, address); return new EndpointDescription(props); } + + 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); + Collections.addAll(list, a1); + for (String s : a2) { + if (!list.contains(s)) { + list.add(s); + } + } + + return list.toArray(new String[list.size()]); + } protected void setCommonWsdlProperties(AbstractWSDLBasedEndpointFactory factory, BundleContext context, Map<String, Object> sd, boolean wsdlType) { http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandler.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandler.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandler.java index a0784fb..aa49f99 100644 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandler.java +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandler.java @@ -27,9 +27,9 @@ import org.apache.aries.rsa.spi.IntentUnsatisfiedException; import org.apache.cxf.Bus; import org.apache.cxf.aegis.databinding.AegisDatabinding; import org.apache.cxf.databinding.DataBinding; -import org.apache.cxf.dosgi.dsw.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.common.intent.IntentManager; import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.apache.cxf.dosgi.dsw.qos.IntentManager; import org.apache.cxf.frontend.ClientProxyFactoryBean; import org.apache.cxf.frontend.ServerFactoryBean; import org.apache.cxf.jaxb.JAXBDataBinding; http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/WsdlConfigurationTypeHandler.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/WsdlConfigurationTypeHandler.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/WsdlConfigurationTypeHandler.java index b818354..7e7ad44 100644 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/WsdlConfigurationTypeHandler.java +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/pojo/WsdlConfigurationTypeHandler.java @@ -29,10 +29,10 @@ import org.apache.aries.rsa.spi.Endpoint; import org.apache.cxf.Bus; import org.apache.cxf.common.util.PackageUtils; import org.apache.cxf.databinding.DataBinding; -import org.apache.cxf.dosgi.dsw.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.common.intent.IntentManager; +import org.apache.cxf.dosgi.common.util.OsgiUtils; import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.apache.cxf.dosgi.dsw.qos.IntentManager; -import org.apache.cxf.dosgi.dsw.util.OsgiUtils; import org.apache.cxf.jaxb.JAXBDataBinding; import org.apache.cxf.jaxws.JaxWsServerFactoryBean; import org.osgi.framework.BundleContext; http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSPojoConfigurationTypeHandler.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSPojoConfigurationTypeHandler.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSPojoConfigurationTypeHandler.java index 49e9d39..385993d 100644 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSPojoConfigurationTypeHandler.java +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSPojoConfigurationTypeHandler.java @@ -26,12 +26,12 @@ import org.apache.aries.rsa.spi.Endpoint; import org.apache.aries.rsa.spi.IntentUnsatisfiedException; import org.apache.cxf.Bus; import org.apache.cxf.common.util.ProxyClassLoader; +import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.common.intent.IntentManager; +import org.apache.cxf.dosgi.common.util.OsgiUtils; +import org.apache.cxf.dosgi.common.util.ServerWrapper; import org.apache.cxf.dosgi.dsw.handlers.pojo.AbstractPojoConfigurationTypeHandler; -import org.apache.cxf.dosgi.dsw.httpservice.HttpServiceManager; import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.apache.cxf.dosgi.dsw.qos.IntentManager; -import org.apache.cxf.dosgi.dsw.util.OsgiUtils; -import org.apache.cxf.dosgi.dsw.util.ServerWrapper; import org.apache.cxf.endpoint.Server; import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; import org.apache.cxf.jaxrs.client.Client; http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSUtils.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSUtils.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSUtils.java index c03a29f..e8f0a75 100644 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSUtils.java +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSUtils.java @@ -24,8 +24,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.apache.cxf.dosgi.dsw.util.ClassUtils; -import org.apache.cxf.dosgi.dsw.util.OsgiUtils; +import org.apache.cxf.dosgi.common.util.ClassUtils; +import org.apache.cxf.dosgi.common.util.OsgiUtils; import org.apache.cxf.jaxrs.model.UserResource; import org.apache.cxf.jaxrs.provider.aegis.AegisElementProvider; import org.apache.cxf.jaxrs.utils.ResourceUtils; http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManager.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManager.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManager.java deleted file mode 100644 index f6ebda1..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManager.java +++ /dev/null @@ -1,176 +0,0 @@ -/** - * 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.httpservice; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Map; - -import org.apache.cxf.Bus; -import org.apache.cxf.transport.http.DestinationRegistry; -import org.apache.cxf.transport.http.DestinationRegistryImpl; -import org.apache.cxf.transport.servlet.CXFNonSpringServlet; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.ServiceException; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; -import org.osgi.service.http.HttpContext; -import org.osgi.service.http.HttpService; -import org.osgi.util.tracker.ServiceTracker; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HttpServiceManager { - - private static final Logger LOG = LoggerFactory.getLogger(HttpServiceManager.class); - private static final long SERVICE_LOOKUP_TIMEOUT = 10000; - private ServiceTracker<HttpService, HttpService> tracker; - private BundleContext bundleContext; - private Map<Long, String> exportedAliases = Collections.synchronizedMap(new HashMap<Long, String>()); - private String httpBase; - private String cxfServletAlias; - - public HttpServiceManager(BundleContext bundleContext, String httpBase, String cxfServletAlias) { - this(bundleContext, httpBase, cxfServletAlias, - new ServiceTracker<HttpService, HttpService>(bundleContext, HttpService.class, null)); - this.tracker.open(); - } - - // Only for tests - public HttpServiceManager(BundleContext bundleContext, - String httpBase, String cxfServletAlias, - ServiceTracker<HttpService, HttpService> tracker) { - this.bundleContext = bundleContext; - this.tracker = tracker; - this.httpBase = getWithDefault(httpBase, "http://" + LocalHostUtil.getLocalIp() + ":8181"); - this.cxfServletAlias = getWithDefault(cxfServletAlias, "/cxf"); - } - - private String getWithDefault(String value, String defaultValue) { - return value == null ? defaultValue : value; - } - - public Bus registerServlet(Bus bus, String contextRoot, BundleContext callingContext, Long sid) { - bus.setExtension(new DestinationRegistryImpl(), DestinationRegistry.class); - CXFNonSpringServlet cxf = new CXFNonSpringServlet(); - cxf.setBus(bus); - try { - HttpService httpService = getHttpService(); - httpService.registerServlet(contextRoot, cxf, new Hashtable<String, String>(), - getHttpContext(callingContext, httpService)); - - registerUnexportHook(sid, contextRoot); - - LOG.info("Successfully registered CXF DOSGi servlet at " + contextRoot); - } catch (Exception e) { - throw new ServiceException("CXF DOSGi: problem registering CXF HTTP Servlet", e); - } - return bus; - } - - protected HttpService getHttpService() { - HttpService service = null; - try { - service = tracker.waitForService(SERVICE_LOOKUP_TIMEOUT); - } catch (InterruptedException ex) { - LOG.warn("waitForService interrupeted", ex); - } - if (service == null) { - throw new RuntimeException("No HTTPService found"); - } - return service; - } - - private HttpContext getHttpContext(BundleContext bc, HttpService httpService) { - HttpContext httpContext = httpService.createDefaultHttpContext(); - return new SecurityDelegatingHttpContext(bc, httpContext); - } - - /** - * This listens for service removal events and "un-exports" the service - * from the HttpService. - * - * @param sref the service reference to track - * @param alias the HTTP servlet context alias - */ - private void registerUnexportHook(Long sid, String alias) { - LOG.debug("Registering service listener for service with ID {}", sid); - - String previous = exportedAliases.put(sid, alias); - if (previous != null) { - LOG.warn("Overwriting service export for service with ID {}", sid); - } - - try { - Filter f = bundleContext.createFilter("(" + org.osgi.framework.Constants.SERVICE_ID + "=" + sid + ")"); - if (f != null) { - bundleContext.addServiceListener(new UnregisterListener(), f.toString()); - } else { - LOG.warn("Service listener could not be started. The service will not be automatically unexported."); - } - } catch (InvalidSyntaxException e) { - LOG.warn("Service listener could not be started. The service will not be automatically unexported.", e); - } - } - - public String getDefaultAddress(Class<?> type) { - return "/" + type.getName().replace('.', '/'); - } - - public String getAbsoluteAddress(String contextRoot, String relativeEndpointAddress) { - if (relativeEndpointAddress.startsWith("http")) { - return relativeEndpointAddress; - } - String effContextRoot = contextRoot == null ? cxfServletAlias : contextRoot; - return this.httpBase + effContextRoot + relativeEndpointAddress; - } - - public void close() { - tracker.close(); - } - - private final class UnregisterListener implements ServiceListener { - - public void serviceChanged(ServiceEvent event) { - if (!(event.getType() == ServiceEvent.UNREGISTERING)) { - return; - } - final ServiceReference<?> sref = event.getServiceReference(); - final Long sid = (Long) sref.getProperty(org.osgi.framework.Constants.SERVICE_ID); - final String alias = exportedAliases.remove(sid); - if (alias == null) { - LOG.error("Unable to unexport HTTP servlet for service class '{}'," - + " service-id {}: no servlet alias found", - sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS), sid); - return; - } - LOG.debug("Unexporting HTTP servlet for alias '{}'", alias); - try { - HttpService http = getHttpService(); - http.unregister(alias); - } catch (Exception e) { - LOG.warn("An exception occurred while unregistering service for HTTP servlet alias '{}'", alias, e); - } - } - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/LocalHostUtil.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/LocalHostUtil.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/LocalHostUtil.java deleted file mode 100644 index f2fefe9..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/LocalHostUtil.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * 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.httpservice; - -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; - -/** - * Utility methods to get the local address even on a linux host. - */ -final class LocalHostUtil { - - private LocalHostUtil() { - // Util Class - } - - /** - * Returns an InetAddress representing the address of the localhost. Every - * attempt is made to find an address for this host that is not the loopback - * address. If no other address can be found, the loopback will be returned. - * - * @return InetAddress the address of localhost - * @throws UnknownHostException if there is a problem determining the address - */ - public static InetAddress getLocalHost() throws UnknownHostException { - InetAddress localHost = InetAddress.getLocalHost(); - if (!localHost.isLoopbackAddress()) { - return localHost; - } - InetAddress[] addrs = getAllLocalUsingNetworkInterface(); - for (InetAddress addr : addrs) { - if (!addr.isLoopbackAddress() && !addr.getHostAddress().contains(":")) { - return addr; - } - } - return localHost; - } - - /** - * Utility method that delegates to the methods of NetworkInterface to - * determine addresses for this machine. - * - * @return all addresses found from the NetworkInterfaces - * @throws UnknownHostException if there is a problem determining addresses - */ - private static InetAddress[] getAllLocalUsingNetworkInterface() throws UnknownHostException { - try { - List<InetAddress> addresses = new ArrayList<InetAddress>(); - Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); - while (e.hasMoreElements()) { - NetworkInterface ni = e.nextElement(); - for (Enumeration<InetAddress> e2 = ni.getInetAddresses(); e2.hasMoreElements();) { - addresses.add(e2.nextElement()); - } - } - return addresses.toArray(new InetAddress[] {}); - } catch (SocketException ex) { - throw new UnknownHostException("127.0.0.1"); - } - } - - public static String getLocalIp() { - String localIP; - try { - localIP = getLocalHost().getHostAddress(); - } catch (Exception e) { - localIP = "localhost"; - } - return localIP; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContext.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContext.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContext.java deleted file mode 100644 index 042f2d5..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContext.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * 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.httpservice; - -import java.io.IOException; -import java.net.URL; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.service.http.HttpContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * <p> - * An HttpContext that delegates to another HttpContext for all things other than security. This implementation handles - * security by delegating to a {@link FilterChain} based on the set of {@link Filter}s registered with a - * {@link #FILTER_PROP} property. - * </p> - * <p> - * If the {@link BundleContext} contains a {@link #FILTER_REQUIRED_PROP} property with value "true", requests will not - * be allowed until at least one {@link Filter} with a {@link #FILTER_PROP} property is registered. - * </p> - */ -class SecurityDelegatingHttpContext implements HttpContext { - - public static final String FILTER_PROP = "org.apache.cxf.httpservice.filter"; - public static final String FILTER_REQUIRED_PROP = "org.apache.cxf.httpservice.requirefilter"; - private static final Logger LOG = LoggerFactory.getLogger(SecurityDelegatingHttpContext.class); - private static final String FILTER_FILTER = "(" + FILTER_PROP + "=*)"; - - BundleContext bundleContext; - HttpContext delegate; - boolean requireFilter; - - SecurityDelegatingHttpContext(BundleContext bundleContext, HttpContext delegate) { - this.bundleContext = bundleContext; - this.delegate = delegate; - requireFilter = Boolean.TRUE.toString().equalsIgnoreCase(bundleContext.getProperty(FILTER_REQUIRED_PROP)); - } - - public String getMimeType(String name) { - return delegate.getMimeType(name); - } - - public URL getResource(String name) { - return delegate.getResource(name); - } - - @SuppressWarnings({ - "unchecked", "rawtypes" - }) - public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException { - ServiceReference[] refs; - try { - refs = bundleContext.getServiceReferences(Filter.class.getName(), FILTER_FILTER); - } catch (InvalidSyntaxException e) { - LOG.warn(e.getMessage(), e); - return false; - } - if (refs == null || refs.length == 0) { - LOG.info("No filter registered."); - return !requireFilter; - } - Filter[] filters = new Filter[refs.length]; - try { - for (int i = 0; i < refs.length; i++) { - filters[i] = (Filter)bundleContext.getService(refs[i]); - } - try { - new Chain(filters).doFilter(request, response); - return !response.isCommitted(); - } catch (ServletException e) { - LOG.warn(e.getMessage(), e); - return false; - } - } finally { - for (int i = 0; i < refs.length; i++) { - if (filters[i] != null) { - bundleContext.ungetService(refs[i]); - } - } - } - } -} - -/** - * A {@link FilterChain} composed of {@link Filter}s with the - */ -class Chain implements FilterChain { - - private static final Logger LOG = LoggerFactory.getLogger(Chain.class); - - int current; - final Filter[] filters; - - Chain(Filter[] filters) { - this.filters = filters; - } - - public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { - if (current < filters.length && !response.isCommitted()) { - Filter filter = filters[current++]; - LOG.info("doFilter() on {}", filter); - filter.doFilter(request, response, this); - } - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Activator.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Activator.java deleted file mode 100644 index 13ef30f..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Activator.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * 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.osgi; - -import java.util.Dictionary; -import java.util.Hashtable; - -import org.apache.aries.rsa.spi.DistributionProvider; -import org.apache.cxf.Bus; -import org.apache.cxf.BusFactory; -import org.apache.cxf.dosgi.dsw.handlers.CXFDistributionProvider; -import org.apache.cxf.dosgi.dsw.httpservice.HttpServiceManager; -import org.apache.cxf.dosgi.dsw.qos.DefaultIntentMapFactory; -import org.apache.cxf.dosgi.dsw.qos.IntentManager; -import org.apache.cxf.dosgi.dsw.qos.IntentManagerImpl; -import org.apache.cxf.dosgi.dsw.qos.IntentMap; -import org.apache.cxf.dosgi.dsw.qos.IntentTracker; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleListener; -import org.osgi.framework.Constants; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.cm.ConfigurationException; -import org.osgi.service.cm.ManagedService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -// registered as spring bean -> start / stop called accordingly -public class Activator implements ManagedService, BundleActivator { - - private static final Logger LOG = LoggerFactory.getLogger(Activator.class); - private static final int DEFAULT_INTENT_TIMEOUT = 30000; - private static final String CONFIG_SERVICE_PID = "cxf-dsw"; - private ServiceRegistration<?> rsaFactoryReg; - private ServiceRegistration<?> decoratorReg; - private IntentTracker intentTracker; - private HttpServiceManager httpServiceManager; - private BundleContext bc; - private BundleListener bundleListener; - private Dictionary<String, Object> curConfiguration; - private Bus bus; - - public void start(BundleContext bundlecontext) throws Exception { - LOG.debug("RemoteServiceAdmin Implementation is starting up"); - this.bc = bundlecontext; - // Disable the fast infoset as it's not compatible (yet) with OSGi - System.setProperty("org.apache.cxf.nofastinfoset", "true"); - curConfiguration = getDefaultConfig(); - init(curConfiguration); - registerManagedService(bc); - } - - private Dictionary<String, Object> getDefaultConfig() { - return new Hashtable<String, Object>(); - } - - private synchronized void init(Dictionary<String, Object> config) { - bus = BusFactory.newInstance().createBus(); - - String httpBase = (String) config.get(org.apache.cxf.dosgi.dsw.osgi.Constants.HTTP_BASE); - String cxfServletAlias = (String) config.get(org.apache.cxf.dosgi.dsw.osgi.Constants.CXF_SERVLET_ALIAS); - - IntentMap intentMap = new IntentMap(new DefaultIntentMapFactory().create()); - intentTracker = new IntentTracker(bc, intentMap); - intentTracker.open(); - IntentManager intentManager = new IntentManagerImpl(intentMap, DEFAULT_INTENT_TIMEOUT); - httpServiceManager = new HttpServiceManager(bc, httpBase, cxfServletAlias); - DistributionProvider cxfProvider - = new CXFDistributionProvider(bc, intentManager, httpServiceManager); - Dictionary<String, Object> props = new Hashtable<String, Object>(); - String[] supportedIntents = intentMap.keySet().toArray(new String[] {}); - props.put(Constants.REMOTE_INTENTS_SUPPORTED, supportedIntents); - props.put(Constants.REMOTE_CONFIGS_SUPPORTED, cxfProvider.getSupportedTypes()); - rsaFactoryReg = bc.registerService(DistributionProvider.class.getName(), cxfProvider, props); - } - - private synchronized void uninit() { - if (decoratorReg != null) { - decoratorReg.unregister(); - decoratorReg = null; - } - if (bundleListener != null) { - bc.removeBundleListener(bundleListener); - bundleListener = null; - } - if (rsaFactoryReg != null) { - // This also triggers the unimport and unexport of the remote services - rsaFactoryReg.unregister(); - rsaFactoryReg = null; - } - if (httpServiceManager != null) { - httpServiceManager.close(); - httpServiceManager = null; - } - if (intentTracker != null) { - intentTracker.close(); - intentTracker = null; - } - } - - private void registerManagedService(BundleContext bundlecontext) { - Dictionary<String, String> props = new Hashtable<String, String>(); - props.put(Constants.SERVICE_PID, CONFIG_SERVICE_PID); - // No need to store the registration. Will be unregistered in stop by framework - bundlecontext.registerService(ManagedService.class.getName(), this, props); - } - - public void stop(BundleContext context) throws Exception { - LOG.debug("RemoteServiceAdmin Implementation is shutting down now"); - uninit(); - shutdownCXFBus(); - } - - /** - * Causes also the shutdown of the embedded HTTP server - */ - private void shutdownCXFBus() { - if (bus != null) { - LOG.debug("Shutting down the CXF Bus"); - bus.shutdown(true); - } - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public synchronized void updated(Dictionary config) throws ConfigurationException { - LOG.debug("RemoteServiceAdmin Implementation configuration is updated with {}", config); - // config is null if it doesn't exist, is being deleted or has not yet been loaded - // in which case we run with defaults (just like we do manually when bundle is first started) - Dictionary<String, Object> configMap = config == null ? getDefaultConfig() : config; - if (!configMap.equals(curConfiguration)) { // only if something actually changed - curConfiguration = configMap; - uninit(); - init(configMap); - } - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Constants.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Constants.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Constants.java index 87c2c21..5619b5f 100644 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Constants.java +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Constants.java @@ -18,36 +18,8 @@ */ package org.apache.cxf.dosgi.dsw.osgi; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - public final class Constants { - // Constants from RFC 119, they should ultimately be picked up from an OSGi class. - @Deprecated - public static final String EXPORTED_INTERFACES = RemoteConstants.SERVICE_EXPORTED_INTERFACES; - @Deprecated - public static final String EXPORTED_INTERFACES_OLD = "osgi.remote.interfaces"; // for BW compatibility - - @Deprecated - public static final String EXPORTED_CONFIGS = RemoteConstants.SERVICE_EXPORTED_CONFIGS; - @Deprecated - public static final String EXPORTED_CONFIGS_OLD = "osgi.remote.configuration.type"; // for BW compatibility - - @Deprecated - public static final String EXPORTED_INTENTS = RemoteConstants.SERVICE_EXPORTED_INTENTS; - @Deprecated - public static final String EXPORTED_INTENTS_EXTRA = RemoteConstants.SERVICE_EXPORTED_INTENTS_EXTRA; - @Deprecated - public static final String EXPORTED_INTENTS_OLD = "osgi.remote.requires.intents"; - - @Deprecated - public static final String IMPORTED = RemoteConstants.SERVICE_IMPORTED; - @Deprecated - public static final String IMPORTD_CONFIGS = RemoteConstants.SERVICE_IMPORTED_CONFIGS; - - @Deprecated - public static final String INTENTS = RemoteConstants.SERVICE_INTENTS; - // WSDL public static final String WSDL_CONFIG_TYPE = "wsdl"; public static final String WSDL_CONFIG_PREFIX = "osgi.remote.configuration" + "." + WSDL_CONFIG_TYPE; @@ -56,11 +28,9 @@ public final class Constants { public static final String WSDL_PORT_NAME = WSDL_CONFIG_PREFIX + ".port.name"; public static final String WSDL_LOCATION = WSDL_CONFIG_PREFIX + ".location"; public static final String WSDL_HTTP_SERVICE_CONTEXT = WSDL_CONFIG_PREFIX + ".httpservice.context"; - // Provider prefix - public static final String PROVIDER_PREFIX = "org.apache.cxf"; // WS - public static final String WS_CONFIG_TYPE = PROVIDER_PREFIX + ".ws"; + public static final String WS_CONFIG_TYPE = "org.apache.cxf" + ".ws"; public static final String WS_ADDRESS_PROPERTY = WS_CONFIG_TYPE + ".address"; public static final String WS_PORT_PROPERTY = WS_CONFIG_TYPE + ".port"; public static final String WS_HTTP_SERVICE_CONTEXT = WS_CONFIG_TYPE + ".httpservice.context"; @@ -85,8 +55,9 @@ public final class Constants { public static final String WS_WSDL_SERVICE_NAME = WS_CONFIG_TYPE + ".service.name"; public static final String WS_WSDL_PORT_NAME = WS_CONFIG_TYPE + ".port.name"; public static final String WS_WSDL_LOCATION = WS_CONFIG_TYPE + ".wsdl.location"; + // Rest - public static final String RS_CONFIG_TYPE = PROVIDER_PREFIX + ".rs"; + public static final String RS_CONFIG_TYPE = "org.apache.cxf" + ".rs"; public static final String RS_ADDRESS_PROPERTY = RS_CONFIG_TYPE + ".address"; public static final String RS_HTTP_SERVICE_CONTEXT = RS_CONFIG_TYPE + ".httpservice.context"; public static final String RS_DATABINDING_PROP_KEY = RS_CONFIG_TYPE + ".databinding"; @@ -100,46 +71,13 @@ public final class Constants { public static final String RS_PROVIDER_EXPECTED_PROP_KEY = RS_PROVIDER_PROP_KEY + ".expected"; public static final String RS_PROVIDER_GLOBAL_PROP_KEY = RS_PROVIDER_PROP_KEY + ".globalquery"; public static final String RS_WADL_LOCATION = RS_CONFIG_TYPE + ".wadl.location"; + // POJO (old value for WS) public static final String WS_CONFIG_TYPE_OLD = "pojo"; public static final String WS_CONFIG_OLD_PREFIX = "osgi.remote.configuration." + WS_CONFIG_TYPE_OLD; public static final String WS_ADDRESS_PROPERTY_OLD = WS_CONFIG_OLD_PREFIX + ".address"; public static final String WS_HTTP_SERVICE_CONTEXT_OLD = WS_CONFIG_OLD_PREFIX + ".httpservice.context"; - // Common Configuration Properties - public static final String CHECK_BUNDLE = "check.bundle"; - - // The following constants are not evaluated anymore - @Deprecated - public static final String DEFAULT_PORT_CONFIG = "default.port"; - @Deprecated - public static final String DEFAULT_HOST_CONFIG = "default.host"; - @Deprecated - public static final String DEFAULT_PORT_VALUE = "9000"; - @Deprecated - public static final String DEFAULT_HOST_VALUE = "localhost"; - @Deprecated - public static final String USE_MASTER_MAP = "use.master.map"; - - // DSW Identification - TODO do we really need this one? - public static final String DSW_CLIENT_ID = PROVIDER_PREFIX + ".remote.dsw.client"; - - public static final String INTENT_NAME_PROP = "org.apache.cxf.dosgi.IntentName"; - - /** - * Prefix to create an absolute URL from a relative URL. - * See HttpServiceManager.getAbsoluteAddress - * - * Defaults to: http://<host name>:8181 - */ - public static final String HTTP_BASE = "httpBase"; - - /** - * Name of the cxf servlet alias - */ - public static final String CXF_SERVLET_ALIAS = "cxfServletAlias"; - public static final String DEFAULT_CXF_SERVLET_ALIAS = "/cxf"; - private Constants() { // never constructed } http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/DefaultIntentMapFactory.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/DefaultIntentMapFactory.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/DefaultIntentMapFactory.java deleted file mode 100644 index 7e0dd2e..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/DefaultIntentMapFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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.qos; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.cxf.binding.soap.Soap11; -import org.apache.cxf.binding.soap.Soap12; -import org.apache.cxf.binding.soap.SoapBindingConfiguration; -import org.apache.cxf.binding.soap.SoapVersion; -import org.apache.cxf.feature.LoggingFeature; - -public class DefaultIntentMapFactory { - - public Map<String, Object> create() { - Map<String, Object> intentMap = new HashMap<String, Object>(); - intentMap.put("logging", getLoggingFeature()); - Object soap11 = getSoapBinding(Soap11.getInstance()); - intentMap.put("SOAP", soap11); - intentMap.put("SOAP.1_1", soap11); - intentMap.put("SOAP.1_2", getSoapBinding(Soap12.getInstance())); - intentMap.put("HTTP", "PROVIDED"); - return intentMap; - } - - private Object getLoggingFeature() { - return new LoggingFeature(); - } - - private Object getSoapBinding(SoapVersion soapVersion) { - SoapBindingConfiguration soapBindingConfig = new SoapBindingConfiguration(); - soapBindingConfig.setVersion(soapVersion); - return soapBindingConfig; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManager.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManager.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManager.java deleted file mode 100644 index ecaf070..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManager.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * 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.qos; - -import java.util.List; -import java.util.Map; - -import org.apache.cxf.endpoint.AbstractEndpointFactory; -import org.apache.cxf.feature.Feature; - -public interface IntentManager { - - String[] applyIntents(List<Feature> features, AbstractEndpointFactory factory, Map<String, Object> props); - void assertAllIntentsSupported(Map<String, Object> serviceProperties); -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java deleted file mode 100644 index e161ef0..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * 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.qos; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.aries.rsa.spi.IntentUnsatisfiedException; -import org.apache.cxf.binding.BindingConfiguration; -import org.apache.cxf.endpoint.AbstractEndpointFactory; -import org.apache.cxf.feature.Feature; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class IntentManagerImpl implements IntentManager { - - static final Logger LOG = LoggerFactory.getLogger(IntentManagerImpl.class); - private static final String PROVIDED_INTENT_VALUE = "PROVIDED"; - - private final IntentMap intentMap; - private final long maxIntentWaitTime; - - public IntentManagerImpl(IntentMap intentMap) { - this(intentMap, 0); - } - - public IntentManagerImpl(IntentMap intentMap, int maxIntentWaitTime) { - this.intentMap = intentMap; - this.maxIntentWaitTime = maxIntentWaitTime; - } - - public String[] applyIntents(List<Feature> features, AbstractEndpointFactory factory, - Map<String, Object> props) throws IntentUnsatisfiedException { - Set<String> requestedIntents = IntentUtils.getRequestedIntents(props); - Set<String> appliedIntents = new HashSet<String>(); - appliedIntents.addAll(reverseLookup(intentMap, PROVIDED_INTENT_VALUE)); - boolean bindingApplied = false; - for (String intentName : requestedIntents) { - bindingApplied |= processIntent(features, factory, intentName, intentMap.get(intentName)); - appliedIntents.add(intentName); - } - if (!bindingApplied) { - String defaultBindingName = "SOAP"; - processIntent(features, factory, defaultBindingName, intentMap.get(defaultBindingName)); - appliedIntents.add(defaultBindingName); - } - appliedIntents.addAll(addSynonymIntents(appliedIntents, intentMap)); - return appliedIntents.toArray(new String[appliedIntents.size()]); - } - - private boolean processIntent(List<Feature> features, AbstractEndpointFactory factory, - String intentName, Object intent) throws IntentUnsatisfiedException { - if (intent instanceof String) { - if (PROVIDED_INTENT_VALUE.equalsIgnoreCase((String) intent)) { - return false; - } - } else if (intent instanceof BindingConfiguration) { - BindingConfiguration bindingCfg = (BindingConfiguration)intent; - LOG.info("Applying intent: " + intentName + " via binding config: " + bindingCfg); - factory.setBindingConfig(bindingCfg); - return true; - } else if (intent instanceof Feature) { - Feature feature = (Feature) intent; - LOG.info("Applying intent: " + intentName + " via feature: " + feature); - features.add(feature); - return false; - } else { - LOG.info("No mapping for intent: " + intentName); - throw new IntentUnsatisfiedException(intentName); - } - return false; - } - - private static Collection<String> addSynonymIntents(Collection<String> appliedIntents, - IntentMap map) { - // E.g. SOAP and SOAP.1_1 are synonyms - List<Object> values = new ArrayList<Object>(); - for (String key : appliedIntents) { - values.add(map.get(key)); - } - return reverseLookup(map, values); - } - - private static Collection<String> reverseLookup(IntentMap im, Object obj) { - return reverseLookup(im, Collections.singleton(obj)); - } - - /** - * Retrieves all keys whose mapped values are found in the given collection. - * - * @param im an intent map - * @param values a collection of potential values - * @return all keys whose mapped values are found in the given collection - */ - private static Collection<String> reverseLookup(IntentMap im, Collection<?> values) { - Set<String> intentsFound = new HashSet<String>(); - for (Map.Entry<String, Object> entry : im.entrySet()) { - if (values.contains(entry.getValue())) { - intentsFound.add(entry.getKey()); - } - } - return intentsFound; - } - - public void assertAllIntentsSupported(Map<String, Object> serviceProperties) { - long endTime = System.currentTimeMillis() + maxIntentWaitTime; - Set<String> requiredIntents = IntentUtils.getRequestedIntents(serviceProperties); - List<String> unsupportedIntents = new ArrayList<String>(); - do { - unsupportedIntents.clear(); - for (String ri : requiredIntents) { - if (!intentMap.containsKey(ri)) { - unsupportedIntents.add(ri); - } - } - long remainingSeconds = (endTime - System.currentTimeMillis()) / 1000; - if (!unsupportedIntents.isEmpty() && remainingSeconds > 0) { - LOG.debug("Waiting for custom intents " + unsupportedIntents + " timeout in " + remainingSeconds); - try { - synchronized (intentMap) { - intentMap.wait(1000); - } - } catch (InterruptedException e) { - LOG.warn(e.getMessage(), e); - } - } - } while (!unsupportedIntents.isEmpty() && System.currentTimeMillis() < endTime); - - if (!unsupportedIntents.isEmpty()) { - throw new RuntimeException("service cannot be exported because the following " - + "intents are not supported by this RSA: " + unsupportedIntents); - } - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java deleted file mode 100644 index 5ed4ef6..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * 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.qos; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Maps intent names to intent objects - * An intent object can be a Feature, a BindingConfiguration or a String - * - * Also supports a default intent map. Custom intents can override the defaults - */ -public class IntentMap extends ConcurrentHashMap<String, Object> { - - private static final long serialVersionUID = 2606460607920520767L; - private Map<String, Object> defaultMap; - - public IntentMap() { - this(new HashMap<String, Object>()); - } - - public IntentMap(Map<String, Object> defaultMap) { - this.defaultMap = defaultMap; - putAll(defaultMap); - } - - @Override - public Object put(String key, Object value) { - Object result = super.put(key, value); - synchronized (this) { - notifyAll(); - } - return result; - } - - @Override - public Object remove(Object key) { - Object old = super.remove(key); - if (defaultMap.containsKey(key)) { - put((String)key, defaultMap.get(key)); - } - return old; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java deleted file mode 100644 index bdbe7c5..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * 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.qos; - -import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class IntentTracker extends ServiceTracker { - - private final IntentMap intentMap; - - - public IntentTracker(BundleContext context, IntentMap intentMap) { - super(context, getFilter(context), null); - this.intentMap = intentMap; - } - - static Filter getFilter(BundleContext context) { - try { - return context.createFilter("(" + Constants.INTENT_NAME_PROP + "=*)"); - } catch (InvalidSyntaxException e) { - throw new RuntimeException(e.getMessage(), e); - } - } - - @Override - public Object addingService(ServiceReference reference) { - String intentName = (String) reference.getProperty(Constants.INTENT_NAME_PROP); - Object intent = super.addingService(reference); - IntentManagerImpl.LOG.info("Adding custom intent " + intentName); - intentMap.put(intentName, intent); - return intent; - } - - @Override - public void removedService(ServiceReference reference, Object service) { - String intentName = (String) reference.getProperty(Constants.INTENT_NAME_PROP); - intentMap.remove(intentName); - super.removedService(reference, service); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java deleted file mode 100644 index 5ee288c..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * 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.qos; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.cxf.dosgi.dsw.osgi.Constants; -import org.apache.cxf.dosgi.dsw.util.OsgiUtils; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -public final class IntentUtils { - - private IntentUtils() { - // never constructed - } - - 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); - Collections.addAll(list, a1); - for (String s : a2) { - if (!list.contains(s)) { - list.add(s); - } - } - - return list.toArray(new String[list.size()]); - } - - public static Set<String> getRequestedIntents(Map<String, Object> sd) { - Collection<String> intents = OsgiUtils.getMultiValueProperty(sd.get(RemoteConstants.SERVICE_EXPORTED_INTENTS)); - Collection<String> intents2 - = OsgiUtils.getMultiValueProperty(sd.get(RemoteConstants.SERVICE_EXPORTED_INTENTS_EXTRA)); - @SuppressWarnings("deprecation") - Collection<String> oldIntents = OsgiUtils.getMultiValueProperty(sd.get(Constants.EXPORTED_INTENTS_OLD)); - Set<String> allIntents = new HashSet<String>(); - if (intents != null) { - allIntents.addAll(parseIntents(intents)); - } - if (intents2 != null) { - allIntents.addAll(parseIntents(intents2)); - } - if (oldIntents != null) { - allIntents.addAll(parseIntents(oldIntents)); - } - - return allIntents; - } - - private static Collection<String> parseIntents(Collection<String> intents) { - List<String> parsed = new ArrayList<String>(); - for (String intent : intents) { - parsed.addAll(Arrays.asList(intent.split("[ ]"))); - } - return parsed; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/d2a3c75f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java deleted file mode 100644 index cd1a323..0000000 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * 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.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.apache.cxf.helpers.CastUtils; -import org.osgi.framework.BundleContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class ClassUtils { - - private static final Logger LOG = LoggerFactory.getLogger(ClassUtils.class); - - private ClassUtils() { - } - - public static List<Object> loadProviderClasses(BundleContext callingContext, - Map<String, Object> sd, String propName) { - Object serviceProviders = sd.get(propName); - if (serviceProviders != null) { - if (serviceProviders.getClass().isArray()) { - if (serviceProviders.getClass().getComponentType() == String.class) { - return loadProviders(callingContext, (String[])serviceProviders); - } else { - return Arrays.asList((Object[])serviceProviders); - } - } else if (serviceProviders.getClass() == String.class) { - String[] classNames = serviceProviders.toString().split(","); - return loadProviders(callingContext, classNames); - } else if (serviceProviders instanceof List) { - List<Object> list = CastUtils.cast((List<?>)serviceProviders); - if (!list.isEmpty()) { - List<Object> providers; - if (list.get(0).getClass() == String.class) { - providers = loadProviders(callingContext, list.toArray(new String[]{})); - } else { - providers = list; - } - return providers; - } - } else { - return Arrays.asList(serviceProviders); - } - } - return Collections.emptyList(); - - } - - private static List<Object> loadProviders(BundleContext callingContext, String[] classNames) { - List<Object> providers = new ArrayList<Object>(); - for (String className : classNames) { - try { - String realName = className.trim(); - if (!realName.isEmpty()) { - Class<?> pClass = callingContext.getBundle().loadClass(realName); - providers.add(pClass.newInstance()); - } - } catch (Exception ex) { - LOG.warn("Provider " + className.trim() + " can not be loaded or created " + ex.getMessage(), ex); - } - } - return providers; - } -}
