Repository: cxf-dosgi Updated Branches: refs/heads/master 0a4950cfe -> 4de42394b
Cleanup util package Project: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/commit/4de42394 Tree: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/tree/4de42394 Diff: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/diff/4de42394 Branch: refs/heads/master Commit: 4de42394b1b37f34d6c3e924eb49cf9d2b9870e4 Parents: 0a4950c Author: Christian Schneider <[email protected]> Authored: Tue Jan 3 17:41:34 2017 +0100 Committer: Christian Schneider <[email protected]> Committed: Tue Jan 3 17:41:34 2017 +0100 ---------------------------------------------------------------------- common/bnd.bnd | 3 +- .../dosgi/common/endpoint/ServerEndpoint.java | 49 ++++++++ .../common/intent/impl/IntentManagerImpl.java | 18 ++- .../cxf/dosgi/common/policy/Exporter.java | 4 + .../cxf/dosgi/common/util/ClassUtils.java | 86 -------------- .../apache/cxf/dosgi/common/util/OsgiUtils.java | 78 ------------- .../cxf/dosgi/common/util/PropertyHelper.java | 64 +++++++++++ .../cxf/dosgi/common/util/ServerEndpoint.java | 49 -------- .../cxf/dosgi/common/util/StringPlus.java | 72 ------------ .../cxf/dosgi/common/util/ClassUtilsTest.java | 114 ------------------- .../cxf/dosgi/common/util/OsgiUtilsTest.java | 70 ------------ .../dosgi/common/util/PropertyHelperTest.java | 71 ++++++++++++ .../cxf/dosgi/dsw/handlers/rest/RsProvider.java | 16 +-- .../cxf/dosgi/dsw/handlers/ws/WsProvider.java | 10 +- .../cxf/dosgi/dsw/handlers/ws/WsdlSupport.java | 10 +- .../ws/PojoConfigurationTypeHandlerTest.java | 2 +- 16 files changed, 216 insertions(+), 500 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/bnd.bnd ---------------------------------------------------------------------- diff --git a/common/bnd.bnd b/common/bnd.bnd index 5bee711..a8b330b 100644 --- a/common/bnd.bnd +++ b/common/bnd.bnd @@ -3,5 +3,6 @@ Export-Package: \ org.apache.cxf.dosgi.common.httpservice,\ org.apache.cxf.dosgi.common.util,\ org.apache.cxf.dosgi.common.intent,\ - org.apache.cxf.dosgi.common.proxy + org.apache.cxf.dosgi.common.proxy,\ + org.apache.cxf.dosgi.common.endpoint http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/main/java/org/apache/cxf/dosgi/common/endpoint/ServerEndpoint.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/endpoint/ServerEndpoint.java b/common/src/main/java/org/apache/cxf/dosgi/common/endpoint/ServerEndpoint.java new file mode 100644 index 0000000..080b1c5 --- /dev/null +++ b/common/src/main/java/org/apache/cxf/dosgi/common/endpoint/ServerEndpoint.java @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.dosgi.common.endpoint; + +import java.io.IOException; + +import org.apache.aries.rsa.spi.Endpoint; +import org.apache.cxf.endpoint.Server; +import org.osgi.service.remoteserviceadmin.EndpointDescription; + +public class ServerEndpoint implements Endpoint { + private EndpointDescription desc; + private Server server; + + public ServerEndpoint(EndpointDescription desc, Server server) { + this.desc = desc; + this.server = server; + } + + public Server getServer() { + return this.server; + } + + @Override + public void close() throws IOException { + this.server.destroy(); + } + + @Override + public EndpointDescription description() { + return this.desc; + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java b/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java index de0247e..596f427 100644 --- a/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java +++ b/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java @@ -29,7 +29,7 @@ import java.util.Set; import java.util.concurrent.Callable; import org.apache.cxf.dosgi.common.intent.IntentManager; -import org.apache.cxf.dosgi.common.util.OsgiUtils; +import org.apache.cxf.dosgi.common.util.PropertyHelper; import org.osgi.framework.BundleContext; import org.osgi.framework.Filter; import org.osgi.framework.FrameworkUtil; @@ -182,22 +182,18 @@ public class IntentManagerImpl implements IntentManager { public Set<String> getExported(Map<String, Object> sd) { Set<String> allIntents = new HashSet<String>(); - Collection<String> intents = OsgiUtils + Collection<String> intents = PropertyHelper .getMultiValueProperty(sd.get(RemoteConstants.SERVICE_EXPORTED_INTENTS)); - if (intents != null) { - allIntents.addAll(parseIntents(intents)); - } - Collection<String> intents2 = OsgiUtils + allIntents.addAll(parseIntents(intents)); + Collection<String> intents2 = PropertyHelper .getMultiValueProperty(sd.get(RemoteConstants.SERVICE_EXPORTED_INTENTS_EXTRA)); - if (intents2 != null) { - allIntents.addAll(parseIntents(intents2)); - } + allIntents.addAll(parseIntents(intents2)); return allIntents; } public Set<String> getImported(Map<String, Object> sd) { - Collection<String> intents = OsgiUtils.getMultiValueProperty(sd.get(RemoteConstants.SERVICE_INTENTS)); - return intents == null ? new HashSet<String>() : new HashSet<String>(intents); + Collection<String> intents = PropertyHelper.getMultiValueProperty(sd.get(RemoteConstants.SERVICE_INTENTS)); + return new HashSet<String>(intents); } private static Collection<String> parseIntents(Collection<String> intents) { http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/main/java/org/apache/cxf/dosgi/common/policy/Exporter.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/policy/Exporter.java b/common/src/main/java/org/apache/cxf/dosgi/common/policy/Exporter.java index bf2578c..e9fab2e 100644 --- a/common/src/main/java/org/apache/cxf/dosgi/common/policy/Exporter.java +++ b/common/src/main/java/org/apache/cxf/dosgi/common/policy/Exporter.java @@ -28,6 +28,10 @@ import org.apache.aries.rsa.spi.ExportPolicy; import org.osgi.framework.ServiceReference; import org.osgi.service.component.annotations.Component; +/** + * This export policy allows to export services with just the rs or ws address property. + * This policy must be configured in the Aries RSA TopologyManager config to be activated. + */ @Component // (// immediate = true, // http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/main/java/org/apache/cxf/dosgi/common/util/ClassUtils.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/util/ClassUtils.java b/common/src/main/java/org/apache/cxf/dosgi/common/util/ClassUtils.java deleted file mode 100644 index 9190b6c..0000000 --- a/common/src/main/java/org/apache/cxf/dosgi/common/util/ClassUtils.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.dosgi.common.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.apache.cxf.helpers.CastUtils; -import org.osgi.framework.BundleContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class ClassUtils { - - private static final Logger LOG = LoggerFactory.getLogger(ClassUtils.class); - - private ClassUtils() { - } - - public static List<Object> loadProviderClasses(BundleContext callingContext, - Map<String, Object> sd, String propName) { - Object serviceProviders = sd.get(propName); - if (serviceProviders != null) { - if (serviceProviders.getClass().isArray()) { - if (serviceProviders.getClass().getComponentType() == String.class) { - return loadProviders(callingContext, (String[])serviceProviders); - } else { - return Arrays.asList((Object[])serviceProviders); - } - } else if (serviceProviders.getClass() == String.class) { - String[] classNames = serviceProviders.toString().split(","); - return loadProviders(callingContext, classNames); - } else if (serviceProviders instanceof List) { - List<Object> list = CastUtils.cast((List<?>)serviceProviders); - if (!list.isEmpty()) { - List<Object> providers; - if (list.get(0).getClass() == String.class) { - providers = loadProviders(callingContext, list.toArray(new String[]{})); - } else { - providers = list; - } - return providers; - } - } else { - return Arrays.asList(serviceProviders); - } - } - return Collections.emptyList(); - - } - - private static List<Object> loadProviders(BundleContext callingContext, String[] classNames) { - List<Object> providers = new ArrayList<Object>(); - for (String className : classNames) { - try { - String realName = className.trim(); - if (!realName.isEmpty()) { - Class<?> pClass = callingContext.getBundle().loadClass(realName); - providers.add(pClass.newInstance()); - } - } catch (Exception ex) { - LOG.warn("Provider " + className.trim() + " can not be loaded or created " + ex.getMessage(), ex); - } - } - return providers; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/main/java/org/apache/cxf/dosgi/common/util/OsgiUtils.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/util/OsgiUtils.java b/common/src/main/java/org/apache/cxf/dosgi/common/util/OsgiUtils.java deleted file mode 100644 index aa24903..0000000 --- a/common/src/main/java/org/apache/cxf/dosgi/common/util/OsgiUtils.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.dosgi.common.util; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class OsgiUtils { - - public static final Logger LOG = LoggerFactory.getLogger(OsgiUtils.class); - - private OsgiUtils() { - } - - public static boolean getBooleanProperty(Map<String, Object> sd, String name) { - return toBoolean(sd.get(name)); - } - - public static boolean toBoolean(Object value) { - return value instanceof Boolean && (Boolean) value - || value instanceof String && Boolean.parseBoolean((String)value); - } - - @SuppressWarnings("unchecked") - public static Collection<String> getMultiValueProperty(Object property) { - if (property == null) { - return null; - } else if (property instanceof Collection) { - return (Collection<String>)property; - } else if (property instanceof String[]) { - return Arrays.asList((String[])property); - } else { - return Collections.singleton(property.toString()); - } - } - - public static String getProperty(EndpointDescription endpoint, String name) { - return getProperty(endpoint.getProperties(), name); - } - - public static String getProperty(Map<String, Object> dict, String name) { - Object value = dict.get(name); - return value instanceof String ? (String) value : null; - } - - public static String getFirstNonEmptyStringProperty(Map<String, Object> dict, String ... keys) { - for (String key : keys) { - String value = getProperty(dict, key); - if (value != null) { - return value; - } - } - return null; - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/main/java/org/apache/cxf/dosgi/common/util/PropertyHelper.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/util/PropertyHelper.java b/common/src/main/java/org/apache/cxf/dosgi/common/util/PropertyHelper.java new file mode 100644 index 0000000..6a5c64c --- /dev/null +++ b/common/src/main/java/org/apache/cxf/dosgi/common/util/PropertyHelper.java @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.dosgi.common.util; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class PropertyHelper { + + public static final Logger LOG = LoggerFactory.getLogger(PropertyHelper.class); + + private PropertyHelper() { + } + + @SuppressWarnings("unchecked") + public static Collection<String> getMultiValueProperty(Object property) { + if (property == null) { + return Collections.emptyList(); + } else if (property instanceof Collection) { + return (Collection<String>)property; + } else if (property instanceof String[]) { + return Arrays.asList((String[])property); + } else { + return Collections.singleton(property.toString()); + } + } + + public static String getProperty(Map<String, Object> dict, String name) { + Object value = dict.get(name); + return value instanceof String ? (String) value : null; + } + + public static String getFirstNonEmptyStringProperty(Map<String, Object> dict, String ... keys) { + for (String key : keys) { + String value = getProperty(dict, key); + if (value != null) { + return value; + } + } + return null; + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/main/java/org/apache/cxf/dosgi/common/util/ServerEndpoint.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/util/ServerEndpoint.java b/common/src/main/java/org/apache/cxf/dosgi/common/util/ServerEndpoint.java deleted file mode 100644 index 5d6d1a7..0000000 --- a/common/src/main/java/org/apache/cxf/dosgi/common/util/ServerEndpoint.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.dosgi.common.util; - -import java.io.IOException; - -import org.apache.aries.rsa.spi.Endpoint; -import org.apache.cxf.endpoint.Server; -import org.osgi.service.remoteserviceadmin.EndpointDescription; - -public class ServerEndpoint implements Endpoint { - private EndpointDescription desc; - private Server server; - - public ServerEndpoint(EndpointDescription desc, Server server) { - this.desc = desc; - this.server = server; - } - - public Server getServer() { - return this.server; - } - - @Override - public void close() throws IOException { - this.server.destroy(); - } - - @Override - public EndpointDescription description() { - return this.desc; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/main/java/org/apache/cxf/dosgi/common/util/StringPlus.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/util/StringPlus.java b/common/src/main/java/org/apache/cxf/dosgi/common/util/StringPlus.java deleted file mode 100644 index c7123b2..0000000 --- a/common/src/main/java/org/apache/cxf/dosgi/common/util/StringPlus.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.dosgi.common.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class StringPlus { - - private static final Logger LOG = LoggerFactory.getLogger(StringPlus.class); - - private StringPlus() { - // never constructed - } - - @SuppressWarnings("rawtypes") - public static String[] normalize(Object object) { - if (object instanceof String) { - String s = (String)object; - String[] values = s.split(","); - List<String> list = new ArrayList<String>(); - for (String val : values) { - String actualValue = val.trim(); - if (!actualValue.isEmpty()) { - list.add(actualValue); - } - } - return list.toArray(new String[list.size()]); - } - - if (object instanceof String[]) { - return (String[])object; - } - - if (object instanceof Collection) { - Collection col = (Collection)object; - List<String> ar = new ArrayList<String>(col.size()); - for (Object o : col) { - if (o instanceof String) { - String s = (String)o; - ar.add(s); - } else { - LOG.warn("stringPlus contained non string element in list! Element was skipped"); - } - } - return ar.toArray(new String[ar.size()]); - } - - return null; - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/test/java/org/apache/cxf/dosgi/common/util/ClassUtilsTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/util/ClassUtilsTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/util/ClassUtilsTest.java deleted file mode 100644 index 233a18a..0000000 --- a/common/src/test/java/org/apache/cxf/dosgi/common/util/ClassUtilsTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.dosgi.common.util; - -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.easymock.EasyMock; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; - -import junit.framework.TestCase; - -public class ClassUtilsTest extends TestCase { - - public void testLoadProvidersAsString() throws Exception { - BundleContext bc = mockBundleContext(); - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", Provider.class.getName()); - List<Object> providers = ClassUtils.loadProviderClasses(bc, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsStringArray() throws Exception { - BundleContext bc = mockBundleContext(); - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", - new String[]{Provider.class.getName()}); - List<Object> providers = ClassUtils.loadProviderClasses(bc, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsObject() throws Exception { - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", new Provider()); - List<Object> providers = ClassUtils.loadProviderClasses(null, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsObjectArray() throws Exception { - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", new Object[]{new Provider()}); - List<Object> providers = ClassUtils.loadProviderClasses(null, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsObjectList() throws Exception { - List<Object> list = new LinkedList<Object>(); - list.add(new Provider()); - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", list); - List<Object> providers = ClassUtils.loadProviderClasses(null, sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - public void testLoadProvidersAsStringList() throws Exception { - List<Object> list = new LinkedList<Object>(); - list.add(Provider.class.getName()); - Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", list); - List<Object> providers = ClassUtils.loadProviderClasses(mockBundleContext(), sd, "providers"); - assertEquals(1, providers.size()); - assertTrue(providers.get(0) instanceof Provider); - } - - private BundleContext mockBundleContext() throws Exception { - BundleContext bc = EasyMock.createMock(BundleContext.class); - Bundle bundle = EasyMock.createMock(Bundle.class); - bc.getBundle(); - EasyMock.expectLastCall().andReturn(bundle); - bundle.loadClass(Provider.class.getName()); - EasyMock.expectLastCall().andReturn(Provider.class); - EasyMock.replay(bc, bundle); - return bc; - } - - @SuppressWarnings({ "serial", "rawtypes" }) - private static class MyMapSubclass extends HashMap { - } - - @SuppressWarnings("serial") - static class MySubclassOne extends MyMapSubclass { - } - - @SuppressWarnings("serial") - static class MySubclassTwo extends MySubclassOne { - } - - @SuppressWarnings("serial") - static class MySubclassThree extends MySubclassTwo { - } - - @SuppressWarnings("serial") - static class MySubclassFour extends MySubclassThree { - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/test/java/org/apache/cxf/dosgi/common/util/OsgiUtilsTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/util/OsgiUtilsTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/util/OsgiUtilsTest.java deleted file mode 100644 index 9aabeef..0000000 --- a/common/src/test/java/org/apache/cxf/dosgi/common/util/OsgiUtilsTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.dosgi.common.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -import junit.framework.TestCase; - -public class OsgiUtilsTest extends TestCase { - - public void testMultiValuePropertyAsString() { - assertEquals(Collections.singleton("hi"), - OsgiUtils.getMultiValueProperty("hi")); - } - - public void testMultiValuePropertyAsArray() { - assertEquals(Arrays.asList("a", "b"), - OsgiUtils.getMultiValueProperty(new String[] {"a", "b"})); - } - - public void testMultiValuePropertyAsCollection() { - List<String> list = new ArrayList<String>(); - list.add("1"); - list.add("2"); - list.add("3"); - assertEquals(list, OsgiUtils.getMultiValueProperty(list)); - } - - public void testMultiValuePropertyNull() { - assertNull(OsgiUtils.getMultiValueProperty(null)); - } - - public void testGetProperty() { - Map<String, Object> p = new HashMap<String, Object>(); - p.put(RemoteConstants.ENDPOINT_ID, "http://google.de"); - p.put("notAString", new Object()); - p.put(org.osgi.framework.Constants.OBJECTCLASS, new String[]{"my.class"}); - p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, new String[]{"my.config"}); - - EndpointDescription endpoint = new EndpointDescription(p); - - assertNull(OsgiUtils.getProperty(endpoint, "unknownProp")); - assertEquals(p.get(RemoteConstants.ENDPOINT_ID), OsgiUtils.getProperty(endpoint, RemoteConstants.ENDPOINT_ID)); - assertEquals(null, OsgiUtils.getProperty(endpoint, "notAString")); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/common/src/test/java/org/apache/cxf/dosgi/common/util/PropertyHelperTest.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/util/PropertyHelperTest.java b/common/src/test/java/org/apache/cxf/dosgi/common/util/PropertyHelperTest.java new file mode 100644 index 0000000..41e8115 --- /dev/null +++ b/common/src/test/java/org/apache/cxf/dosgi/common/util/PropertyHelperTest.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.dosgi.common.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.osgi.service.remoteserviceadmin.EndpointDescription; +import org.osgi.service.remoteserviceadmin.RemoteConstants; + +import junit.framework.TestCase; + +public class PropertyHelperTest extends TestCase { + + public void testMultiValuePropertyAsString() { + assertEquals(Collections.singleton("hi"), + PropertyHelper.getMultiValueProperty("hi")); + } + + public void testMultiValuePropertyAsArray() { + assertEquals(Arrays.asList("a", "b"), + PropertyHelper.getMultiValueProperty(new String[] {"a", "b"})); + } + + public void testMultiValuePropertyAsCollection() { + List<String> list = new ArrayList<String>(); + list.add("1"); + list.add("2"); + list.add("3"); + assertEquals(list, PropertyHelper.getMultiValueProperty(list)); + } + + public void testMultiValuePropertyNull() { + assertTrue(PropertyHelper.getMultiValueProperty(null).isEmpty()); + } + + public void testGetProperty() { + Map<String, Object> p = new HashMap<String, Object>(); + p.put(RemoteConstants.ENDPOINT_ID, "http://google.de"); + p.put("notAString", new Object()); + p.put(org.osgi.framework.Constants.OBJECTCLASS, new String[]{"my.class"}); + p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, new String[]{"my.config"}); + + EndpointDescription endpoint = new EndpointDescription(p); + + assertNull(PropertyHelper.getProperty(endpoint.getProperties(), "unknownProp")); + assertEquals(p.get(RemoteConstants.ENDPOINT_ID), + PropertyHelper.getProperty(endpoint.getProperties(), RemoteConstants.ENDPOINT_ID)); + assertEquals(null, PropertyHelper.getProperty(endpoint.getProperties(), "notAString")); + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java ---------------------------------------------------------------------- diff --git a/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java b/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java index 66f6ff1..032bb46 100644 --- a/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java +++ b/provider-rs/src/main/java/org/apache/cxf/dosgi/dsw/handlers/rest/RsProvider.java @@ -18,7 +18,7 @@ */ package org.apache.cxf.dosgi.dsw.handlers.rest; -import static org.apache.cxf.dosgi.common.util.OsgiUtils.getMultiValueProperty; +import static org.apache.cxf.dosgi.common.util.PropertyHelper.getMultiValueProperty; import static org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED; import static org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_INTENTS_SUPPORTED; @@ -40,11 +40,11 @@ import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; import org.apache.cxf.binding.BindingConfiguration; import org.apache.cxf.databinding.DataBinding; +import org.apache.cxf.dosgi.common.endpoint.ServerEndpoint; import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager; import org.apache.cxf.dosgi.common.intent.IntentManager; import org.apache.cxf.dosgi.common.proxy.ProxyFactory; -import org.apache.cxf.dosgi.common.util.OsgiUtils; -import org.apache.cxf.dosgi.common.util.ServerEndpoint; +import org.apache.cxf.dosgi.common.util.PropertyHelper; import org.apache.cxf.endpoint.AbstractEndpointFactory; import org.apache.cxf.endpoint.Server; import org.apache.cxf.feature.Feature; @@ -96,7 +96,7 @@ public class RsProvider implements DistributionProvider { Set<String> intentNames = intentManager.getImported(endpoint.getProperties()); List<Object> intents = intentManager.getRequiredIntents(intentNames); Class<?> iClass = interfaces[0]; - String address = OsgiUtils.getProperty(endpoint, RsConstants.RS_ADDRESS_PROPERTY); + String address = PropertyHelper.getProperty(endpoint.getProperties(), RsConstants.RS_ADDRESS_PROPERTY); if (address == null) { LOG.warn("Remote address is unavailable"); return null; @@ -128,13 +128,13 @@ public class RsProvider implements DistributionProvider { if (!configTypeSupported(endpointProps, RsConstants.RS_CONFIG_TYPE)) { return null; } - String contextRoot = OsgiUtils.getProperty(endpointProps, RsConstants.RS_HTTP_SERVICE_CONTEXT); + String contextRoot = PropertyHelper.getProperty(endpointProps, RsConstants.RS_HTTP_SERVICE_CONTEXT); String address; Class<?> iClass = exportedInterfaces[0]; if (contextRoot == null) { address = getServerAddress(endpointProps, iClass); } else { - address = OsgiUtils.getProperty(endpointProps, RsConstants.RS_ADDRESS_PROPERTY); + address = PropertyHelper.getProperty(endpointProps, RsConstants.RS_ADDRESS_PROPERTY); if (address == null) { address = "/"; } @@ -215,7 +215,7 @@ public class RsProvider implements DistributionProvider { factory.setResourceProvider(iClass, new SingletonResourceProvider(serviceBean)); factory.setAddress(address); addContextProperties(factory, sd, RsConstants.RS_CONTEXT_PROPS_PROP_KEY); - String location = OsgiUtils.getProperty(sd, RsConstants.RS_WADL_LOCATION); + String location = PropertyHelper.getProperty(sd, RsConstants.RS_WADL_LOCATION); setWadlLocation(callingContext, factory, location); return factory; } @@ -242,7 +242,7 @@ public class RsProvider implements DistributionProvider { } private String getServerAddress(Map<String, Object> sd, Class<?> iClass) { - String address = OsgiUtils.getProperty(sd, RsConstants.RS_ADDRESS_PROPERTY); + String address = PropertyHelper.getProperty(sd, RsConstants.RS_ADDRESS_PROPERTY); return address == null ? httpServiceManager.getDefaultAddress(iClass) : address; } http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsProvider.java ---------------------------------------------------------------------- diff --git a/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsProvider.java b/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsProvider.java index 3958c8b..27fe72b 100644 --- a/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsProvider.java +++ b/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsProvider.java @@ -18,7 +18,7 @@ */ package org.apache.cxf.dosgi.dsw.handlers.ws; -import static org.apache.cxf.dosgi.common.util.OsgiUtils.getMultiValueProperty; +import static org.apache.cxf.dosgi.common.util.PropertyHelper.getMultiValueProperty; import static org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_CONFIGS_SUPPORTED; import static org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_INTENTS_SUPPORTED; @@ -38,11 +38,11 @@ import org.apache.cxf.aegis.databinding.AegisDatabinding; import org.apache.cxf.binding.BindingConfiguration; import org.apache.cxf.binding.soap.SoapBindingConfiguration; import org.apache.cxf.databinding.DataBinding; +import org.apache.cxf.dosgi.common.endpoint.ServerEndpoint; import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager; import org.apache.cxf.dosgi.common.intent.IntentManager; import org.apache.cxf.dosgi.common.proxy.ProxyFactory; -import org.apache.cxf.dosgi.common.util.OsgiUtils; -import org.apache.cxf.dosgi.common.util.ServerEndpoint; +import org.apache.cxf.dosgi.common.util.PropertyHelper; import org.apache.cxf.endpoint.AbstractEndpointFactory; import org.apache.cxf.endpoint.Server; import org.apache.cxf.feature.Feature; @@ -164,7 +164,7 @@ public class WsProvider implements DistributionProvider { Class<?> iClass = exportedInterfaces[0]; String address = getPojoAddress(endpointProps, iClass); ServerFactoryBean factory = createServerFactoryBean(endpointProps, iClass); - String contextRoot = OsgiUtils.getProperty(endpointProps, WsConstants.WS_HTTP_SERVICE_CONTEXT); + String contextRoot = PropertyHelper.getProperty(endpointProps, WsConstants.WS_HTTP_SERVICE_CONTEXT); final Long sid = (Long) endpointProps.get(RemoteConstants.ENDPOINT_SERVICE_ID); Set<String> intentNames = intentManager.getExported(endpointProps); @@ -239,7 +239,7 @@ public class WsProvider implements DistributionProvider { } protected String getClientAddress(Map<String, Object> sd) { - return OsgiUtils.getFirstNonEmptyStringProperty(sd, WsConstants.WS_ADDRESS_PROPERTY, + return PropertyHelper.getFirstNonEmptyStringProperty(sd, WsConstants.WS_ADDRESS_PROPERTY, RemoteConstants.ENDPOINT_ID); } http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsdlSupport.java ---------------------------------------------------------------------- diff --git a/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsdlSupport.java b/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsdlSupport.java index 810e445..83794c5 100644 --- a/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsdlSupport.java +++ b/provider-ws/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ws/WsdlSupport.java @@ -24,7 +24,7 @@ import java.util.Map; import javax.xml.namespace.QName; import org.apache.cxf.common.util.PackageUtils; -import org.apache.cxf.dosgi.common.util.OsgiUtils; +import org.apache.cxf.dosgi.common.util.PropertyHelper; import org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory; import org.osgi.framework.BundleContext; @@ -36,7 +36,7 @@ public final class WsdlSupport { public static void setWsdlProperties(AbstractWSDLBasedEndpointFactory factory, // BundleContext context, // Map<String, Object> sd) { - String location = OsgiUtils.getProperty(sd, WsConstants.WS_WSDL_LOCATION); + String location = PropertyHelper.getProperty(sd, WsConstants.WS_WSDL_LOCATION); if (location != null) { URL wsdlURL = context.getBundle().getResource(location); if (wsdlURL != null) { @@ -58,8 +58,8 @@ public final class WsdlSupport { 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); + String serviceNs = PropertyHelper.getProperty(sd, nsPropName); + String serviceName = PropertyHelper.getProperty(sd, namePropName); if (iClass == null && (serviceNs == null || serviceName == null)) { return null; } @@ -73,7 +73,7 @@ public final class WsdlSupport { } protected static QName getPortQName(String ns, Map<String, Object> sd, String propName) { - String portName = OsgiUtils.getProperty(sd, propName); + String portName = PropertyHelper.getProperty(sd, propName); if (portName == null) { return null; } http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/4de42394/provider-ws/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ws/PojoConfigurationTypeHandlerTest.java ---------------------------------------------------------------------- diff --git a/provider-ws/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ws/PojoConfigurationTypeHandlerTest.java b/provider-ws/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ws/PojoConfigurationTypeHandlerTest.java index b4b2f57..acbb992 100644 --- a/provider-ws/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ws/PojoConfigurationTypeHandlerTest.java +++ b/provider-ws/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ws/PojoConfigurationTypeHandlerTest.java @@ -28,10 +28,10 @@ import javax.xml.namespace.QName; import org.apache.aries.rsa.spi.Endpoint; import org.apache.aries.rsa.util.EndpointHelper; +import org.apache.cxf.dosgi.common.endpoint.ServerEndpoint; import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager; import org.apache.cxf.dosgi.common.intent.IntentManager; import org.apache.cxf.dosgi.common.intent.impl.IntentManagerImpl; -import org.apache.cxf.dosgi.common.util.ServerEndpoint; import org.apache.cxf.dosgi.dsw.handlers.jaxws.MyJaxWsEchoService; import org.apache.cxf.dosgi.dsw.handlers.simple.MySimpleEchoService; import org.apache.cxf.endpoint.EndpointImpl;
