[DOSGI-229] Move some property handling to RSA
Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/610ef4aa Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/610ef4aa Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/610ef4aa Branch: refs/heads/master Commit: 610ef4aac9c87121ab3636d155c1166e46ec85e0 Parents: e01f0ee Author: Christian Schneider <[email protected]> Authored: Tue Mar 8 17:01:42 2016 +0100 Committer: Christian Schneider <[email protected]> Committed: Tue Mar 8 17:01:42 2016 +0100 ---------------------------------------------------------------------- dsw/cxf-dosgi-provider-api/pom.xml | 3 + dsw/cxf-dosgi-rsa/pom.xml | 4 +- .../cxf/dosgi/dsw/service/PackageUtil.java | 85 ++++++++++++++++++++ .../dsw/service/RemoteServiceAdminCore.java | 37 ++++++++- .../dsw/service/RemoteServiceAdminCoreTest.java | 26 +++++- .../AbstractPojoConfigurationTypeHandler.java | 58 +++---------- .../dosgi/dsw/handlers/HttpServiceManager.java | 9 +-- .../JaxRSPojoConfigurationTypeHandler.java | 25 +++--- .../handlers/PojoConfigurationTypeHandler.java | 33 ++++---- .../handlers/WsdlConfigurationTypeHandler.java | 15 ++-- .../apache/cxf/dosgi/dsw/qos/IntentUtils.java | 6 -- .../dsw/handlers/HttpServiceManagerTest.java | 2 +- .../PojoConfigurationTypeHandlerTest.java | 29 +++---- osgi-api/pom.xml | 15 ++-- 14 files changed, 227 insertions(+), 120 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dosgi-provider-api/pom.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dosgi-provider-api/pom.xml b/dsw/cxf-dosgi-provider-api/pom.xml index 9b248fb..0deab6c 100644 --- a/dsw/cxf-dosgi-provider-api/pom.xml +++ b/dsw/cxf-dosgi-provider-api/pom.xml @@ -24,10 +24,12 @@ <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> </dependency> <dependency> @@ -44,6 +46,7 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> <version>1.7.14</version> + <scope>test</scope> </dependency> </dependencies> http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dosgi-rsa/pom.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dosgi-rsa/pom.xml b/dsw/cxf-dosgi-rsa/pom.xml index 149e287..b96828b 100644 --- a/dsw/cxf-dosgi-rsa/pom.xml +++ b/dsw/cxf-dosgi-rsa/pom.xml @@ -24,10 +24,12 @@ <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.cxf.dosgi</groupId> @@ -49,6 +51,7 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> <version>1.7.14</version> + <scope>test</scope> </dependency> </dependencies> @@ -67,5 +70,4 @@ </plugin> </plugins> </build> -</project> </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/PackageUtil.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/PackageUtil.java b/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/PackageUtil.java new file mode 100644 index 0000000..effcef1 --- /dev/null +++ b/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/PackageUtil.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.service; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.packageadmin.ExportedPackage; +import org.osgi.service.packageadmin.PackageAdmin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@SuppressWarnings("deprecation") +public final class PackageUtil { + + public static final Logger LOG = LoggerFactory.getLogger(PackageUtil.class); + + private PackageUtil() { + } + + /** + * Tries to retrieve the version of iClass via the PackageAdmin. + * + * @param iClass tThe interface for which the version should be found + * @param bc any valid BundleContext + * @return the version of the interface or "0.0.0" if no version information could be found or an error + * occurred during the retrieval + */ + public static String getVersion(Class<?> iClass, BundleContext bc) { + ServiceReference<PackageAdmin> paRef = bc.getServiceReference(PackageAdmin.class); + if (paRef != null) { + PackageAdmin pa = bc.getService(paRef); + try { + Bundle b = pa.getBundle(iClass); + if (b == null) { + LOG.info("Unable to find interface version for interface " + iClass.getName() + + ". Falling back to 0.0.0"); + return "0.0.0"; + } + LOG.debug("Interface source bundle: {}", b.getSymbolicName()); + + ExportedPackage[] ep = pa.getExportedPackages(b); + LOG.debug("Exported Packages of the source bundle: {}", (Object)ep); + + String pack = iClass.getPackage().getName(); + LOG.debug("Looking for Package: {}", pack); + if (ep != null) { + for (ExportedPackage p : ep) { + if (p != null + && pack.equals(p.getName())) { + LOG.debug("found package -> Version: {}", p.getVersion()); + return p.getVersion().toString(); + } + } + } + } finally { + if (pa != null) { + bc.ungetService(paRef); + } + } + } else { + LOG.error("Was unable to obtain the package admin service -> can't resolve interface versions"); + } + + LOG.info("Unable to find interface version for interface " + iClass.getName() + + ". Falling back to 0.0.0"); + return "0.0.0"; + } +} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java b/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java index aa6e4ee..d9bdabc 100644 --- a/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java +++ b/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java @@ -174,7 +174,8 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin { LOG.info("interfaces selected for export: " + interfaceNames); try { Class<?>[] interfaces = getInterfaces(interfaceNames, serviceReference.getBundle()); - Endpoint endpoint = provider.exportService(serviceReference, serviceProperties, interfaces); + Map<String, Object> eprops = createEndpointProps(serviceProperties, interfaces); + Endpoint endpoint = provider.exportService(serviceReference, eprops, interfaces); return new ExportRegistrationImpl(serviceReference, endpoint, this); } catch (Exception e) { return new ExportRegistrationImpl(this, e); @@ -550,4 +551,38 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin { } return props; } + + protected Map<String, Object> createEndpointProps(Map<String, Object> sd, + Class<?>[] ifaces) { + Map<String, Object> props = new HashMap<String, Object>(); + copyEndpointProperties(sd, props); + props.remove(org.osgi.framework.Constants.SERVICE_ID); + props.put(org.osgi.framework.Constants.OBJECTCLASS, getClassNames(ifaces)); + props.put(RemoteConstants.ENDPOINT_SERVICE_ID, sd.get(org.osgi.framework.Constants.SERVICE_ID)); + String frameworkUUID = bctx.getProperty(org.osgi.framework.Constants.FRAMEWORK_UUID); + props.put(RemoteConstants.ENDPOINT_FRAMEWORK_UUID, frameworkUUID); + for (Class<?> iface : ifaces) { + String pkg = iface.getPackage().getName(); + props.put(RemoteConstants.ENDPOINT_PACKAGE_VERSION_ + pkg, PackageUtil.getVersion(iface, bctx)); + } + return props; + } + + private String[] getClassNames(Class<?>[] ifaces) { + List<String> ifaceNames = new ArrayList<String>(); + for (Class<?> iface : ifaces) { + ifaceNames.add(iface.getName()); + } + return ifaceNames.toArray(new String[]{}); + } + + private void copyEndpointProperties(Map<String, Object> sd, Map<String, Object> endpointProps) { + Set<Map.Entry<String, Object>> keys = sd.entrySet(); + for (Map.Entry<String, Object> entry : keys) { + String skey = entry.getKey(); + if (!skey.startsWith(".")) { + endpointProps.put(skey, entry.getValue()); + } + } + } } http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dosgi-rsa/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dosgi-rsa/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java b/dsw/cxf-dosgi-rsa/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java index af7052f..13c34f0 100644 --- a/dsw/cxf-dosgi-rsa/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java +++ b/dsw/cxf-dosgi-rsa/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java @@ -33,6 +33,7 @@ import org.apache.cxf.dosgi.dsw.api.Endpoint; import org.easymock.EasyMock; import org.easymock.IAnswer; import org.easymock.IMocksControl; +import org.junit.Assert; import org.junit.Test; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -41,6 +42,7 @@ import org.osgi.framework.FrameworkUtil; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceReference; +import org.osgi.service.packageadmin.PackageAdmin; import org.osgi.service.remoteserviceadmin.EndpointDescription; import org.osgi.service.remoteserviceadmin.ExportRegistration; import org.osgi.service.remoteserviceadmin.ImportRegistration; @@ -55,7 +57,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @SuppressWarnings({ - "rawtypes", "unchecked" + "rawtypes", "unchecked", "deprecation" }) public class RemoteServiceAdminCoreTest { @@ -198,6 +200,8 @@ public class RemoteServiceAdminCoreTest { EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes(); EasyMock.expect(bc.createFilter("(service.id=51)")) .andReturn(FrameworkUtil.createFilter("(service.id=51)")).anyTimes(); + EasyMock.expect(bc.getProperty(org.osgi.framework.Constants.FRAMEWORK_UUID)).andReturn("1111"); + EasyMock.expect(bc.getServiceReference(PackageAdmin.class)).andReturn(null); EasyMock.replay(bc); Map<String, Object> eProps = new HashMap<String, Object>(sProps); @@ -488,4 +492,24 @@ public class RemoteServiceAdminCoreTest { } assertEquals("newValue", copy.get("MyProp")); } + + @Test + public void testCreateEndpointProps() { + BundleContext bc = EasyMock.createNiceMock(BundleContext.class); + EasyMock.expect(bc.getProperty("org.osgi.framework.uuid")).andReturn("some_uuid1"); + EasyMock.replay(bc); + + Map<String, Object> sd = new HashMap<String, Object>(); + sd.put(org.osgi.framework.Constants.SERVICE_ID, 42); + DistributionProvider provider = null; + RemoteServiceAdminCore rsa = new RemoteServiceAdminCore(bc, bc, provider); + Map<String, Object> props = rsa.createEndpointProps(sd, new Class[]{String.class}); + + Assert.assertFalse(props.containsKey(org.osgi.framework.Constants.SERVICE_ID)); + assertEquals(42, props.get(RemoteConstants.ENDPOINT_SERVICE_ID)); + assertEquals("some_uuid1", props.get(RemoteConstants.ENDPOINT_FRAMEWORK_UUID)); + assertEquals(Arrays.asList("java.lang.String"), + Arrays.asList((Object[]) props.get(org.osgi.framework.Constants.OBJECTCLASS))); + assertEquals("0.0.0", props.get("endpoint.package.version.java.lang")); + } } http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java index 9cbb839..9e1356c 100644 --- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java +++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java @@ -20,10 +20,8 @@ package org.apache.cxf.dosgi.dsw.handlers; import java.lang.reflect.Proxy; import java.net.URL; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import javax.xml.namespace.QName; @@ -36,6 +34,7 @@ import org.apache.cxf.dosgi.dsw.api.Endpoint; 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; @@ -45,15 +44,10 @@ 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.framework.ServiceReference; import org.osgi.service.remoteserviceadmin.EndpointDescription; import org.osgi.service.remoteserviceadmin.RemoteConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public abstract class AbstractPojoConfigurationTypeHandler implements DistributionProvider { - - private static final Logger LOG = LoggerFactory.getLogger(AbstractPojoConfigurationTypeHandler.class); protected BundleContext bundleContext; protected IntentManager intentManager; protected HttpServiceManager httpServiceManager; @@ -71,25 +65,11 @@ public abstract class AbstractPojoConfigurationTypeHandler implements Distributi }, new ServiceInvocationHandler(serviceProxy, iType)); } - protected Map<String, Object> createEndpointProps(Map<String, Object> sd, Class<?> iClass, - String[] importedConfigs, String address, String[] intents) { - Map<String, Object> props = new HashMap<String, Object>(); - - copyEndpointProperties(sd, props); - - String[] sa = new String[] { - iClass.getName() - }; - String pkg = iClass.getPackage().getName(); - - props.remove(org.osgi.framework.Constants.SERVICE_ID); - props.put(org.osgi.framework.Constants.OBJECTCLASS, sa); - props.put(RemoteConstants.ENDPOINT_SERVICE_ID, sd.get(org.osgi.framework.Constants.SERVICE_ID)); - String frameworkUUID = bundleContext.getProperty(org.osgi.framework.Constants.FRAMEWORK_UUID); - props.put(RemoteConstants.ENDPOINT_FRAMEWORK_UUID, frameworkUUID); + protected EndpointDescription createEndpointDesc(Map<String, Object> props, + String[] importedConfigs, + String address, + String[] intents) { props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, importedConfigs); - props.put(RemoteConstants.ENDPOINT_PACKAGE_VERSION_ + pkg, OsgiUtils.getVersion(iClass, bundleContext)); - for (String configurationType : importedConfigs) { if (Constants.WS_CONFIG_TYPE.equals(configurationType)) { props.put(Constants.WS_ADDRESS_PROPERTY, address); @@ -100,26 +80,11 @@ public abstract class AbstractPojoConfigurationTypeHandler implements Distributi props.put(Constants.WS_ADDRESS_PROPERTY, address); } } - - String[] allIntents = IntentUtils.mergeArrays(intents, IntentUtils.getIntentsImplementedByTheService(sd)); + 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 props; - } - - private void copyEndpointProperties(Map<String, Object> sd, Map<String, Object> endpointProps) { - Set<Map.Entry<String, Object>> keys = sd.entrySet(); - for (Map.Entry<String, Object> entry : keys) { - try { - String skey = entry.getKey(); - if (!skey.startsWith(".")) { - endpointProps.put(skey, entry.getValue()); - } - } catch (ClassCastException e) { - LOG.warn("ServiceProperties Map contained non String key. Skipped " + entry + " " - + e.getLocalizedMessage()); - } - } + return new EndpointDescription(props); } protected void setCommonWsdlProperties(AbstractWSDLBasedEndpointFactory factory, BundleContext context, @@ -199,20 +164,19 @@ public abstract class AbstractPojoConfigurationTypeHandler implements Distributi } - protected Bus createBus(ServiceReference<?> sref, BundleContext callingContext, String contextRoot) { + protected Bus createBus(Long sid, BundleContext callingContext, String contextRoot) { Bus bus = BusFactory.newInstance().createBus(); if (contextRoot != null) { - httpServiceManager.registerServlet(bus, contextRoot, callingContext, sref); + httpServiceManager.registerServlet(bus, contextRoot, callingContext, sid); } return bus; } - protected Endpoint createServerFromFactory(ServerFactoryBean factory, Map<String, Object> endpointProps) { + protected Endpoint createServerFromFactory(ServerFactoryBean factory, EndpointDescription epd) { ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader()); Server server = factory.create(); - EndpointDescription epd = new EndpointDescription(endpointProps); return new ServerWrapper(epd, server); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManager.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManager.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManager.java index 77de3de..eca5460 100644 --- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManager.java +++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManager.java @@ -70,8 +70,7 @@ public class HttpServiceManager { return value == null ? defaultValue : value; } - public Bus registerServlet(Bus bus, String contextRoot, BundleContext callingContext, - ServiceReference<?> sref) { + public Bus registerServlet(Bus bus, String contextRoot, BundleContext callingContext, Long sid) { bus.setExtension(new DestinationRegistryImpl(), DestinationRegistry.class); CXFNonSpringServlet cxf = new CXFNonSpringServlet(); cxf.setBus(bus); @@ -79,7 +78,8 @@ public class HttpServiceManager { HttpService httpService = getHttpService(); httpService.registerServlet(contextRoot, cxf, new Hashtable<String, String>(), getHttpContext(callingContext, httpService)); - registerUnexportHook(sref, contextRoot); + + registerUnexportHook(sid, contextRoot); LOG.info("Successfully registered CXF DOSGi servlet at " + contextRoot); } catch (Exception e) { @@ -113,8 +113,7 @@ public class HttpServiceManager { * @param sref the service reference to track * @param alias the HTTP servlet context alias */ - private void registerUnexportHook(ServiceReference<?> sref, String alias) { - final Long sid = (Long) sref.getProperty(org.osgi.framework.Constants.SERVICE_ID); + private void registerUnexportHook(Long sid, String alias) { LOG.debug("Registering service listener for service with ID {}", sid); String previous = exportedAliases.put(sid, alias); http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java index 3068e8b..c90d7df 100644 --- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java +++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java @@ -38,6 +38,7 @@ import org.apache.cxf.jaxrs.model.UserResource; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.remoteserviceadmin.EndpointDescription; +import org.osgi.service.remoteserviceadmin.RemoteConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,6 +56,7 @@ public class JaxRSPojoConfigurationTypeHandler extends AbstractPojoConfiguration return new String[] {Constants.RS_CONFIG_TYPE}; } + @SuppressWarnings("rawtypes") public Object importEndpoint(BundleContext consumerContext, Class[] interfaces, EndpointDescription endpoint) { @@ -109,44 +111,45 @@ public class JaxRSPojoConfigurationTypeHandler extends AbstractPojoConfiguration return getProxy(bean.create(), iClass); } + @SuppressWarnings("rawtypes") public Endpoint exportService(ServiceReference<?> sref, - Map<String, Object> sd, + Map<String, Object> endpointProps, Class[] exportedInterfaces) throws IntentUnsatisfiedException { BundleContext callingContext = sref.getBundle().getBundleContext(); Object serviceBean = callingContext.getService(sref); - String contextRoot = getServletContextRoot(sd); + String contextRoot = getServletContextRoot(endpointProps); String address; Class<?> iClass = exportedInterfaces[0]; if (contextRoot == null) { - address = getServerAddress(sd, iClass); + address = getServerAddress(endpointProps, iClass); } else { - address = getClientAddress(sd); + address = getClientAddress(endpointProps); if (address == null) { address = "/"; } } - Bus bus = createBus(sref, callingContext, contextRoot); + final Long sid = (Long) endpointProps.get(RemoteConstants.ENDPOINT_SERVICE_ID); + Bus bus = createBus(sid, callingContext, contextRoot); LOG.info("Creating a " + iClass.getName() + " endpoint via JaxRSPojoConfigurationTypeHandler, address is " + address); - JAXRSServerFactoryBean factory = createServerFactory(callingContext, sd, iClass, serviceBean, address, bus); + JAXRSServerFactoryBean factory = createServerFactory(callingContext, endpointProps, + iClass, serviceBean, address, bus); String completeEndpointAddress = httpServiceManager.getAbsoluteAddress(contextRoot, address); - // The properties for the EndpointDescription - Map<String, Object> endpointProps = createEndpointProps(sd, iClass, new String[] {Constants.RS_CONFIG_TYPE}, + EndpointDescription epd = createEndpointDesc(endpointProps, new String[] {Constants.RS_CONFIG_TYPE}, completeEndpointAddress, new String[] {"HTTP"}); - return createServerFromFactory(factory, endpointProps); + return createServerFromFactory(factory, epd); } private Endpoint createServerFromFactory(JAXRSServerFactoryBean factory, - Map<String, Object> endpointProps) { + EndpointDescription epd) { ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(JAXRSServerFactoryBean.class.getClassLoader()); Server server = factory.create(); - EndpointDescription epd = new EndpointDescription(endpointProps); return new ServerWrapper(epd, server); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java index 129b579..e929a2d 100644 --- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java +++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java @@ -37,6 +37,7 @@ import org.apache.cxf.jaxws.JaxWsServerFactoryBean; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.remoteserviceadmin.EndpointDescription; +import org.osgi.service.remoteserviceadmin.RemoteConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,6 +55,7 @@ public class PojoConfigurationTypeHandler extends AbstractPojoConfigurationTypeH return new String[] {Constants.WS_CONFIG_TYPE, Constants.WS_CONFIG_TYPE_OLD}; } + @SuppressWarnings("rawtypes") public Object importEndpoint(BundleContext consumerContext, Class[] interfaces, EndpointDescription endpoint) throws IntentUnsatisfiedException { @@ -89,35 +91,34 @@ public class PojoConfigurationTypeHandler extends AbstractPojoConfigurationTypeH return null; } + @SuppressWarnings("rawtypes") public Endpoint exportService(ServiceReference<?> sref, - Map<String, Object> sd, + Map<String, Object> endpointProps, Class[] exportedInterfaces) throws IntentUnsatisfiedException { BundleContext callingContext = sref.getBundle().getBundleContext(); Object serviceBean = callingContext.getService(sref); Class<?> iClass = exportedInterfaces[0]; - String address = getPojoAddress(sd, iClass); - ServerFactoryBean factory = createServerFactoryBean(sd, iClass); - factory.setDataBinding(getDataBinding(sd, iClass)); - String contextRoot = getServletContextRoot(sd); + String address = getPojoAddress(endpointProps, iClass); + ServerFactoryBean factory = createServerFactoryBean(endpointProps, iClass); + factory.setDataBinding(getDataBinding(endpointProps, iClass)); + String contextRoot = getServletContextRoot(endpointProps); - Bus bus = createBus(sref, callingContext, contextRoot); + final Long sid = (Long) endpointProps.get(RemoteConstants.ENDPOINT_SERVICE_ID); + Bus bus = createBus(sid, callingContext, contextRoot); factory.setBus(bus); factory.setServiceClass(iClass); factory.setAddress(address); factory.setServiceBean(serviceBean); - addWsInterceptorsFeaturesProps(factory, callingContext, sd); - setWsdlProperties(factory, callingContext, sd, false); - String[] intents = intentManager.applyIntents(factory.getFeatures(), factory, sd); + addWsInterceptorsFeaturesProps(factory, callingContext, endpointProps); + setWsdlProperties(factory, callingContext, endpointProps, false); + String[] intents = intentManager.applyIntents(factory.getFeatures(), factory, endpointProps); String completeEndpointAddress = httpServiceManager.getAbsoluteAddress(contextRoot, address); - - // The properties for the EndpointDescription - Map<String, Object> endpointProps = createEndpointProps(sd, iClass, - new String[]{Constants.WS_CONFIG_TYPE}, - completeEndpointAddress, intents); - - return createServerFromFactory(factory, endpointProps); + EndpointDescription epd = createEndpointDesc(endpointProps, + new String[]{Constants.WS_CONFIG_TYPE}, + completeEndpointAddress, intents); + return createServerFromFactory(factory, epd); } private String getPojoAddress(Map<String, Object> sd, Class<?> iClass) { http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java index dd477b6..3bd89da 100644 --- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java +++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java @@ -54,6 +54,7 @@ public class WsdlConfigurationTypeHandler extends AbstractPojoConfigurationTypeH return new String[] {Constants.WSDL_CONFIG_TYPE}; } + @SuppressWarnings("rawtypes") public Object importEndpoint(BundleContext consumerContext, Class[] interfaces, EndpointDescription endpoint) { @@ -100,6 +101,7 @@ public class WsdlConfigurationTypeHandler extends AbstractPojoConfigurationTypeH return Service.create(wsdlAddress, serviceQname); } + @SuppressWarnings("rawtypes") public Endpoint exportService(ServiceReference<?> sref, Map<String, Object> sd, Class[] exportedInterfaces) { @@ -125,8 +127,8 @@ public class WsdlConfigurationTypeHandler extends AbstractPojoConfigurationTypeH DataBinding databinding = new JAXBDataBinding(); JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); - - Bus bus = createBus(sref, callingContext, contextRoot); + final Long sid = (Long) sref.getProperty(org.osgi.framework.Constants.SERVICE_ID); + Bus bus = createBus(sid, callingContext, contextRoot); factory.setBus(bus); factory.setServiceClass(iClass); factory.setAddress(address != null ? address : "/"); @@ -139,11 +141,10 @@ public class WsdlConfigurationTypeHandler extends AbstractPojoConfigurationTypeH String[] intents = intentManager.applyIntents(factory.getFeatures(), factory, sd); - // The properties for the EndpointDescription - Map<String, Object> endpointProps = createEndpointProps(sd, iClass, - new String[]{Constants.WS_CONFIG_TYPE}, - address, intents); - return createServerFromFactory(factory, endpointProps); + EndpointDescription epd = createEndpointDesc(sd, + new String[]{Constants.WS_CONFIG_TYPE}, + address, intents); + return createServerFromFactory(factory, epd); } private String getWsdlAddress(EndpointDescription endpoint, Class<?> iClass) { http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java index e41dadc..31b1e42 100644 --- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java +++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java @@ -29,7 +29,6 @@ import java.util.Set; import org.apache.cxf.dosgi.dsw.Constants; import org.apache.cxf.dosgi.dsw.util.OsgiUtils; -import org.apache.cxf.dosgi.dsw.util.StringPlus; import org.osgi.service.remoteserviceadmin.RemoteConstants; public final class IntentUtils { @@ -38,11 +37,6 @@ public final class IntentUtils { // never constructed } - public static String[] getIntentsImplementedByTheService(Map<String, Object> serviceProperties) { - // Get the Intents that are implemented by the service - return StringPlus.normalize(serviceProperties.get(RemoteConstants.SERVICE_INTENTS)); - } - public static String[] mergeArrays(String[] a1, String[] a2) { if (a1 == null) { return a2; http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java index a792bd6..10fba12 100644 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java +++ b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java @@ -89,7 +89,7 @@ public class HttpServiceManagerTest extends TestCase { } }; Bus bus = BusFactory.newInstance().createBus(); - h.registerServlet(bus, "/myService", dswContext, sr); + h.registerServlet(bus, "/myService", dswContext, 12345L); ServiceEvent event = new ServiceEvent(ServiceEvent.UNREGISTERING, sr); captured.getValue().serviceChanged(event); http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java index 93b1171..bd8c9ae 100644 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java +++ b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java @@ -53,6 +53,7 @@ import org.junit.Assert; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; +import org.osgi.framework.Version; import org.osgi.service.remoteserviceadmin.EndpointDescription; import org.osgi.service.remoteserviceadmin.RemoteConstants; @@ -189,6 +190,7 @@ public class PojoConfigurationTypeHandlerTest extends TestCase { EasyMock.replay(sref); Map<String, Object> props = new HashMap<String, Object>(); + props.put(org.osgi.framework.Constants.OBJECTCLASS, new String[]{String.class.getName()}); props.put(Constants.WS_ADDRESS_PROPERTY, "http://alternate_host:80/myString"); Endpoint exportResult = p.exportService(sref, props, new Class[]{String.class}); @@ -221,6 +223,7 @@ public class PojoConfigurationTypeHandlerTest extends TestCase { } private void runAddressingTest(Map<String, Object> properties, String expectedAddress) throws Exception { + properties.put(org.osgi.framework.Constants.OBJECTCLASS, new String[]{Runnable.class.getName()}); BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class); String expectedUUID = UUID.randomUUID().toString(); EasyMock.expect(dswContext.getProperty(org.osgi.framework.Constants.FRAMEWORK_UUID)).andReturn(expectedUUID); @@ -234,8 +237,7 @@ public class PojoConfigurationTypeHandlerTest extends TestCase { dummyHttpServiceManager()) { @Override protected Endpoint createServerFromFactory(ServerFactoryBean factory, - Map<String, Object> endpointProps) { - EndpointDescription epd = new EndpointDescription(endpointProps); + EndpointDescription epd) { return new ServerWrapper(epd, null); } }; @@ -258,10 +260,8 @@ public class PojoConfigurationTypeHandlerTest extends TestCase { Endpoint result = handler.exportService(sref, properties, new Class[]{Runnable.class}); Map<String, Object> props = result.description().getProperties(); assertEquals(expectedAddress, props.get("org.apache.cxf.ws.address")); - assertEquals("Version of java. package is always 0", "0.0.0", props.get("endpoint.package.version.java.lang")); assertTrue(Arrays.equals(new String[] {"org.apache.cxf.ws"}, (String[]) props.get("service.imported.configs"))); assertTrue(Arrays.equals(new String[] {"java.lang.Runnable"}, (String[]) props.get("objectClass"))); - assertEquals(expectedUUID, props.get("endpoint.framework.uuid")); } public void t2estCreateServerException() { @@ -276,7 +276,7 @@ public class PojoConfigurationTypeHandlerTest extends TestCase { dummyHttpServiceManager()) { @Override protected Endpoint createServerFromFactory(ServerFactoryBean factory, - Map<String, Object> endpointProps) { + EndpointDescription epd) { throw new TestException(); } }; @@ -359,20 +359,15 @@ public class PojoConfigurationTypeHandlerTest extends TestCase { Map<String, Object> sd = new HashMap<String, Object>(); sd.put(org.osgi.framework.Constants.SERVICE_ID, 42); - Map<String, Object> props = pch.createEndpointProps(sd, String.class, new String[] {"org.apache.cxf.ws"}, + sd.put(org.osgi.framework.Constants.OBJECTCLASS, new String[]{String.class.getName()}); + EndpointDescription epd = pch.createEndpointDesc(sd, new String[] {"org.apache.cxf.ws"}, "http://localhost:12345", new String[] {"my_intent", "your_intent"}); - assertFalse(props.containsKey(org.osgi.framework.Constants.SERVICE_ID)); - assertEquals(42, props.get(RemoteConstants.ENDPOINT_SERVICE_ID)); - assertEquals("some_uuid1", props.get(RemoteConstants.ENDPOINT_FRAMEWORK_UUID)); - assertEquals("http://localhost:12345", props.get(RemoteConstants.ENDPOINT_ID)); - assertEquals(Arrays.asList("java.lang.String"), - Arrays.asList((Object[]) props.get(org.osgi.framework.Constants.OBJECTCLASS))); - assertEquals(Arrays.asList("org.apache.cxf.ws"), - Arrays.asList((Object[]) props.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS))); - assertEquals(Arrays.asList("my_intent", "your_intent"), - Arrays.asList((Object[]) props.get(RemoteConstants.SERVICE_INTENTS))); - assertEquals("0.0.0", props.get("endpoint.package.version.java.lang")); + assertEquals("http://localhost:12345", epd.getId()); + assertEquals(Arrays.asList("java.lang.String"), epd.getInterfaces()); + assertEquals(Arrays.asList("org.apache.cxf.ws"), epd.getConfigurationTypes()); + assertEquals(Arrays.asList("my_intent", "your_intent"), epd.getIntents()); + assertEquals(new Version("0.0.0"), epd.getPackageVersion("java.lang")); } public void t2estCreateJaxWsEndpointWithoutIntents() { http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/610ef4aa/osgi-api/pom.xml ---------------------------------------------------------------------- diff --git a/osgi-api/pom.xml b/osgi-api/pom.xml index 44e09f4..6a123eb 100644 --- a/osgi-api/pom.xml +++ b/osgi-api/pom.xml @@ -39,6 +39,14 @@ <!-- the minimal set of OSGi Compendium packages that is required for DOSGi to run --> <required-packages>org.osgi.service.remoteserviceadmin,org.osgi.service.event</required-packages> </properties> + + <dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> <build> <plugins> @@ -59,11 +67,4 @@ </plugins> </build> - <dependencies> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - </dependency> - </dependencies> - </project>
