[DOSGI-232] Remove code that moved to Aries-rsa and refer to it instead
Project: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/commit/1425743f Tree: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/tree/1425743f Diff: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/diff/1425743f Branch: refs/heads/master Commit: 1425743fb41db6c5ede9fba7a8872c73a835a80e Parents: 9ed37be Author: Christian Schneider <[email protected]> Authored: Fri Mar 11 23:53:28 2016 +0100 Committer: Christian Schneider <[email protected]> Committed: Fri Mar 11 23:53:28 2016 +0100 ---------------------------------------------------------------------- cxf-dsw/pom.xml | 155 +++++ .../org/apache/cxf/dosgi/dsw/Activator.java | 160 +++++ .../org/apache/cxf/dosgi/dsw/Constants.java | 146 +++++ .../dosgi/dsw/decorator/DecorationParser.java | 85 +++ .../cxf/dosgi/dsw/decorator/InterfaceRule.java | 96 +++ .../apache/cxf/dosgi/dsw/decorator/Rule.java | 41 ++ .../dosgi/dsw/decorator/ServiceDecorator.java | 28 + .../ServiceDecoratorBundleListener.java | 48 ++ .../dsw/decorator/ServiceDecoratorImpl.java | 97 +++ .../AbstractPojoConfigurationTypeHandler.java | 243 ++++++++ .../dsw/handlers/CXFDistributionProvider.java | 178 ++++++ .../cxf/dosgi/dsw/handlers/ClassUtils.java | 142 +++++ .../dosgi/dsw/handlers/HttpServiceManager.java | 176 ++++++ .../JaxRSPojoConfigurationTypeHandler.java | 201 +++++++ .../cxf/dosgi/dsw/handlers/JaxRSUtils.java | 121 ++++ .../cxf/dosgi/dsw/handlers/LocalHostUtil.java | 92 +++ .../handlers/PojoConfigurationTypeHandler.java | 172 ++++++ .../handlers/SecurityDelegatingHttpContext.java | 133 +++++ .../cxf/dosgi/dsw/handlers/ServerWrapper.java | 49 ++ .../dsw/handlers/ServiceInvocationHandler.java | 100 ++++ .../handlers/WsdlConfigurationTypeHandler.java | 160 +++++ .../dosgi/dsw/qos/DefaultIntentMapFactory.java | 52 ++ .../apache/cxf/dosgi/dsw/qos/IntentManager.java | 31 + .../cxf/dosgi/dsw/qos/IntentManagerImpl.java | 155 +++++ .../org/apache/cxf/dosgi/dsw/qos/IntentMap.java | 62 ++ .../apache/cxf/dosgi/dsw/qos/IntentTracker.java | 62 ++ .../apache/cxf/dosgi/dsw/qos/IntentUtils.java | 86 +++ .../apache/cxf/dosgi/dsw/util/OsgiUtils.java | 132 +++++ .../apache/cxf/dosgi/dsw/util/StringPlus.java | 72 +++ .../src/main/resources/service-decoration.xsd | 67 +++ .../org/apache/cxf/dosgi/dsw/ActivatorTest.java | 66 +++ .../org/apache/cxf/dosgi/dsw/TestUtils.java | 37 ++ .../dsw/decorator/DecorationParserTest.java | 63 ++ .../dosgi/dsw/decorator/InterfaceRuleTest.java | 163 +++++ .../ServiceDecoratorBundleListenerTest.java | 69 +++ .../dsw/decorator/ServiceDecoratorImplTest.java | 187 ++++++ .../handlers/CXFDistributionProviderTest.java | 104 ++++ .../cxf/dosgi/dsw/handlers/ClassUtilsTest.java | 134 +++++ .../dsw/handlers/HttpServiceManagerTest.java | 125 ++++ .../cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java | 195 ++++++ .../PojoConfigurationTypeHandlerTest.java | 422 +++++++++++++ .../SecurityDelegatingHttpContextTest.java | 267 +++++++++ .../handlers/ServiceInvocationHandlerTest.java | 75 +++ .../WsdlConfigurationTypeHandlerTest.java | 67 +++ .../dsw/handlers/jaxws/MyJaxWsEchoService.java | 26 + .../handlers/jaxws/MyJaxWsEchoServiceImpl.java | 27 + .../handlers/simple/MySimpleEchoService.java | 23 + .../simple/MySimpleEchoServiceImpl.java | 27 + .../dsw/hooks/CxfFindListenerHookTest.java | 341 +++++++++++ .../cxf/dosgi/dsw/hooks/CxfPublishHookTest.java | 299 ++++++++++ .../dosgi/dsw/hooks/ServiceHookUtilsTest.java | 116 ++++ .../apache/cxf/dosgi/dsw/hooks/TestService.java | 22 + .../dosgi/dsw/qos/IntentManagerImplTest.java | 278 +++++++++ .../apache/cxf/dosgi/dsw/qos/IntentMapTest.java | 41 ++ .../cxf/dosgi/dsw/qos/IntentTrackerTest.java | 80 +++ .../cxf/dosgi/dsw/qos/IntentUtilsTest.java | 70 +++ .../cxf/dosgi/dsw/util/OsgiUtilsTest.java | 152 +++++ .../org/apache/cxf/dosgi/dsw/util/Provider.java | 23 + .../remote-service/alt-remote-services.xml | 32 + .../OSGI-INF/remote-service/multi-services.xml | 38 ++ .../OSGI-INF/remote-service/remote-services.xml | 32 + .../src/test/resources/test-resources/rs1.xml | 31 + .../src/test/resources/test-resources/rs2.xml | 28 + .../src/test/resources/test-resources/sd-1.xml | 3 + .../src/test/resources/test-resources/sd.xml | 8 + .../src/test/resources/test-resources/sd0.xml | 2 + .../src/test/resources/test-resources/sd1.xml | 8 + .../src/test/resources/test-resources/sd2.xml | 14 + discovery/distributed/cxf-discovery/pom.xml | 120 ---- .../dosgi/discovery/zookeeper/Activator.java | 43 -- .../discovery/zookeeper/ZooKeeperDiscovery.java | 164 ------ .../zookeeper/publish/DiscoveryPlugin.java | 54 -- .../publish/PublishingEndpointListener.java | 216 ------- .../PublishingEndpointListenerFactory.java | 105 ---- .../subscribe/EndpointListenerTracker.java | 56 -- .../zookeeper/subscribe/InterfaceMonitor.java | 262 --------- .../subscribe/InterfaceMonitorManager.java | 218 ------- .../dosgi/discovery/zookeeper/util/Utils.java | 165 ------ .../zookeeper/DiscoveryDriverTest.java | 135 ----- .../FindInZooKeeperCustomizerTest.java | 301 ---------- .../InterfaceDataMonitorListenerImplTest.java | 183 ------ .../PublishingEndpointListenerFactoryTest.java | 100 ---- .../publish/PublishingEndpointListenerTest.java | 201 ------- .../subscribe/InterfaceMonitorManagerTest.java | 139 ----- .../subscribe/InterfaceMonitorTest.java | 67 --- .../discovery/zookeeper/util/UtilsTest.java | 110 ---- discovery/distributed/pom.xml | 42 -- .../distributed/zookeeper-server-config/pom.xml | 78 --- .../zookeeper/server/config/Activator.java | 110 ---- discovery/distributed/zookeeper-server/pom.xml | 114 ---- .../discovery/zookeeper/server/Activator.java | 44 -- .../dosgi/discovery/zookeeper/server/Utils.java | 108 ---- .../zookeeper/server/ZookeeperStarter.java | 164 ------ .../resources/OSGI-INF/metatype/zookeeper.xml | 34 -- .../zookeeper/server/ZookeeperStarterTest.java | 81 --- discovery/local/pom.xml | 99 ---- .../discovery/local/internal/Activator.java | 41 -- .../local/internal/LocalDiscovery.java | 242 -------- .../cxf/dosgi/discovery/local/util/Utils.java | 125 ---- .../EndpointDescriptionBundleParser.java | 104 ---- .../endpointdesc/EndpointDescriptionParser.java | 90 --- .../dosgi/endpointdesc/PropertiesMapper.java | 345 ----------- .../src/main/resources/endpoint-description.xsd | 61 -- .../discovery/local/internal/ActivatorTest.java | 52 -- .../local/internal/LocalDiscoveryTest.java | 409 ------------- .../EndpointDescriptionBundleParserTest.java | 138 ----- .../EndpointDescriptionParserTest.java | 49 -- .../endpointdesc/PropertiesMapperTest.java | 97 --- discovery/local/src/test/resources/ed1.xml | 72 --- .../local/src/test/resources/ed2-generated.xml | 54 -- discovery/local/src/test/resources/ed2.xml | 99 ---- discovery/local/src/test/resources/ed3.xml | 32 - discovery/local/src/test/resources/ed4.xml | 43 -- discovery/local/src/test/resources/sd.xml | 23 - discovery/local/src/test/resources/sd2.xml | 32 - discovery/pom.xml | 41 -- .../features/src/main/resources/features.xml | 33 +- distribution/multi-bundle/pom.xml | 5 +- dsw/cxf-dosgi-provider-api/pom.xml | 67 --- .../cxf/dosgi/dsw/api/DistributionProvider.java | 56 -- .../org/apache/cxf/dosgi/dsw/api/Endpoint.java | 27 - .../cxf/dosgi/dsw/api/EndpointHelper.java | 41 -- .../apache/cxf/dosgi/dsw/api/ExportPolicy.java | 46 -- .../dsw/api/IntentUnsatisfiedException.java | 35 -- dsw/cxf-dosgi-rsa/pom.xml | 73 --- .../apache/cxf/dosgi/dsw/service/Activator.java | 37 -- .../dosgi/dsw/service/ClientServiceFactory.java | 110 ---- .../service/DistributionProviderTracker.java | 73 --- .../cxf/dosgi/dsw/service/EventAdminHelper.java | 151 ----- .../cxf/dosgi/dsw/service/EventProducer.java | 114 ---- .../dosgi/dsw/service/ExportReferenceImpl.java | 77 --- .../dsw/service/ExportRegistrationImpl.java | 152 ----- .../dsw/service/ImportRegistrationImpl.java | 230 -------- .../cxf/dosgi/dsw/service/PackageUtil.java | 85 --- .../dsw/service/RemoteServiceAdminCore.java | 587 ------------------- .../dsw/service/RemoteServiceAdminInstance.java | 99 ---- .../dsw/service/RemoteServiceadminFactory.java | 51 -- .../cxf/dosgi/dsw/service/StringPlus.java | 72 --- .../dsw/service/ClientServiceFactoryTest.java | 92 --- .../DistributionProviderTrackerTest.java | 82 --- .../dosgi/dsw/service/EventProducerTest.java | 189 ------ .../dsw/service/ImportRegistrationImplTest.java | 178 ------ .../dsw/service/RemoteServiceAdminCoreTest.java | 517 ---------------- .../cxf/dosgi/dsw/service/StringPlusTest.java | 63 -- dsw/cxf-dosgi-tcp/pom.xml | 72 --- .../aries/rsa/provider/tcp/Activator.java | 45 -- .../provider/tcp/LoaderObjectInputStream.java | 43 -- .../aries/rsa/provider/tcp/LocalHostUtil.java | 92 --- .../aries/rsa/provider/tcp/TCPProvider.java | 67 --- .../aries/rsa/provider/tcp/TCPServer.java | 118 ---- .../aries/rsa/provider/tcp/TcpEndpoint.java | 58 -- .../rsa/provider/tcp/TcpInvocationHandler.java | 68 --- .../aries/rsa/provider/tcp/TcpProviderTest.java | 107 ---- .../rsa/provider/tcp/myservice/MyService.java | 30 - .../provider/tcp/myservice/MyServiceImpl.java | 36 -- dsw/cxf-dsw/pom.xml | 155 ----- .../org/apache/cxf/dosgi/dsw/Activator.java | 160 ----- .../org/apache/cxf/dosgi/dsw/Constants.java | 146 ----- .../dosgi/dsw/decorator/DecorationParser.java | 85 --- .../cxf/dosgi/dsw/decorator/InterfaceRule.java | 96 --- .../apache/cxf/dosgi/dsw/decorator/Rule.java | 41 -- .../dosgi/dsw/decorator/ServiceDecorator.java | 28 - .../ServiceDecoratorBundleListener.java | 48 -- .../dsw/decorator/ServiceDecoratorImpl.java | 97 --- .../AbstractPojoConfigurationTypeHandler.java | 243 -------- .../dsw/handlers/CXFDistributionProvider.java | 178 ------ .../cxf/dosgi/dsw/handlers/ClassUtils.java | 142 ----- .../dosgi/dsw/handlers/HttpServiceManager.java | 176 ------ .../JaxRSPojoConfigurationTypeHandler.java | 201 ------- .../cxf/dosgi/dsw/handlers/JaxRSUtils.java | 121 ---- .../cxf/dosgi/dsw/handlers/LocalHostUtil.java | 92 --- .../handlers/PojoConfigurationTypeHandler.java | 172 ------ .../handlers/SecurityDelegatingHttpContext.java | 133 ----- .../cxf/dosgi/dsw/handlers/ServerWrapper.java | 49 -- .../dsw/handlers/ServiceInvocationHandler.java | 100 ---- .../handlers/WsdlConfigurationTypeHandler.java | 160 ----- .../dosgi/dsw/qos/DefaultIntentMapFactory.java | 52 -- .../apache/cxf/dosgi/dsw/qos/IntentManager.java | 31 - .../cxf/dosgi/dsw/qos/IntentManagerImpl.java | 155 ----- .../org/apache/cxf/dosgi/dsw/qos/IntentMap.java | 62 -- .../apache/cxf/dosgi/dsw/qos/IntentTracker.java | 62 -- .../apache/cxf/dosgi/dsw/qos/IntentUtils.java | 86 --- .../apache/cxf/dosgi/dsw/util/OsgiUtils.java | 132 ----- .../apache/cxf/dosgi/dsw/util/StringPlus.java | 72 --- .../src/main/resources/service-decoration.xsd | 67 --- .../org/apache/cxf/dosgi/dsw/ActivatorTest.java | 66 --- .../org/apache/cxf/dosgi/dsw/TestUtils.java | 37 -- .../dsw/decorator/DecorationParserTest.java | 63 -- .../dosgi/dsw/decorator/InterfaceRuleTest.java | 163 ----- .../ServiceDecoratorBundleListenerTest.java | 69 --- .../dsw/decorator/ServiceDecoratorImplTest.java | 187 ------ .../handlers/CXFDistributionProviderTest.java | 104 ---- .../cxf/dosgi/dsw/handlers/ClassUtilsTest.java | 134 ----- .../dsw/handlers/HttpServiceManagerTest.java | 125 ---- .../cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java | 195 ------ .../PojoConfigurationTypeHandlerTest.java | 422 ------------- .../SecurityDelegatingHttpContextTest.java | 267 --------- .../handlers/ServiceInvocationHandlerTest.java | 75 --- .../WsdlConfigurationTypeHandlerTest.java | 67 --- .../dsw/handlers/jaxws/MyJaxWsEchoService.java | 26 - .../handlers/jaxws/MyJaxWsEchoServiceImpl.java | 27 - .../handlers/simple/MySimpleEchoService.java | 23 - .../simple/MySimpleEchoServiceImpl.java | 27 - .../dsw/hooks/CxfFindListenerHookTest.java | 341 ----------- .../cxf/dosgi/dsw/hooks/CxfPublishHookTest.java | 299 ---------- .../dosgi/dsw/hooks/ServiceHookUtilsTest.java | 116 ---- .../apache/cxf/dosgi/dsw/hooks/TestService.java | 22 - .../dosgi/dsw/qos/IntentManagerImplTest.java | 278 --------- .../apache/cxf/dosgi/dsw/qos/IntentMapTest.java | 41 -- .../cxf/dosgi/dsw/qos/IntentTrackerTest.java | 80 --- .../cxf/dosgi/dsw/qos/IntentUtilsTest.java | 70 --- .../cxf/dosgi/dsw/util/OsgiUtilsTest.java | 152 ----- .../org/apache/cxf/dosgi/dsw/util/Provider.java | 23 - .../remote-service/alt-remote-services.xml | 32 - .../OSGI-INF/remote-service/multi-services.xml | 38 -- .../OSGI-INF/remote-service/remote-services.xml | 32 - .../src/test/resources/test-resources/rs1.xml | 31 - .../src/test/resources/test-resources/rs2.xml | 28 - .../src/test/resources/test-resources/sd-1.xml | 3 - .../src/test/resources/test-resources/sd.xml | 8 - .../src/test/resources/test-resources/sd0.xml | 2 - .../src/test/resources/test-resources/sd1.xml | 8 - .../src/test/resources/test-resources/sd2.xml | 14 - dsw/cxf-topology-manager/pom.xml | 111 ---- .../cxf/dosgi/topologymanager/Activator.java | 192 ------ .../exporter/DefaultExportPolicy.java | 37 -- .../exporter/EndpointListenerNotifier.java | 133 ----- .../exporter/EndpointRepository.java | 140 ----- .../topologymanager/exporter/StringPlus.java | 57 -- .../exporter/TopologyManagerExport.java | 195 ------ .../importer/EndpointListenerManager.java | 98 ---- .../topologymanager/importer/FilterHelper.java | 43 -- .../importer/ListenerHookImpl.java | 119 ---- .../topologymanager/importer/RSATracker.java | 26 - .../importer/ReferenceCounter.java | 76 --- .../importer/ServiceInterestListener.java | 26 - .../importer/TopologyManagerImport.java | 345 ----------- .../dosgi/topologymanager/ActivatorTest.java | 68 --- .../exporter/EndpointListenerNotifierTest.java | 160 ----- .../exporter/EndpointRepositoryTest.java | 82 --- .../exporter/TopologyManagerExportTest.java | 153 ----- .../importer/EndpointListenerImplTest.java | 111 ---- .../importer/ListenerHookImplTest.java | 89 --- .../importer/ReferenceCounterTest.java | 42 -- .../importer/TopologyManagerImportTest.java | 87 --- dsw/pom.xml | 46 -- osgi-api/pom.xml | 70 --- parent/pom.xml | 3 + pom.xml | 5 +- systests2/multi-bundle/pom.xml | 6 - tck/apply-to-tck.sh.template | 15 - ...gi.impl.service.remoteserviceadmin-4.3.0.lib | 5 - 252 files changed, 7046 insertions(+), 19308 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/cxf-dsw/pom.xml ---------------------------------------------------------------------- diff --git a/cxf-dsw/pom.xml b/cxf-dsw/pom.xml new file mode 100644 index 0000000..92ef7ae --- /dev/null +++ b/cxf-dsw/pom.xml @@ -0,0 +1,155 @@ +<?xml version='1.0' encoding='UTF-8' ?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-dosgi-ri-dsw-cxf</artifactId> + <packaging>bundle</packaging> + <name>CXF dOSGi Distribution provider</name> + + <parent> + <groupId>org.apache.cxf.dosgi</groupId> + <artifactId>cxf-dosgi-ri-parent</artifactId> + <version>1.8-SNAPSHOT</version> + <relativePath>../parent/pom.xml</relativePath> + </parent> + + <properties> + <topDirectoryLocation>..</topDirectoryLocation> + </properties> + + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + + + <dependency> + <groupId>org.apache.aries.rsa</groupId> + <artifactId>spi</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-core</artifactId> + <version>${cxf.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxws</artifactId> + <version>${cxf.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxrs</artifactId> + <version>${cxf.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-rs-client</artifactId> + <version>${cxf.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-databinding-aegis</artifactId> + <version>${cxf.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-rs-extension-providers</artifactId> + <version>${cxf.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-servlet_${servlet.version}_spec</artifactId> + <version>1.0</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymockclassextension</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.7.14</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.jvnet.jaxb2.maven2</groupId> + <artifactId>maven-jaxb2-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + <Import-Package> + javax.servlet*;version="[0.0,4)", + * + </Import-Package> + <Export-Package> + !* + </Export-Package> + <Bundle-Activator>org.apache.cxf.dosgi.dsw.Activator</Bundle-Activator> + </instructions> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <excludes> + <exclude>**/TestUtils*</exclude> + </excludes> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java new file mode 100644 index 0000000..37b6aab --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java @@ -0,0 +1,160 @@ +/** + * 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; + +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.decorator.ServiceDecorator; +import org.apache.cxf.dosgi.dsw.decorator.ServiceDecoratorBundleListener; +import org.apache.cxf.dosgi.dsw.decorator.ServiceDecoratorImpl; +import org.apache.cxf.dosgi.dsw.handlers.CXFDistributionProvider; +import org.apache.cxf.dosgi.dsw.handlers.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.Constants.HTTP_BASE); + String cxfServletAlias = (String) config.get(org.apache.cxf.dosgi.dsw.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("remote.intents.supported", supportedIntents); + props.put("remote.configs.supported", cxfProvider.getSupportedTypes()); + rsaFactoryReg = bc.registerService(DistributionProvider.class.getName(), cxfProvider, props); + ServiceDecoratorImpl serviceDecorator = new ServiceDecoratorImpl(); + bundleListener = new ServiceDecoratorBundleListener(serviceDecorator); + bc.addBundleListener(bundleListener); + decoratorReg = bc.registerService(ServiceDecorator.class.getName(), serviceDecorator, null); + } + + 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/1425743f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java new file mode 100644 index 0000000..218bec6 --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java @@ -0,0 +1,146 @@ +/** + * 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; + +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; + public static final String WSDL_SERVICE_NAMESPACE = WSDL_CONFIG_PREFIX + ".service.ns"; + public static final String WSDL_SERVICE_NAME = WSDL_CONFIG_PREFIX + ".service.name"; + 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_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"; + + public static final String WS_FRONTEND_PROP_KEY = WS_CONFIG_TYPE + ".frontend"; + public static final String WS_FRONTEND_JAXWS = "jaxws"; + public static final String WS_FRONTEND_SIMPLE = "simple"; + + public static final String WS_IN_INTERCEPTORS_PROP_KEY = WS_CONFIG_TYPE + ".in.interceptors"; + public static final String WS_OUT_INTERCEPTORS_PROP_KEY = WS_CONFIG_TYPE + ".out.interceptors"; + public static final String WS_OUT_FAULT_INTERCEPTORS_PROP_KEY = WS_CONFIG_TYPE + ".out.fault.interceptors"; + public static final String WS_IN_FAULT_INTERCEPTORS_PROP_KEY = WS_CONFIG_TYPE + ".in.fault.interceptors"; + public static final String WS_CONTEXT_PROPS_PROP_KEY = WS_CONFIG_TYPE + ".context.properties"; + public static final String WS_FEATURES_PROP_KEY = WS_CONFIG_TYPE + ".features"; + + public static final String WS_DATABINDING_PROP_KEY = WS_CONFIG_TYPE + ".databinding"; + public static final String WS_DATABINDING_BEAN_PROP_KEY = WS_DATABINDING_PROP_KEY + ".bean"; + public static final String WS_DATA_BINDING_JAXB = "jaxb"; + public static final String WS_DATA_BINDING_AEGIS = "aegis"; + + public static final String WS_WSDL_SERVICE_NAMESPACE = WS_CONFIG_TYPE + ".service.ns"; + 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_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"; + public static final String RS_IN_INTERCEPTORS_PROP_KEY = RS_CONFIG_TYPE + ".in.interceptors"; + public static final String RS_OUT_INTERCEPTORS_PROP_KEY = RS_CONFIG_TYPE + ".out.interceptors"; + public static final String RS_IN_FAULT_INTERCEPTORS_PROP_KEY = RS_CONFIG_TYPE + ".in.fault.interceptors"; + public static final String RS_OUT_FAULT_INTERCEPTORS_PROP_KEY = RS_CONFIG_TYPE + ".out.fault.interceptors"; + public static final String RS_CONTEXT_PROPS_PROP_KEY = RS_CONFIG_TYPE + ".context.properties"; + public static final String RS_FEATURES_PROP_KEY = RS_CONFIG_TYPE + ".features"; + public static final String RS_PROVIDER_PROP_KEY = RS_CONFIG_TYPE + ".provider"; + 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/1425743f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/DecorationParser.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/DecorationParser.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/DecorationParser.java new file mode 100644 index 0000000..82753b1 --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/DecorationParser.java @@ -0,0 +1,85 @@ +/** + * 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.decorator; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.XMLConstants; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.apache.cxf.xmlns.service_decoration._1_0.ServiceDecorationType; +import org.apache.cxf.xmlns.service_decoration._1_0.ServiceDecorationsType; + +class DecorationParser { + private JAXBContext jaxbContext; + private Schema schema; + + DecorationParser() { + try { + jaxbContext = JAXBContext.newInstance(ServiceDecorationsType.class.getPackage().getName(), + this.getClass().getClassLoader()); + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + URL resource = getClass().getResource("/service-decoration.xsd"); + schema = schemaFactory.newSchema(resource); + } catch (Exception e) { + throw new RuntimeException("Error loading decorations schema", e); + } + + } + + List<ServiceDecorationType> getDecorations(URL resourceURL) throws JAXBException, IOException { + if (resourceURL == null || !decorationType(resourceURL)) { + return new ArrayList<ServiceDecorationType>(); + } + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + unmarshaller.setSchema(schema); + InputStream is = resourceURL.openStream(); + Source source = new StreamSource(is); + JAXBElement<ServiceDecorationsType> jaxb = unmarshaller.unmarshal(source, ServiceDecorationsType.class); + ServiceDecorationsType decorations = jaxb.getValue(); + return decorations.getServiceDecoration(); + } + + private boolean decorationType(URL resourceURL) { + try { + InputStream is = resourceURL.openStream(); + XMLInputFactory factory = XMLInputFactory.newInstance(); + XMLStreamReader reader = factory.createXMLStreamReader(is); + reader.next(); + String ns = reader.getNamespaceURI(); + reader.close(); + return ns.equals("http://cxf.apache.org/xmlns/service-decoration/1.0.0"); + } catch (Exception e) { + return false; + } + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRule.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRule.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRule.java new file mode 100644 index 0000000..894d01d --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/InterfaceRule.java @@ -0,0 +1,96 @@ +/** + * 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.decorator; + +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.osgi.framework.Bundle; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class InterfaceRule implements Rule { + + private static final Logger LOG = LoggerFactory.getLogger(InterfaceRule.class); + + private final Bundle bundle; + private final Pattern matchPattern; + private final Map<String, String> propMatches = new HashMap<String, String>(); + private final Map<String, Object> addProps = new HashMap<String, Object>(); + + public InterfaceRule(Bundle b, String im) { + bundle = b; + matchPattern = Pattern.compile(im); + } + + public synchronized void addPropMatch(String name, String value) { + propMatches.put(name, value); + } + + public synchronized void addProperty(String name, String value, String type) { + Object obj = value; + + if (type != null && !String.class.getName().equals(type)) { + try { + Class<?> cls = getClass().getClassLoader().loadClass(type); + Constructor<?> ctor = cls.getConstructor(new Class[] {String.class}); + obj = ctor.newInstance(value); + } catch (Throwable th) { + LOG.warn("Could not handle property '" + name + + "' with value '" + value + "' of type: " + type, th); + return; + } + } + + addProps.put(name, obj); + } + + public synchronized void apply(ServiceReference<?> sref, Map<String, Object> target) { + String[] objectClass = (String[]) sref.getProperty(Constants.OBJECTCLASS); + boolean matches = false; + for (String cls : objectClass) { + Matcher m = matchPattern.matcher(cls); + if (m.matches()) { + for (Map.Entry<String, String> pm : propMatches.entrySet()) { + Object value = sref.getProperty(pm.getKey()); + if (value == null || !Pattern.matches(pm.getValue(), value.toString())) { + return; + } + } + matches = true; + break; + } + } + if (!matches) { + return; + } + + LOG.info("Adding the following properties to " + sref + ": " + addProps); + target.putAll(addProps); + } + + public Bundle getBundle() { + return bundle; + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/Rule.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/Rule.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/Rule.java new file mode 100644 index 0000000..adbd1cf --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/Rule.java @@ -0,0 +1,41 @@ +/** + * 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.decorator; + +import java.util.Map; + +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceReference; + +public interface Rule { + + /** + * When the ServiceReference passed in matches the rule's condition, + * set the additional properties in the target. + * @param sref The Service Reference to be checked. + * @param target Any additional properties are to be set in this map. + */ + void apply(ServiceReference<?> sref, Map<String, Object> target); + + /** + * Returns the bundle that provided this rule. + * @return The Bundle where the Rule was defined. + */ + Bundle getBundle(); +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecorator.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecorator.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecorator.java new file mode 100644 index 0000000..203bd1c --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecorator.java @@ -0,0 +1,28 @@ +/** + * 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.decorator; + +import java.util.Map; + +import org.osgi.framework.ServiceReference; + +public interface ServiceDecorator { + + void decorate(ServiceReference<?> sref, Map<String, Object> properties); +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListener.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListener.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListener.java new file mode 100644 index 0000000..79c2908 --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListener.java @@ -0,0 +1,48 @@ +/** + * 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.decorator; + +import org.osgi.framework.BundleEvent; +import org.osgi.framework.BundleListener; + +public class ServiceDecoratorBundleListener implements BundleListener { + /** + * + */ + private final ServiceDecoratorImpl serviceDecorator; + + /** + * @param serviceDecorator + */ + public ServiceDecoratorBundleListener(ServiceDecoratorImpl serviceDecorator) { + this.serviceDecorator = serviceDecorator; + } + + public void bundleChanged(BundleEvent be) { + switch(be.getType()) { + case BundleEvent.STARTED: + this.serviceDecorator.addDecorations(be.getBundle()); + break; + case BundleEvent.STOPPING: + this.serviceDecorator.removeDecorations(be.getBundle()); + break; + default: + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImpl.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImpl.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImpl.java new file mode 100644 index 0000000..20130c3 --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImpl.java @@ -0,0 +1,97 @@ +/** + * 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.decorator; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.cxf.xmlns.service_decoration._1_0.AddPropertyType; +import org.apache.cxf.xmlns.service_decoration._1_0.MatchPropertyType; +import org.apache.cxf.xmlns.service_decoration._1_0.MatchType; +import org.apache.cxf.xmlns.service_decoration._1_0.ServiceDecorationType; +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ServiceDecoratorImpl implements ServiceDecorator { + private static final Logger LOG = LoggerFactory.getLogger(ServiceDecoratorImpl.class); + final List<Rule> decorations = new CopyOnWriteArrayList<Rule>(); + + private DecorationParser parser; + + public ServiceDecoratorImpl() { + parser = new DecorationParser(); + } + + public void decorate(ServiceReference<?> sref, Map<String, Object> target) { + for (Rule matcher : decorations) { + matcher.apply(sref, target); + } + } + + void addDecorations(Bundle bundle) { + for (ServiceDecorationType decoration : getDecorationElements(bundle)) { + for (MatchType match : decoration.getMatch()) { + decorations.add(getRule(bundle, match)); + } + } + } + + private Rule getRule(Bundle bundle, MatchType match) { + InterfaceRule m = new InterfaceRule(bundle, match.getInterface()); + for (MatchPropertyType propMatch : match.getMatchProperty()) { + m.addPropMatch(propMatch.getName(), propMatch.getValue()); + } + for (AddPropertyType addProp : match.getAddProperty()) { + m.addProperty(addProp.getName(), addProp.getValue(), addProp.getType()); + } + return m; + } + + List<ServiceDecorationType> getDecorationElements(Bundle bundle) { + @SuppressWarnings("rawtypes") + Enumeration entries = bundle.findEntries("OSGI-INF/remote-service", "*.xml", false); + if (entries == null) { + return Collections.emptyList(); + } + List<ServiceDecorationType> elements = new ArrayList<ServiceDecorationType>(); + while (entries.hasMoreElements()) { + try { + elements.addAll(parser.getDecorations((URL)entries.nextElement())); + } catch (Exception e) { + LOG.warn("Error parsing remote-service descriptions in bundle" + bundle.getSymbolicName(), e); + } + } + return elements; + } + + void removeDecorations(Bundle bundle) { + for (Rule r : decorations) { + if (bundle.equals(r.getBundle())) { + decorations.remove(r); // the iterator doesn't support 'remove' + } + } + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java new file mode 100644 index 0000000..d2c8929 --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java @@ -0,0 +1,243 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.dosgi.dsw.handlers; + +import java.lang.reflect.Proxy; +import java.net.URL; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.aries.rsa.spi.DistributionProvider; +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.Constants; +import org.apache.cxf.dosgi.dsw.qos.IntentManager; +import org.apache.cxf.dosgi.dsw.qos.IntentUtils; +import org.apache.cxf.dosgi.dsw.util.OsgiUtils; +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; +import org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory; +import org.apache.cxf.frontend.ClientFactoryBean; +import org.apache.cxf.frontend.ServerFactoryBean; +import org.apache.cxf.helpers.CastUtils; +import org.apache.cxf.interceptor.Interceptor; +import org.osgi.framework.BundleContext; +import org.osgi.service.remoteserviceadmin.EndpointDescription; +import org.osgi.service.remoteserviceadmin.RemoteConstants; + +public abstract class AbstractPojoConfigurationTypeHandler implements DistributionProvider { + protected BundleContext bundleContext; + protected IntentManager intentManager; + protected HttpServiceManager httpServiceManager; + + public AbstractPojoConfigurationTypeHandler(BundleContext dswBC, IntentManager intentManager, + HttpServiceManager httpServiceManager) { + this.bundleContext = dswBC; + this.intentManager = intentManager; + this.httpServiceManager = httpServiceManager; + } + + protected Object getProxy(Object serviceProxy, Class<?> iType) { + return Proxy.newProxyInstance(iType.getClassLoader(), new Class[] { + iType + }, new ServiceInvocationHandler(serviceProxy, iType)); + } + + protected EndpointDescription createEndpointDesc(Map<String, Object> props, + String[] importedConfigs, + String address, + String[] intents) { + props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, importedConfigs); + for (String configurationType : importedConfigs) { + if (Constants.WS_CONFIG_TYPE.equals(configurationType)) { + props.put(Constants.WS_ADDRESS_PROPERTY, address); + } else if (Constants.RS_CONFIG_TYPE.equals(configurationType)) { + props.put(Constants.RS_ADDRESS_PROPERTY, address); + } else if (Constants.WS_CONFIG_TYPE_OLD.equals(configurationType)) { + props.put(Constants.WS_ADDRESS_PROPERTY_OLD, address); + props.put(Constants.WS_ADDRESS_PROPERTY, address); + } + } + String[] sIntents = StringPlus.normalize(props.get(RemoteConstants.SERVICE_INTENTS)); + String[] allIntents = IntentUtils.mergeArrays(intents, sIntents); + props.put(RemoteConstants.SERVICE_INTENTS, allIntents); + props.put(RemoteConstants.ENDPOINT_ID, address); + return new EndpointDescription(props); + } + + protected void setCommonWsdlProperties(AbstractWSDLBasedEndpointFactory factory, BundleContext context, + Map<String, Object> sd, boolean wsdlType) { + String location = OsgiUtils.getProperty(sd, wsdlType ? Constants.WSDL_LOCATION : Constants.WS_WSDL_LOCATION); + if (location != null) { + URL wsdlURL = context.getBundle().getResource(location); + if (wsdlURL != null) { + factory.setWsdlURL(wsdlURL.toString()); + } + QName serviceName = getServiceQName(null, sd, + wsdlType ? Constants.WSDL_SERVICE_NAMESPACE : Constants.WS_WSDL_SERVICE_NAMESPACE, + wsdlType ? Constants.WSDL_SERVICE_NAME : Constants.WS_WSDL_SERVICE_NAME); + if (serviceName != null) { + factory.setServiceName(serviceName); + QName portName = getPortQName(serviceName.getNamespaceURI(), sd, + wsdlType ? Constants.WSDL_PORT_NAME : Constants.WS_WSDL_PORT_NAME); + if (portName != null) { + factory.setEndpointName(portName); + } + } + } + } + + protected void setWsdlProperties(ServerFactoryBean factory, BundleContext callingContext, Map<String, Object> sd, + boolean wsdlType) { + setCommonWsdlProperties(factory, callingContext, sd, wsdlType); + } + + protected void setClientWsdlProperties(ClientFactoryBean factory, BundleContext dswContext, Map<String, Object> sd, + boolean wsdlType) { + setCommonWsdlProperties(factory, dswContext, sd, wsdlType); + } + + protected static QName getServiceQName(Class<?> iClass, Map<String, Object> sd, String nsPropName, + String namePropName) { + String serviceNs = OsgiUtils.getProperty(sd, nsPropName); + String serviceName = OsgiUtils.getProperty(sd, namePropName); + if (iClass == null && (serviceNs == null || serviceName == null)) { + return null; + } + if (serviceNs == null) { + serviceNs = PackageUtils.getNamespace(PackageUtils.getPackageName(iClass)); + } + if (serviceName == null) { + serviceName = iClass.getSimpleName(); + } + return new QName(serviceNs, serviceName); + } + + protected static QName getPortQName(String ns, Map<String, Object> sd, String propName) { + String portName = OsgiUtils.getProperty(sd, propName); + if (portName == null) { + return null; + } + return new QName(ns, portName); + } + + protected String getClientAddress(Map<String, Object> sd) { + return OsgiUtils.getFirstNonEmptyStringProperty(sd, RemoteConstants.ENDPOINT_ID, + Constants.WS_ADDRESS_PROPERTY, + Constants.WS_ADDRESS_PROPERTY_OLD, + Constants.RS_ADDRESS_PROPERTY); + } + + protected String getServerAddress(Map<String, Object> sd, Class<?> iClass) { + String address = getClientAddress(sd); + return address == null ? httpServiceManager.getDefaultAddress(iClass) : address; + } + + public String getServletContextRoot(Map<String, Object> sd) { + return OsgiUtils.getFirstNonEmptyStringProperty(sd, + Constants.WS_HTTP_SERVICE_CONTEXT, + Constants.WS_HTTP_SERVICE_CONTEXT_OLD, + Constants.WSDL_HTTP_SERVICE_CONTEXT, + Constants.RS_HTTP_SERVICE_CONTEXT); + } + + + protected Bus createBus(Long sid, BundleContext callingContext, String contextRoot) { + Bus bus = BusFactory.newInstance().createBus(); + if (contextRoot != null) { + httpServiceManager.registerServlet(bus, contextRoot, callingContext, sid); + } + return bus; + } + + protected Endpoint createServerFromFactory(ServerFactoryBean factory, EndpointDescription epd) { + ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader()); + Server server = factory.create(); + return new ServerWrapper(epd, server); + } finally { + Thread.currentThread().setContextClassLoader(oldClassLoader); + } + } + + protected static void addWsInterceptorsFeaturesProps(AbstractEndpointFactory factory, BundleContext callingContext, + Map<String, Object> sd) { + addInterceptors(factory, callingContext, sd, Constants.WS_IN_INTERCEPTORS_PROP_KEY); + addInterceptors(factory, callingContext, sd, Constants.WS_OUT_INTERCEPTORS_PROP_KEY); + addInterceptors(factory, callingContext, sd, Constants.WS_OUT_FAULT_INTERCEPTORS_PROP_KEY); + addInterceptors(factory, callingContext, sd, Constants.WS_IN_FAULT_INTERCEPTORS_PROP_KEY); + addFeatures(factory, callingContext, sd, Constants.WS_FEATURES_PROP_KEY); + addContextProperties(factory, sd, Constants.WS_CONTEXT_PROPS_PROP_KEY); + } + + static void addRsInterceptorsFeaturesProps(AbstractEndpointFactory factory, BundleContext callingContext, + Map<String, Object> sd) { + addInterceptors(factory, callingContext, sd, Constants.RS_IN_INTERCEPTORS_PROP_KEY); + addInterceptors(factory, callingContext, sd, Constants.RS_OUT_INTERCEPTORS_PROP_KEY); + addInterceptors(factory, callingContext, sd, Constants.RS_OUT_FAULT_INTERCEPTORS_PROP_KEY); + addInterceptors(factory, callingContext, sd, Constants.RS_IN_FAULT_INTERCEPTORS_PROP_KEY); + addFeatures(factory, callingContext, sd, Constants.RS_FEATURES_PROP_KEY); + addContextProperties(factory, sd, Constants.RS_CONTEXT_PROPS_PROP_KEY); + } + + private static void addInterceptors(AbstractEndpointFactory factory, BundleContext callingContext, + Map<String, Object> sd, String propName) { + List<Object> providers = ClassUtils.loadProviderClasses(callingContext, sd, propName); + boolean in = propName.contains("in.interceptors"); + boolean out = propName.contains("out.interceptors"); + boolean inFault = propName.contains("in.fault.interceptors"); + boolean outFault = propName.contains("out.fault.interceptors"); + for (Object provider : providers) { + Interceptor<?> interceptor = (Interceptor<?>) provider; + if (in) { + factory.getInInterceptors().add(interceptor); + } else if (out) { + factory.getOutInterceptors().add(interceptor); + } else if (inFault) { + factory.getInFaultInterceptors().add(interceptor); + } else if (outFault) { + factory.getOutFaultInterceptors().add(interceptor); + } + } + } + + private static void addFeatures(AbstractEndpointFactory factory, BundleContext callingContext, + Map<String, Object> sd, String propName) { + List<Object> providers = ClassUtils.loadProviderClasses(callingContext, sd, propName); + if (!providers.isEmpty()) { + factory.getFeatures().addAll(CastUtils.cast(providers, AbstractFeature.class)); + } + } + + private static void addContextProperties(AbstractEndpointFactory factory, Map<String, Object> sd, String propName) { + @SuppressWarnings("unchecked") + Map<String, Object> props = (Map<String, Object>)sd.get(propName); + if (props != null) { + factory.getProperties(true).putAll(props); + } + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/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 new file mode 100644 index 0000000..9069de8 --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java @@ -0,0 +1,178 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.dosgi.dsw.handlers; + +import java.util.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.aries.rsa.spi.DistributionProvider; +import org.apache.aries.rsa.spi.Endpoint; +import org.apache.aries.rsa.spi.IntentUnsatisfiedException; +import org.apache.cxf.dosgi.dsw.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.remoteserviceadmin.EndpointDescription; +import org.osgi.service.remoteserviceadmin.RemoteConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CXFDistributionProvider implements DistributionProvider { + + 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; + + public CXFDistributionProvider(BundleContext bc, IntentManager intentManager, + HttpServiceManager httpServiceManager) { + this.intentManager = intentManager; + 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") + @Override + public Endpoint exportService(Object serviceO, + BundleContext serviceContext, + Map<String, Object> effectiveProperties, + Class[] exportedInterfaces) { + List<String> configurationTypes = determineConfigurationTypes(effectiveProperties); + DistributionProvider handler = getHandler(configurationTypes, effectiveProperties); + return handler != null ? handler.exportService(serviceO, serviceContext, + effectiveProperties, exportedInterfaces) : null; + } + + @SuppressWarnings("rawtypes") + @Override + public Object importEndpoint(ClassLoader consumerLoader, BundleContext consumerContext, + Class[] iClass, EndpointDescription endpoint) + throws IntentUnsatisfiedException { + List<String> configurationTypes = determineConfigTypesForImport(endpoint); + DistributionProvider handler = getHandler(configurationTypes, endpoint.getProperties()); + return handler != null ? handler.importEndpoint(consumerLoader, consumerContext, iClass, endpoint) : null; + } + + DistributionProvider getHandler(List<String> configurationTypes, + Map<String, Object> serviceProperties) { + intentManager.assertAllIntentsSupported(serviceProperties); + if (configurationTypes.contains(Constants.WS_CONFIG_TYPE) + || configurationTypes.contains(Constants.WS_CONFIG_TYPE_OLD) + || configurationTypes.contains(Constants.RS_CONFIG_TYPE)) { + boolean jaxrs = isJaxrsRequested(configurationTypes, serviceProperties); + return jaxrs ? jaxRsPojoConfigurationTypeHandler : pojoConfigurationTypeHandler; + } else if (configurationTypes.contains(Constants.WSDL_CONFIG_TYPE)) { + return wsdlConfigurationTypeHandler; + } + LOG.info("None of the configuration types in " + configurationTypes + " is supported."); + return null; + } + + private boolean isJaxrsRequested(Collection<String> types, Map<String, Object> serviceProperties) { + if (types == null) { + return false; + } + + if (types.contains(Constants.RS_CONFIG_TYPE)) { + Collection<String> intentsProperty + = OsgiUtils.getMultiValueProperty(serviceProperties.get(RemoteConstants.SERVICE_EXPORTED_INTENTS)); + boolean hasHttpIntent = false; + boolean hasSoapIntent = false; + if (intentsProperty != null) { + for (String intent : intentsProperty) { + if (intent.contains("SOAP")) { + hasSoapIntent = true; + break; + } + + if (intent.contains("HTTP")) { + hasHttpIntent = true; + } + } + } + if ((hasHttpIntent && !hasSoapIntent) || intentsProperty == null) { + return true; + } + } + return false; + } + + /** + * determine which configuration types should be used / if the requested are + * supported + */ + List<String> determineConfigurationTypes(Map<String, Object> serviceProperties) { + String[] requestedConfigurationTypes = StringPlus.normalize(serviceProperties + .get(RemoteConstants.SERVICE_EXPORTED_CONFIGS)); + if (requestedConfigurationTypes == null || requestedConfigurationTypes.length == 0) { + return Collections.singletonList(DEFAULT_CONFIGURATION_TYPE); + } + + List<String> configurationTypes = new ArrayList<String>(); + for (String rct : requestedConfigurationTypes) { + if (configTypesSet.contains(rct)) { + configurationTypes.add(rct); + } + } + LOG.info("Configuration types selected for export: {}.", configurationTypes); + return configurationTypes; + } + + private List<String> determineConfigTypesForImport(EndpointDescription endpoint) { + List<String> remoteConfigurationTypes = endpoint.getConfigurationTypes(); + + List<String> usableConfigurationTypes = new ArrayList<String>(); + for (String ct : supportedConfigurationTypes) { + if (remoteConfigurationTypes.contains(ct)) { + usableConfigurationTypes.add(ct); + } + } + + LOG.info("Ignoring endpoint {} as it has no compatible configuration types: {}.", + endpoint.getId(), remoteConfigurationTypes); + return usableConfigurationTypes; + } + + public String[] getSupportedTypes() { + return supportedConfigurationTypes; + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/1425743f/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtils.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtils.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtils.java new file mode 100644 index 0000000..cae19bd --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtils.java @@ -0,0 +1,142 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.dosgi.dsw.handlers; + +import java.util.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 Class<?> getInterfaceClass(Object service, String interfaceName) { + return getInterfaceClass(service.getClass(), interfaceName); + } + + private static Class<?> getInterfaceClass(Class<?> serviceClass, String interfaceName) { + for (Class<?> iClass : serviceClass.getInterfaces()) { + if (iClass.getName().equals(interfaceName)) { + return iClass; + } + Class<?> intf = getInterfaceClass(iClass, interfaceName); + if (intf != null) { + return intf; + } + } + + if (serviceClass.getName().equals(interfaceName)) { + return serviceClass; + } + + Class<?> interfaceOnProxiedClass = getInterfaceClassOnSuperClasses(serviceClass, interfaceName); + if (interfaceOnProxiedClass != null) { + return interfaceOnProxiedClass; + } + + return null; + } + + /** + * This method tries to deal specifically with classes that might have been proxied + * eg. CGLIB proxies of which there might be a chain of proxies as different osgi frameworks + * might be proxying the original service class that has been registered and then proxying the proxy. + * + * @param serviceClass + * @param interfaceName + * @return + */ + private static Class<?> getInterfaceClassOnSuperClasses(Class<?> serviceClass, String interfaceName) { + Class<?> superClass = serviceClass.getSuperclass(); + if (superClass != null) { + for (Class<?> iClass : superClass.getInterfaces()) { + if (iClass.getName().equals(interfaceName)) { + return iClass; + } + Class<?> intf = getInterfaceClass(iClass, interfaceName); + if (intf != null) { + return intf; + } + } + Class<?> foundOnSuperclass = getInterfaceClassOnSuperClasses(superClass, interfaceName); + if (foundOnSuperclass != null) { + return foundOnSuperclass; + } + } + return null; + } + + 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; + } +}
