http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Constants.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Constants.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/Constants.java new file mode 100644 index 0000000..87c2c21 --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/osgi/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.osgi; + +import org.osgi.service.remoteserviceadmin.RemoteConstants; + +public final class Constants { + + // Constants from RFC 119, they should ultimately be picked up from an OSGi class. + @Deprecated + public static final String EXPORTED_INTERFACES = RemoteConstants.SERVICE_EXPORTED_INTERFACES; + @Deprecated + public static final String EXPORTED_INTERFACES_OLD = "osgi.remote.interfaces"; // for BW compatibility + + @Deprecated + public static final String EXPORTED_CONFIGS = RemoteConstants.SERVICE_EXPORTED_CONFIGS; + @Deprecated + public static final String EXPORTED_CONFIGS_OLD = "osgi.remote.configuration.type"; // for BW compatibility + + @Deprecated + public static final String EXPORTED_INTENTS = RemoteConstants.SERVICE_EXPORTED_INTENTS; + @Deprecated + public static final String EXPORTED_INTENTS_EXTRA = RemoteConstants.SERVICE_EXPORTED_INTENTS_EXTRA; + @Deprecated + public static final String EXPORTED_INTENTS_OLD = "osgi.remote.requires.intents"; + + @Deprecated + public static final String IMPORTED = RemoteConstants.SERVICE_IMPORTED; + @Deprecated + public static final String IMPORTD_CONFIGS = RemoteConstants.SERVICE_IMPORTED_CONFIGS; + + @Deprecated + public static final String INTENTS = RemoteConstants.SERVICE_INTENTS; + + // WSDL + public static final String WSDL_CONFIG_TYPE = "wsdl"; + public static final String WSDL_CONFIG_PREFIX = "osgi.remote.configuration" + "." + WSDL_CONFIG_TYPE; + 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/79bb9a43/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java index e1ceaaa..bdbe7c5 100644 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentTracker.java @@ -18,7 +18,7 @@ */ package org.apache.cxf.dosgi.dsw.qos; -import org.apache.cxf.dosgi.dsw.Constants; +import org.apache.cxf.dosgi.dsw.osgi.Constants; import org.osgi.framework.BundleContext; import org.osgi.framework.Filter; import org.osgi.framework.InvalidSyntaxException; http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java index 31b1e42..5ee288c 100644 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentUtils.java @@ -27,7 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.cxf.dosgi.dsw.Constants; +import org.apache.cxf.dosgi.dsw.osgi.Constants; import org.apache.cxf.dosgi.dsw.util.OsgiUtils; import org.osgi.service.remoteserviceadmin.RemoteConstants; http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java new file mode 100644 index 0000000..cd1a323 --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java @@ -0,0 +1,86 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.dosgi.dsw.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.apache.cxf.helpers.CastUtils; +import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class ClassUtils { + + private static final Logger LOG = LoggerFactory.getLogger(ClassUtils.class); + + private ClassUtils() { + } + + public static List<Object> loadProviderClasses(BundleContext callingContext, + Map<String, Object> sd, String propName) { + Object serviceProviders = sd.get(propName); + if (serviceProviders != null) { + if (serviceProviders.getClass().isArray()) { + if (serviceProviders.getClass().getComponentType() == String.class) { + return loadProviders(callingContext, (String[])serviceProviders); + } else { + return Arrays.asList((Object[])serviceProviders); + } + } else if (serviceProviders.getClass() == String.class) { + String[] classNames = serviceProviders.toString().split(","); + return loadProviders(callingContext, classNames); + } else if (serviceProviders instanceof List) { + List<Object> list = CastUtils.cast((List<?>)serviceProviders); + if (!list.isEmpty()) { + List<Object> providers; + if (list.get(0).getClass() == String.class) { + providers = loadProviders(callingContext, list.toArray(new String[]{})); + } else { + providers = list; + } + return providers; + } + } else { + return Arrays.asList(serviceProviders); + } + } + return Collections.emptyList(); + + } + + private static List<Object> loadProviders(BundleContext callingContext, String[] classNames) { + List<Object> providers = new ArrayList<Object>(); + for (String className : classNames) { + try { + String realName = className.trim(); + if (!realName.isEmpty()) { + Class<?> pClass = callingContext.getBundle().loadClass(realName); + providers.add(pClass.newInstance()); + } + } catch (Exception ex) { + LOG.warn("Provider " + className.trim() + " can not be loaded or created " + ex.getMessage(), ex); + } + } + return providers; + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java index 9acd0f0..be1cba0 100644 --- a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java @@ -23,16 +23,10 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; -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.osgi.service.remoteserviceadmin.EndpointDescription; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@SuppressWarnings("deprecation") public final class OsgiUtils { public static final Logger LOG = LoggerFactory.getLogger(OsgiUtils.class); @@ -81,52 +75,4 @@ public final class OsgiUtils { return null; } - /** - * 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/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ServerWrapper.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ServerWrapper.java b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ServerWrapper.java new file mode 100644 index 0000000..d04db75 --- /dev/null +++ b/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ServerWrapper.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.dsw.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 ServerWrapper implements Endpoint { + private EndpointDescription desc; + private Server server; + + public ServerWrapper(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/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java index d9bc98d..ac3ae51 100644 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java +++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java @@ -24,6 +24,7 @@ import java.util.Hashtable; import junit.framework.TestCase; import org.apache.aries.rsa.spi.DistributionProvider; +import org.apache.cxf.dosgi.dsw.osgi.Activator; import org.easymock.EasyMock; import org.easymock.IMocksControl; import org.osgi.framework.Bundle; http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java index dcf1f2d..6215f10 100644 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java +++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProviderTest.java @@ -23,7 +23,11 @@ import java.util.List; import java.util.Map; import org.apache.aries.rsa.spi.DistributionProvider; -import org.apache.cxf.dosgi.dsw.Constants; +import org.apache.cxf.dosgi.dsw.handlers.pojo.PojoConfigurationTypeHandler; +import org.apache.cxf.dosgi.dsw.handlers.pojo.WsdlConfigurationTypeHandler; +import org.apache.cxf.dosgi.dsw.handlers.rest.JaxRSPojoConfigurationTypeHandler; +import org.apache.cxf.dosgi.dsw.httpservice.HttpServiceManager; +import org.apache.cxf.dosgi.dsw.osgi.Constants; import org.apache.cxf.dosgi.dsw.qos.DefaultIntentMapFactory; import org.apache.cxf.dosgi.dsw.qos.IntentManager; import org.apache.cxf.dosgi.dsw.qos.IntentManagerImpl; http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java index a0774be..a38fea7 100644 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java +++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClassUtilsTest.java @@ -18,8 +18,6 @@ */ package org.apache.cxf.dosgi.dsw.handlers; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; @@ -28,6 +26,7 @@ import java.util.Map; import junit.framework.TestCase; +import org.apache.cxf.dosgi.dsw.util.ClassUtils; import org.apache.cxf.dosgi.dsw.util.Provider; import org.easymock.EasyMock; import org.osgi.framework.Bundle; @@ -35,23 +34,6 @@ import org.osgi.framework.BundleContext; public class ClassUtilsTest extends TestCase { - public void testGetInterfaceClass() { - assertEquals(String.class, - ClassUtils.getInterfaceClass("Hello", "java.lang.String")); - assertNull(ClassUtils.getInterfaceClass("Hello", "java.lang.Integer")); - assertEquals(List.class, ClassUtils.getInterfaceClass( - new ArrayList<String>(), "java.util.List")); - assertEquals(Collection.class, ClassUtils.getInterfaceClass( - new ArrayList<String>(), "java.util.Collection")); - } - - public void testGetInterfaceClassFromSubclass() { - assertEquals(Map.class, ClassUtils.getInterfaceClass( - new MySubclassFour(), "java.util.Map")); - assertNull(ClassUtils.getInterfaceClass(new MySubclassFour(), - "java.util.UnknownType")); - } - public void testLoadProvidersAsString() throws Exception { BundleContext bc = mockBundleContext(); Map<String, Object> sd = Collections.<String, Object>singletonMap("providers", Provider.class.getName()); http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java deleted file mode 100644 index 10fba12..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.dosgi.dsw.handlers; - -import java.util.Dictionary; - -import javax.servlet.Servlet; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; - -import junit.framework.TestCase; - -import org.apache.cxf.Bus; -import org.apache.cxf.BusFactory; -import org.easymock.Capture; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Assert; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; -import org.osgi.service.http.HttpContext; -import org.osgi.service.http.HttpService; -import org.osgi.service.http.NamespaceException; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; - -public class HttpServiceManagerTest extends TestCase { - - public void testGetAbsoluteAddress() { - IMocksControl c = EasyMock.createControl(); - BundleContext bundleContext = c.createMock(BundleContext.class); - c.replay(); - HttpServiceManager manager = new HttpServiceManager(bundleContext, null, null, null); - String localIp = LocalHostUtil.getLocalIp(); - - String address1 = manager.getAbsoluteAddress(null, "/myservice"); - assertEquals("http://" + localIp + ":8181/cxf/myservice", address1); - - String address2 = manager.getAbsoluteAddress("/mycontext", "/myservice"); - assertEquals("http://" + localIp + ":8181/mycontext/myservice", address2); - - c.verify(); - } - - public void testRegisterAndUnregisterServlet() throws Exception { - IMocksControl c = EasyMock.createControl(); - BundleContext dswContext = c.createMock(BundleContext.class); - Filter filter = c.createMock(Filter.class); - expect(dswContext.createFilter(EasyMock.eq("(service.id=12345)"))).andReturn(filter).once(); - Capture<ServiceListener> captured = EasyMock.newCapture(); - dswContext.addServiceListener(EasyMock.capture(captured), EasyMock.<String>anyObject()); - expectLastCall().atLeastOnce(); - expect(dswContext.getProperty("org.apache.cxf.httpservice.requirefilter")).andReturn(null).atLeastOnce(); - ServletConfig config = c.createMock(ServletConfig.class); - expect(config.getInitParameter(EasyMock.<String>anyObject())).andReturn(null).atLeastOnce(); - ServletContext servletContext = c.createMock(ServletContext.class); - expect(config.getServletContext()).andReturn(servletContext); - final HttpService httpService = new DummyHttpService(config); - ServiceReference<?> sr = c.createMock(ServiceReference.class); - expect(sr.getProperty(EasyMock.eq("service.id"))).andReturn(12345L).atLeastOnce(); - expect(servletContext.getResourceAsStream((String)EasyMock.anyObject())).andReturn(null).anyTimes(); - c.replay(); - - HttpServiceManager h = new HttpServiceManager(dswContext, null, null, null) { - @Override - protected HttpService getHttpService() { - return httpService; - } - }; - Bus bus = BusFactory.newInstance().createBus(); - h.registerServlet(bus, "/myService", dswContext, 12345L); - - ServiceEvent event = new ServiceEvent(ServiceEvent.UNREGISTERING, sr); - captured.getValue().serviceChanged(event); - c.verify(); - } - - static class DummyHttpService implements HttpService { - - private ServletConfig config; - - DummyHttpService(ServletConfig config) { - this.config = config; - } - - @SuppressWarnings("rawtypes") - public void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context) - throws ServletException, NamespaceException { - Assert.assertEquals("/myService", alias); - servlet.init(config); - } - - public void registerResources(String alias, String name, HttpContext context) throws NamespaceException { - throw new RuntimeException("This method should not be called"); - } - - public void unregister(String alias) { - } - - public HttpContext createDefaultHttpContext() { - return EasyMock.createNiceMock(HttpContext.class); - } - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java deleted file mode 100644 index 6c8e35a..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.dosgi.dsw.handlers; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import junit.framework.TestCase; - -import org.apache.cxf.dosgi.dsw.Constants; -import org.apache.cxf.jaxrs.provider.JAXBElementProvider; -import org.apache.cxf.jaxrs.provider.aegis.AegisElementProvider; -import org.easymock.EasyMock; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -public class JaxRSUtilsTest extends TestCase { - - private void addRequiredProps(Map<String, Object> props) { - props.put(RemoteConstants.ENDPOINT_ID, "http://google.de"); - props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "myGreatConfiguration"); - props.put(org.osgi.framework.Constants.OBJECTCLASS, new String[] {"my.class"}); - } - - public void testNoGlobalProviders() { - Map<String, Object> props = new HashMap<String, Object>(); - addRequiredProps(props); - props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false"); - - assertEquals(0, JaxRSUtils.getProviders(null, props).size()); - } - - public void testAegisProvider() { - Map<String, Object> props = new HashMap<String, Object>(); - props.put(Constants.RS_DATABINDING_PROP_KEY, "aegis"); - props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false"); - - addRequiredProps(props); - - List<Object> providers = JaxRSUtils.getProviders(null, props); - assertEquals(1, providers.size()); - assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName()); - } - - @SuppressWarnings("rawtypes") - public void testServiceProviders() { - Map<String, Object> props = new HashMap<String, Object>(); - props.put(Constants.RS_PROVIDER_PROP_KEY, new Object[] { - new AegisElementProvider() - }); - props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false"); - addRequiredProps(props); - - List<Object> providers = JaxRSUtils.getProviders(null, props); - assertEquals(1, providers.size()); - assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName()); - } - - public void testServiceProviderProperty() throws Exception { - BundleContext bc = EasyMock.createMock(BundleContext.class); - Bundle bundle = EasyMock.createMock(Bundle.class); - bc.getBundle(); - EasyMock.expectLastCall().andReturn(bundle).times(2); - bundle.loadClass(AegisElementProvider.class.getName()); - EasyMock.expectLastCall().andReturn(AegisElementProvider.class); - bundle.loadClass(JAXBElementProvider.class.getName()); - EasyMock.expectLastCall().andReturn(JAXBElementProvider.class); - EasyMock.replay(bc, bundle); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put(Constants.RS_PROVIDER_PROP_KEY, - "\r\n " + AegisElementProvider.class.getName() + " , \r\n" - + JAXBElementProvider.class.getName() + "\r\n"); - - props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false"); - addRequiredProps(props); - - List<Object> providers = JaxRSUtils.getProviders(bc, props); - assertEquals(2, providers.size()); - assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName()); - assertEquals(JAXBElementProvider.class.getName(), providers.get(1).getClass().getName()); - } - - public void testServiceProviderStrings() throws Exception { - BundleContext bc = EasyMock.createMock(BundleContext.class); - Bundle bundle = EasyMock.createMock(Bundle.class); - bc.getBundle(); - EasyMock.expectLastCall().andReturn(bundle).times(2); - bundle.loadClass(AegisElementProvider.class.getName()); - EasyMock.expectLastCall().andReturn(AegisElementProvider.class); - bundle.loadClass(JAXBElementProvider.class.getName()); - EasyMock.expectLastCall().andReturn(JAXBElementProvider.class); - EasyMock.replay(bc, bundle); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put(Constants.RS_PROVIDER_PROP_KEY, new String[] { - "\r\n " + AegisElementProvider.class.getName(), - JAXBElementProvider.class.getName() + "\r\n" - }); - - props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false"); - addRequiredProps(props); - - List<Object> providers = JaxRSUtils.getProviders(bc, props); - assertEquals(2, providers.size()); - assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName()); - assertEquals(JAXBElementProvider.class.getName(), providers.get(1).getClass().getName()); - } - - @SuppressWarnings({ - "rawtypes", "unchecked" - }) - public void testCustomGlobalProvider() throws Exception { - ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class); - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - bc.getServiceReferences((String)null, JaxRSUtils.PROVIDERS_FILTER); - EasyMock.expectLastCall().andReturn(new ServiceReference[] {sref}); - sref.getProperty(Constants.RS_PROVIDER_EXPECTED_PROP_KEY); - EasyMock.expectLastCall().andReturn(false); - bc.getService(sref); - AegisElementProvider<?> p = new AegisElementProvider(); - EasyMock.expectLastCall().andReturn(p); - EasyMock.replay(bc, sref); - Map<String, Object> props = new HashMap<String, Object>(); - addRequiredProps(props); - - List<Object> providers = JaxRSUtils.getProviders(bc, props); - assertEquals(1, providers.size()); - assertSame(p, providers.get(0)); - } - - @SuppressWarnings({ - "rawtypes", "unchecked" - }) - public void testNoCustomGlobalProvider() throws Exception { - ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class); - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - bc.getServiceReferences((String)null, JaxRSUtils.PROVIDERS_FILTER); - EasyMock.expectLastCall().andReturn(new ServiceReference[] {sref}); - sref.getProperty(Constants.RS_PROVIDER_PROP_KEY); - EasyMock.expectLastCall().andReturn(false); - bc.getService(sref); - AegisElementProvider<?> p = new AegisElementProvider(); - EasyMock.expectLastCall().andReturn(p); - EasyMock.replay(bc); - Map<String, Object> props = new HashMap<String, Object>(); - props.put(Constants.RS_PROVIDER_EXPECTED_PROP_KEY, "true"); - addRequiredProps(props); - - List<Object> providers = JaxRSUtils.getProviders(bc, props); - assertEquals(0, providers.size()); - } - - @SuppressWarnings({ - "rawtypes", "unchecked" - }) - public void testCustomGlobalProviderExpected() throws Exception { - ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class); - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - bc.getServiceReferences((String)null, JaxRSUtils.PROVIDERS_FILTER); - EasyMock.expectLastCall().andReturn(new ServiceReference[] {sref}); - sref.getProperty(Constants.RS_PROVIDER_PROP_KEY); - EasyMock.expectLastCall().andReturn(true); - bc.getService(sref); - AegisElementProvider<?> p = new AegisElementProvider(); - EasyMock.expectLastCall().andReturn(p); - EasyMock.replay(bc, sref); - Map<String, Object> props = new HashMap<String, Object>(); - props.put(Constants.RS_PROVIDER_EXPECTED_PROP_KEY, "true"); - addRequiredProps(props); - - List<Object> providers = JaxRSUtils.getProviders(bc, props); - assertEquals(1, providers.size()); - assertSame(p, providers.get(0)); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java deleted file mode 100644 index b6b05ea..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java +++ /dev/null @@ -1,422 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.dosgi.dsw.handlers; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import javax.xml.namespace.QName; - -import junit.framework.TestCase; - -import org.apache.aries.rsa.spi.Endpoint; -import org.apache.aries.rsa.util.EndpointHelper; -import org.apache.cxf.dosgi.dsw.Constants; -import org.apache.cxf.dosgi.dsw.handlers.jaxws.MyJaxWsEchoService; -import org.apache.cxf.dosgi.dsw.handlers.simple.MySimpleEchoService; -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.endpoint.AbstractEndpointFactory; -import org.apache.cxf.endpoint.EndpointImpl; -import org.apache.cxf.endpoint.Server; -import org.apache.cxf.feature.Feature; -import org.apache.cxf.frontend.ClientProxyFactoryBean; -import org.apache.cxf.frontend.ServerFactoryBean; -import org.apache.cxf.jaxws.support.JaxWsEndpointImpl; -import org.apache.cxf.transport.Destination; -import org.apache.cxf.ws.addressing.AttributedURIType; -import org.apache.cxf.ws.addressing.EndpointReferenceType; -import org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean; -import org.easymock.EasyMock; -import org.easymock.IAnswer; -import org.easymock.IMocksControl; -import org.junit.Assert; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Version; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -public class PojoConfigurationTypeHandlerTest extends TestCase { - - public void testGetPojoAddressEndpointURI() { - IntentManager intentManager = new IntentManagerImpl(new IntentMap()); - PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, - intentManager, - dummyHttpServiceManager()); - Map<String, Object> sd = new HashMap<String, Object>(); - String url = "http://somewhere:1234/blah"; - sd.put(RemoteConstants.ENDPOINT_ID, url); - assertEquals(url, handler.getServerAddress(sd, String.class)); - } - - private HttpServiceManager dummyHttpServiceManager() { - return new HttpServiceManager(null, null, null, null); - } - - public void testGetPojoAddressEndpointCxf() { - IntentManager intentManager = new IntentManagerImpl(new IntentMap()); - PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, - intentManager, - dummyHttpServiceManager()); - Map<String, Object> sd = new HashMap<String, Object>(); - String url = "http://somewhere:29/boo"; - sd.put("org.apache.cxf.ws.address", url); - assertEquals(url, handler.getServerAddress(sd, String.class)); - } - - public void testGetPojoAddressEndpointPojo() { - IntentManager intentManager = new IntentManagerImpl(new IntentMap()); - PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, - intentManager, - dummyHttpServiceManager()); - Map<String, Object> sd = new HashMap<String, Object>(); - String url = "http://somewhere:32768/foo"; - sd.put("osgi.remote.configuration.pojo.address", url); - assertEquals(url, handler.getServerAddress(sd, String.class)); - } - - public void testGetDefaultPojoAddress() { - IntentManager intentManager = new IntentManagerImpl(new IntentMap()); - PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, - intentManager, - dummyHttpServiceManager()); - Map<String, Object> sd = new HashMap<String, Object>(); - assertEquals("/java/lang/String", handler.getServerAddress(sd, String.class)); - } - - // todo: add test for data bindings - public void testCreateProxy() { - IMocksControl c = EasyMock.createNiceControl(); - BundleContext bc1 = c.createMock(BundleContext.class); - - BundleContext requestingContext = c.createMock(BundleContext.class); - - final ClientProxyFactoryBean cpfb = c.createMock(ClientProxyFactoryBean.class); - ReflectionServiceFactoryBean sf = c.createMock(ReflectionServiceFactoryBean.class); - EasyMock.expect(cpfb.getServiceFactory()).andReturn(sf).anyTimes(); - IntentManager intentManager = new IntentManagerImpl(new IntentMap()) { - @Override - public String[] applyIntents(List<Feature> features, - AbstractEndpointFactory factory, - Map<String, Object> sd) { - return new String[0]; - } - }; - PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(bc1, - intentManager, - dummyHttpServiceManager()) { - @Override - protected ClientProxyFactoryBean createClientProxyFactoryBean(Map<String, Object> sd, Class<?> iClass) { - return cpfb; - } - }; - - Class<?>[] exportedInterfaces = new Class[]{Runnable.class}; - - Map<String, Object> props = new HashMap<String, Object>(); - props.put(RemoteConstants.ENDPOINT_ID, "http://google.de/"); - EndpointHelper.addObjectClass(props, exportedInterfaces); - props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, new String[]{"my.config"}); - EndpointDescription endpoint = new EndpointDescription(props); - - cpfb.setAddress((String)EasyMock.eq(props.get(RemoteConstants.ENDPOINT_ID))); - EasyMock.expectLastCall().atLeastOnce(); - - cpfb.setServiceClass(EasyMock.eq(Runnable.class)); - EasyMock.expectLastCall().atLeastOnce(); - - c.replay(); - ClassLoader cl = null; - Object proxy = p.importEndpoint(cl, requestingContext, exportedInterfaces, endpoint); - assertNotNull(proxy); - assertTrue("Proxy is not of the requested type! ", proxy instanceof Runnable); - c.verify(); - } - - public void testCreateServerWithAddressProperty() throws Exception { - BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.replay(dswContext); - - String myService = "Hi"; - final ServerFactoryBean sfb = createMockServerFactoryBean(); - - IntentMap intentMap = new IntentMap(); - IntentManager intentManager = new IntentManagerImpl(intentMap) { - @Override - public String[] applyIntents(List<Feature> features, AbstractEndpointFactory factory, - Map<String, Object> sd) { - return new String[]{}; - } - }; - PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, intentManager, - dummyHttpServiceManager()) { - @Override - protected ServerFactoryBean createServerFactoryBean(Map<String, Object> sd, Class<?> iClass) { - return sfb; - } - }; - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.replay(bundleContext); - - Class<?>[] exportedInterface = new Class[]{String.class}; - Map<String, Object> props = new HashMap<String, Object>(); - EndpointHelper.addObjectClass(props, exportedInterface); - props.put(Constants.WS_ADDRESS_PROPERTY, "http://alternate_host:80/myString"); - - Endpoint exportResult = p.exportService(myService, bundleContext, props, exportedInterface); - Map<String, Object> edProps = exportResult.description().getProperties(); - - assertNotNull(edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS)); - assertEquals(1, ((String[])edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS)).length); - assertEquals(Constants.WS_CONFIG_TYPE, ((String[])edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS))[0]); - assertEquals("http://alternate_host:80/myString", edProps.get(RemoteConstants.ENDPOINT_ID)); - } - - public void testAddressing() throws Exception { - runAddressingTest(new HashMap<String, Object>(), "http://localhost:9000/java/lang/Runnable"); - - Map<String, Object> p1 = new HashMap<String, Object>(); - p1.put("org.apache.cxf.ws.address", "http://somewhere"); - runAddressingTest(p1, "http://somewhere"); - - Map<String, Object> p2 = new HashMap<String, Object>(); - p2.put("org.apache.cxf.rs.address", "https://somewhereelse"); - runAddressingTest(p2, "https://somewhereelse"); - - Map<String, Object> p3 = new HashMap<String, Object>(); - p3.put("org.apache.cxf.ws.port", 65535); - runAddressingTest(p3, "http://localhost:65535/java/lang/Runnable"); - - Map<String, Object> p4 = new HashMap<String, Object>(); - p4.put("org.apache.cxf.ws.port", "8181"); - runAddressingTest(p4, "http://localhost:8181/java/lang/Runnable"); - } - - private void runAddressingTest(Map<String, Object> properties, String expectedAddress) throws Exception { - Class<?>[] exportedInterface = new Class[]{Runnable.class}; - EndpointHelper.addObjectClass(properties, exportedInterface); - BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class); - String expectedUUID = UUID.randomUUID().toString(); - EasyMock.expect(dswContext.getProperty(org.osgi.framework.Constants.FRAMEWORK_UUID)).andReturn(expectedUUID); - EasyMock.replay(dswContext); - - IntentManager intentManager = EasyMock.createNiceMock(IntentManager.class); - EasyMock.replay(intentManager); - - PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(dswContext, - intentManager, - dummyHttpServiceManager()) { - @Override - protected Endpoint createServerFromFactory(ServerFactoryBean factory, - EndpointDescription epd) { - return new ServerWrapper(epd, null); - } - }; - Runnable myService = EasyMock.createMock(Runnable.class); - EasyMock.replay(myService); - - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.replay(bundleContext); - - Endpoint result = handler.exportService(myService, bundleContext, properties, exportedInterface); - Map<String, Object> props = result.description().getProperties(); - assertEquals(expectedAddress, props.get("org.apache.cxf.ws.address")); - Assert.assertArrayEquals(new String[] {"org.apache.cxf.ws"}, - (String[]) props.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS)); - Assert.assertArrayEquals(new String[] {"java.lang.Runnable"}, - (String[]) props.get(org.osgi.framework.Constants.OBJECTCLASS)); - } - - public void t2estCreateServerException() { - BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.replay(dswContext); - - IntentManager intentManager = EasyMock.createNiceMock(IntentManager.class); - EasyMock.replay(intentManager); - - PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(dswContext, - intentManager, - dummyHttpServiceManager()) { - @Override - protected Endpoint createServerFromFactory(ServerFactoryBean factory, - EndpointDescription epd) { - throw new TestException(); - } - }; - - Map<String, Object> props = new HashMap<String, Object>(); - - Runnable myService = EasyMock.createMock(Runnable.class); - EasyMock.replay(myService); - try { - handler.exportService(myService, null, props, new Class[]{Runnable.class}); - fail("Expected TestException"); - } catch (TestException e) { - // Expected - } - } - - private ServerFactoryBean createMockServerFactoryBean() { - ReflectionServiceFactoryBean sf = EasyMock.createNiceMock(ReflectionServiceFactoryBean.class); - EasyMock.replay(sf); - - final StringBuilder serverURI = new StringBuilder(); - - ServerFactoryBean sfb = EasyMock.createNiceMock(ServerFactoryBean.class); - Server server = createMockServer(sfb); - - EasyMock.expect(sfb.getServiceFactory()).andReturn(sf).anyTimes(); - EasyMock.expect(sfb.create()).andReturn(server); - sfb.setAddress((String) EasyMock.anyObject()); - EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - serverURI.setLength(0); - serverURI.append(EasyMock.getCurrentArguments()[0]); - return null; - } - }); - EasyMock.expect(sfb.getAddress()).andAnswer(new IAnswer<String>() { - public String answer() throws Throwable { - return serverURI.toString(); - } - }); - EasyMock.replay(sfb); - return sfb; - } - - private Server createMockServer(final ServerFactoryBean sfb) { - AttributedURIType addr = EasyMock.createMock(AttributedURIType.class); - EasyMock.expect(addr.getValue()).andAnswer(new IAnswer<String>() { - public String answer() throws Throwable { - return sfb.getAddress(); - } - }); - EasyMock.replay(addr); - - EndpointReferenceType er = EasyMock.createMock(EndpointReferenceType.class); - EasyMock.expect(er.getAddress()).andReturn(addr); - EasyMock.replay(er); - - Destination destination = EasyMock.createMock(Destination.class); - EasyMock.expect(destination.getAddress()).andReturn(er); - EasyMock.replay(destination); - - Server server = EasyMock.createNiceMock(Server.class); - EasyMock.expect(server.getDestination()).andReturn(destination); - EasyMock.replay(server); - return server; - } - - public void testCreateEndpointProps() { - BundleContext bc = EasyMock.createNiceMock(BundleContext.class); - EasyMock.expect(bc.getProperty("org.osgi.framework.uuid")).andReturn("some_uuid1"); - EasyMock.replay(bc); - - IntentManager intentManager = new IntentManagerImpl(new IntentMap()); - PojoConfigurationTypeHandler pch = new PojoConfigurationTypeHandler(bc, - intentManager, - dummyHttpServiceManager()); - Class<?>[] exportedInterfaces = new Class[] {String.class}; - Map<String, Object> sd = new HashMap<String, Object>(); - sd.put(org.osgi.framework.Constants.SERVICE_ID, 42); - EndpointHelper.addObjectClass(sd, exportedInterfaces); - EndpointDescription epd = pch.createEndpointDesc(sd, new String[] {"org.apache.cxf.ws"}, - "http://localhost:12345", new String[] {"my_intent", "your_intent"}); - - 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() { - IMocksControl c = EasyMock.createNiceControl(); - BundleContext dswBC = c.createMock(BundleContext.class); - - IntentManager intentManager = new DummyIntentManager(); - PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(dswBC, - intentManager, - dummyHttpServiceManager()); - - Map<String, Object> sd = new HashMap<String, Object>(); - sd.put(Constants.WS_ADDRESS_PROPERTY, "/somewhere"); - BundleContext serviceBC = c.createMock(BundleContext.class); - Object myService = null; - c.replay(); - - ServerWrapper serverWrapper = (ServerWrapper)handler.exportService(myService, - serviceBC, - sd, - new Class[]{MyJaxWsEchoService.class}); - c.verify(); - - org.apache.cxf.endpoint.Endpoint ep = serverWrapper.getServer().getEndpoint(); - QName bindingName = ep.getEndpointInfo().getBinding().getName(); - Assert.assertEquals(JaxWsEndpointImpl.class, ep.getClass()); - Assert.assertEquals(new QName("http://jaxws.handlers.dsw.dosgi.cxf.apache.org/", - "MyJaxWsEchoServiceServiceSoapBinding"), - bindingName); - } - - public void t2estCreateSimpleEndpointWithoutIntents() { - IMocksControl c = EasyMock.createNiceControl(); - BundleContext dswBC = c.createMock(BundleContext.class); - - IntentManager intentManager = new DummyIntentManager(); - PojoConfigurationTypeHandler handler - = new PojoConfigurationTypeHandler(dswBC, intentManager, dummyHttpServiceManager()); - Map<String, Object> sd = new HashMap<String, Object>(); - sd.put(Constants.WS_ADDRESS_PROPERTY, "/somewhere_else"); - BundleContext serviceBC = c.createMock(BundleContext.class); - c.replay(); - ServerWrapper serverWrapper = (ServerWrapper)handler.exportService(null, serviceBC, sd, - new Class[]{MySimpleEchoService.class}); - c.verify(); - - org.apache.cxf.endpoint.Endpoint ep = serverWrapper.getServer().getEndpoint(); - QName bindingName = ep.getEndpointInfo().getBinding().getName(); - Assert.assertEquals(EndpointImpl.class, ep.getClass()); - Assert.assertEquals(new QName("http://simple.handlers.dsw.dosgi.cxf.apache.org/", - "MySimpleEchoServiceSoapBinding"), - bindingName); - } - - public static class DummyIntentManager implements IntentManager { - - @Override - public String[] applyIntents(List<Feature> features, - AbstractEndpointFactory factory, - Map<String, Object> props) { - return new String[]{}; - } - - @Override - public void assertAllIntentsSupported(Map<String, Object> serviceProperties) { - } - } - - @SuppressWarnings("serial") - public static class TestException extends RuntimeException { - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java deleted file mode 100644 index 58b5f58..0000000 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java +++ /dev/null @@ -1,267 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.dosgi.dsw.handlers; - -import java.io.PrintWriter; -import java.net.URL; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import junit.framework.TestCase; - -import org.easymock.EasyMock; -import org.junit.Assert; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.http.HttpContext; - -@SuppressWarnings({ - "unchecked", "rawtypes" - }) -public class SecurityDelegatingHttpContextTest extends TestCase { - - protected HttpContext defaultHttpContext; - protected SecurityDelegatingHttpContext httpContext; - protected CommitResponseFilter commitFilter; - protected DoNothingFilter doNothingFilter; - protected AccessDeniedFilter accessDeniedFilter; - protected String mimeType; - protected URL url; // does not need to exist - - public void setUp() throws Exception { - mimeType = "text/xml"; - url = new URL("file:test.xml"); // does not need to exist - - // Sample filters - commitFilter = new CommitResponseFilter(); - doNothingFilter = new DoNothingFilter(); - accessDeniedFilter = new AccessDeniedFilter(); - - // Mock up the default http context - defaultHttpContext = EasyMock.createNiceMock(HttpContext.class); - EasyMock.expect(defaultHttpContext.getMimeType((String)EasyMock.anyObject())).andReturn(mimeType); - EasyMock.expect(defaultHttpContext.getResource((String)EasyMock.anyObject())).andReturn(url); - EasyMock.replay(defaultHttpContext); - } - - public void testFilterRequired() throws Exception { - // Mock up the service references - ServiceReference[] serviceReferences = new ServiceReference[] {}; - - // Mock up the bundle context - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.expect(bundleContext.getServiceReferences(Filter.class.getName(), - "(org.apache.cxf.httpservice.filter=true)")) - .andReturn(serviceReferences); - EasyMock.replay(bundleContext); - - // Set up the secure http context - httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext); - httpContext.requireFilter = true; - - // Ensure that the httpContext doesn't allow the request to be processed, since there are no registered servlet - // filters - HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); - EasyMock.replay(request); - HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); - EasyMock.replay(response); - boolean requestAllowed = httpContext.handleSecurity(request, response); - Assert.assertFalse(requestAllowed); - - // Ensure that the httpContext returns true if there is no requirement for registered servlet filters - httpContext.requireFilter = false; - requestAllowed = httpContext.handleSecurity(request, response); - Assert.assertTrue(requestAllowed); - } - - public void testSingleCommitFilter() throws Exception { - // Mock up the service references - ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.replay(filterReference); - ServiceReference[] serviceReferences = new ServiceReference[] { - filterReference - }; - - // Mock up the bundle context - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject())) - .andReturn(serviceReferences); - EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter); - EasyMock.replay(bundleContext); - - // Set up the secure http context - httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext); - - // Ensure that the httpContext returns false, since the filter has committed the response - HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); - EasyMock.replay(request); - HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); - EasyMock.expect(response.isCommitted()).andReturn(false); // the first call checks to see whether to invoke the - // filter - EasyMock.expect(response.isCommitted()).andReturn(true); // the second is called to determine the handleSecurity - // return value - EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out)); - EasyMock.replay(response); - Assert.assertFalse(httpContext.handleSecurity(request, response)); - - // Ensure that the appropriate filters were called - Assert.assertTrue(commitFilter.called); - Assert.assertFalse(doNothingFilter.called); - Assert.assertFalse(accessDeniedFilter.called); - } - - public void testFilterChain() throws Exception { - // Mock up the service references - ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.replay(filterReference); - ServiceReference[] serviceReferences = new ServiceReference[] { - filterReference, filterReference - }; - - // Mock up the bundle context - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject())) - .andReturn(serviceReferences); - EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter); - EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter); - EasyMock.replay(bundleContext); - - // Set up the secure http context - httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext); - - // Ensure that the httpContext returns false, since the filter has committed the response - HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); - EasyMock.replay(request); - HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); - EasyMock.expect(response.isCommitted()).andReturn(false); // doNothingFilter should not commit the response - EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out)); - EasyMock.expect(response.isCommitted()).andReturn(false); - EasyMock.expect(response.isCommitted()).andReturn(true); // the commit filter indicating that it committed the - // response - EasyMock.replay(response); - Assert.assertFalse(httpContext.handleSecurity(request, response)); - - // Ensure that the appropriate filters were called - Assert.assertTrue(doNothingFilter.called); - Assert.assertTrue(commitFilter.called); - Assert.assertFalse(accessDeniedFilter.called); - } - - public void testAllowRequest() throws Exception { - // Mock up the service references - ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class); - EasyMock.replay(filterReference); - ServiceReference[] serviceReferences = new ServiceReference[] { - filterReference - }; - - // Mock up the bundle context - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject())) - .andReturn(serviceReferences); - EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter); - EasyMock.replay(bundleContext); - - // Set up the secure http context - httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext); - - // Ensure that the httpContext returns true, since the filter has not committed the response - HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); - EasyMock.replay(request); - HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); - EasyMock.expect(response.isCommitted()).andReturn(false); - EasyMock.replay(response); - Assert.assertTrue(httpContext.handleSecurity(request, response)); - - // Ensure that the appropriate filters were called - Assert.assertTrue(doNothingFilter.called); - Assert.assertFalse(commitFilter.called); - Assert.assertFalse(accessDeniedFilter.called); - } - - public void testDelegation() throws Exception { - BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class); - EasyMock.replay(bundleContext); - - // Set up the secure http context - httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext); - - // Ensure that it delegates non-security calls to the wrapped implementation (in this case, the mock) - Assert.assertEquals(mimeType, httpContext.getMimeType("")); - Assert.assertEquals(url, httpContext.getResource("")); - } -} - -class CommitResponseFilter implements Filter { - - boolean called; - - public void init(FilterConfig filterConfig) throws ServletException { - } - - public void destroy() { - } - - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws java.io.IOException, javax.servlet.ServletException { - called = true; - response.getWriter().write("committing the response"); - } -} - -class DoNothingFilter implements Filter { - - boolean called; - - public void init(FilterConfig filterConfig) throws ServletException { - } - - public void destroy() { - } - - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws java.io.IOException, javax.servlet.ServletException { - called = true; - chain.doFilter(request, response); - } -} - -class AccessDeniedFilter implements Filter { - - boolean called; - - public void init(FilterConfig filterConfig) throws ServletException { - } - - public void destroy() { - } - - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws java.io.IOException, javax.servlet.ServletException { - called = true; - ((HttpServletResponse)response).sendError(HttpServletResponse.SC_FORBIDDEN); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java ---------------------------------------------------------------------- diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java index 64beeac..3b909d6 100644 --- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java +++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java @@ -26,6 +26,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.cxf.dosgi.dsw.handlers.pojo.ServiceInvocationHandler; + import junit.framework.TestCase; public class ServiceInvocationHandlerTest extends TestCase {
