cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r807720 - in /cxf/dosgi/trunk: dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/ dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ dsw/cxf-dsw/src/test/java/org/apache/cxf/dos...
Date Tue, 25 Aug 2009 17:13:38 GMT
Author: sergeyb
Date: Tue Aug 25 17:13:37 2009
New Revision: 807720

URL: http://svn.apache.org/viewvc?rev=807720&view=rev
Log:
Improving JAXRS integration so that custom JAXRS providers can be registered

Added:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
  (with props)
Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
    cxf/dosgi/trunk/samples/greeter_rest/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/rest/Activator.java
    cxf/dosgi/trunk/samples/greeter_rest/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml
    cxf/dosgi/trunk/samples/greeter_rest/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/rest/Activator.java
    cxf/dosgi/trunk/samples/greeter_rest/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/rest/GreeterServiceImpl2.java
    cxf/dosgi/trunk/systests/common_rest/src/main/java/org/apache/cxf/dosgi/systests/common/rest/AbstractJaxRsPublishHookTest.java
    cxf/dosgi/trunk/systests/common_rest/src/main/java/org/apache/cxf/dosgi/systests/common/rest/AbstractListenerHookServiceListenerTest.java
    cxf/dosgi/trunk/systests/single_bundle_distro_rest/src/test/resources/OSGI-INF/remote-service/remote-services.xml

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Constants.java Tue
Aug 25 17:13:37 2009
@@ -54,7 +54,10 @@
     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 = WS_CONFIG_TYPE + ".databinding";
+    public static final String RS_DATABINDING_PROP_KEY = RS_CONFIG_TYPE + ".databinding";
+    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";
     
     // POJO (old value for WS)
     public static final String WS_CONFIG_TYPE_OLD = "pojo";

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java Tue
Aug 25 17:13:37 2009
@@ -136,7 +136,9 @@
             list = new ServiceEndpointDescription[iNames.length];
             for (int i = 0; i < iNames.length; i++) {
                 Map<String, Object> props = excludeProperty(sd.getProperties(),
-                        Constants.EXPORTED_INTERFACES, Constants.EXPORTED_INTERFACES_OLD);
+                        Constants.EXPORTED_INTERFACES, Constants.EXPORTED_INTERFACES_OLD,
+                        Constants.RS_PROVIDER_GLOBAL_PROP_KEY, Constants.RS_PROVIDER_EXPECTED_PROP_KEY,
+                        Constants.RS_PROVIDER_PROP_KEY);
                 
                 String keys[] = props.keySet().toArray(new String[props.size()]);
                 for (int j = 0; j < keys.length; j++) {

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSHttpServiceConfigurationTypeHandler.java
Tue Aug 25 17:13:37 2009
@@ -86,6 +86,10 @@
         }
         
         factory.setAddress("/");
+        List<Object> providers = JaxRSUtils.getProviders(callingContext, dswContext,
sd);
+        if (providers != null && providers.size() > 0) {
+	        factory.setProviders(providers);
+        }
         
         String address = constructAddress(dswContext, contextRoot);
         

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
Tue Aug 25 17:13:37 2009
@@ -18,7 +18,6 @@
   */
 package org.apache.cxf.dosgi.dsw.handlers;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -34,7 +33,6 @@
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.model.UserResource;
-import org.apache.cxf.jaxrs.provider.AegisElementProvider;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.discovery.ServiceEndpointDescription;
@@ -74,9 +72,10 @@
           } else {
               bean.setServiceClass(iClass);
           }
-    	  if (!"jaxb".equals(sd.getProperty(Constants.RS_DATABINDING_PROP_KEY))) {
-    	      bean.setProvider(new AegisElementProvider());
-    	  }
+          List<Object> providers = JaxRSUtils.getProviders(callingContext, dswContext,
sd);
+          if (providers != null && providers.size() > 0) {
+  	        bean.setProviders(providers);
+          }
     	  Thread.currentThread().setContextClassLoader(JAXRSClientFactoryBean.class.getClassLoader());
     	  Object proxy = getProxy(bean.create(), iClass);
     	  getDistributionProvider().addRemoteService(serviceReference);
@@ -117,10 +116,8 @@
         }
         
         factory.setAddress(address);
-        
-        if (!"jaxb".equals(sd.getProperty(Constants.RS_DATABINDING_PROP_KEY))) {
-	        List<Object> providers = new ArrayList<Object>(); 
-	        providers.add(new AegisElementProvider());
+        List<Object> providers = JaxRSUtils.getProviders(callingContext, dswContext,
sd);
+        if (providers != null && providers.size() > 0) {
 	        factory.setProviders(providers);
         }
         

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java
Tue Aug 25 17:13:37 2009
@@ -21,12 +21,19 @@
 
 import java.io.InputStream;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.logging.Logger;
 
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
 import org.apache.cxf.jaxrs.model.UserResource;
+import org.apache.cxf.jaxrs.provider.AegisElementProvider;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.discovery.ServiceEndpointDescription;
 
 public class JaxRSUtils {
 
@@ -34,6 +41,57 @@
 	
 	public final static String MODEL_FOLDER = "/OSGI-INF/cxf/jaxrs/";
 	public final static String DEFAULT_MODEL = "/OSGI-INF/cxf/jaxrs/model.xml";
+	public final static String PROVIDERS_FILTER = 
+		"(|" 
+		+ "(" + Constants.OBJECTCLASS + "=javax.ws.rs.ext.MessageBodyReader" + ")"
+		+ "(" + Constants.OBJECTCLASS + "=javax.ws.rs.ext.MessageBodyWriter" + ")"
+		+ "(" + Constants.OBJECTCLASS + "=javax.ws.rs.ext.ExceptionMapper" + ")"
+		+ "(" + Constants.OBJECTCLASS + "=org.apache.cxf.jaxrs.ext.RequestHandler" + ")"
+		+ "(" + Constants.OBJECTCLASS + "=org.apache.cxf.jaxrs.ext.ResponseHandler" + ")"
+		+ "(" + Constants.OBJECTCLASS + "=org.apache.cxf.jaxrs.ext.ParameterHandler" + ")"
+		+ ")";
+	
+	public static List<Object> getProviders(BundleContext callingContext, 
+			                                BundleContext dswBC,
+			                                ServiceEndpointDescription sd) {
+		
+		List<Object> providers = new ArrayList<Object>();
+		if ("aegis".equals(sd.getProperty(org.apache.cxf.dosgi.dsw.Constants.RS_DATABINDING_PROP_KEY)))
{
+	        providers.add(new AegisElementProvider());
+        }
+        Object serviceProviders = 
+        	sd.getProperty(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_PROP_KEY);
+        if (serviceProviders != null) {
+        	providers.addAll(Arrays.asList((Object[])serviceProviders));
+        }
+		
+		Object globalQueryProp = 
+			sd.getProperty(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_GLOBAL_PROP_KEY);
+		boolean globalQueryRequired = globalQueryProp == null || OsgiUtils.toBoolean(globalQueryProp);
+        if (!globalQueryRequired) {
+        	return providers;
+        }
+		
+		boolean cxfProvidersOnly = OsgiUtils.getBooleanProperty(sd, 
+				org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_EXPECTED_PROP_KEY);
+		
+		try {
+			ServiceReference[] refs = callingContext.getServiceReferences(null, PROVIDERS_FILTER);
		
+			if (refs != null) {
+				for (ServiceReference ref : refs) {
+					if (!cxfProvidersOnly || cxfProvidersOnly 
+						&& OsgiUtils.toBoolean(
+							ref.getProperty(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_PROP_KEY))) {
+				        providers.add(callingContext.getService(ref));
+					}
+				}
+			}
+		} catch (Exception ex) {
+			ex.printStackTrace();
+			LOG.fine("Problems finding JAXRS providers " + ex.getMessage());
+		}
+		return providers;
+    }
 	
 	public static List<UserResource> getModel(BundleContext callingContext, Class<?>
iClass) {
 		String classModel = MODEL_FOLDER + iClass.getSimpleName() + "-model.xml";

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
Tue Aug 25 17:13:37 2009
@@ -1,3 +1,21 @@
+/** 
+  * Licensed to the Apache Software Foundation (ASF) under one 
+  * or more contributor license agreements. See the NOTICE file 
+  * distributed with this work for additional information 
+  * regarding copyright ownership. The ASF licenses this file 
+  * to you under the Apache License, Version 2.0 (the 
+  * "License"); you may not use this file except in compliance 
+  * with the License. You may obtain a copy of the License at 
+  * 
+  * http://www.apache.org/licenses/LICENSE-2.0 
+  * 
+  * Unless required by applicable law or agreed to in writing, 
+  * software distributed under the License is distributed on an 
+  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+  * KIND, either express or implied. See the License for the 
+  * specific language governing permissions and limitations 
+  * under the License. 
+  */
 package org.apache.cxf.dosgi.dsw;
 
 import java.util.Arrays;

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/OsgiUtilsTest.java
Tue Aug 25 17:13:37 2009
@@ -1,3 +1,21 @@
+/** 
+  * Licensed to the Apache Software Foundation (ASF) under one 
+  * or more contributor license agreements. See the NOTICE file 
+  * distributed with this work for additional information 
+  * regarding copyright ownership. The ASF licenses this file 
+  * to you under the Apache License, Version 2.0 (the 
+  * "License"); you may not use this file except in compliance 
+  * with the License. You may obtain a copy of the License at 
+  * 
+  * http://www.apache.org/licenses/LICENSE-2.0 
+  * 
+  * Unless required by applicable law or agreed to in writing, 
+  * software distributed under the License is distributed on an 
+  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+  * KIND, either express or implied. See the License for the 
+  * specific language governing permissions and limitations 
+  * under the License. 
+  */
 package org.apache.cxf.dosgi.dsw;
 
 import java.net.URL;
@@ -19,7 +37,6 @@
 import org.jdom.Namespace;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.discovery.ServiceEndpointDescription;
 

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
Tue Aug 25 17:13:37 2009
@@ -1,3 +1,21 @@
+/** 
+  * 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.net.InetAddress;

Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java?rev=807720&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
(added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
Tue Aug 25 17:13:37 2009
@@ -0,0 +1,124 @@
+/** 
+  * 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.dosgi.dsw.service.ServiceEndpointDescriptionImpl;
+import org.apache.cxf.jaxrs.provider.AegisElementProvider;
+import org.easymock.EasyMock;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.discovery.ServiceEndpointDescription;
+
+public class JaxRSUtilsTest extends TestCase  {
+
+	public void testNoGlobalProviders() {
+		Map<String, Object> props = new HashMap<String, Object>();
+        props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("MyInterface",
props);
+        
+        assertEquals(0, JaxRSUtils.getProviders(null, null, sd).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");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("MyInterface",
props);
+        
+        List<Object> providers = JaxRSUtils.getProviders(null, null, sd);
+        assertEquals(1, providers.size());
+        assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
+	}
+	
+	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");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("MyInterface",
props);
+        
+        List<Object> providers = JaxRSUtils.getProviders(null, null, sd);
+        assertEquals(1, providers.size());
+        assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
+	}
+	
+	public void testCustomGlobalProvider() throws Exception {
+		ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
+		BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+		bc.getServiceReferences(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);
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("MyInterface");
+        
+        List<Object> providers = JaxRSUtils.getProviders(bc, null, sd);
+        assertEquals(1, providers.size());
+        assertSame(p, providers.get(0));
+	}
+	
+	public void testNoCustomGlobalProvider() throws Exception {
+		ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
+		BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+		bc.getServiceReferences(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");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("MyInterface",
props);
+        
+        List<Object> providers = JaxRSUtils.getProviders(bc, null, sd);
+        assertEquals(0, providers.size());
+	}
+	
+	public void testCustomGlobalProviderExpected() throws Exception {
+		ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
+		BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+		bc.getServiceReferences(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");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("MyInterface",
props);
+        
+        List<Object> providers = JaxRSUtils.getProviders(bc, null, sd);
+        assertEquals(1, providers.size());
+        assertSame(p, providers.get(0));
+	}
+	
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
Tue Aug 25 17:13:37 2009
@@ -1,3 +1,21 @@
+/** 
+  * Licensed to the Apache Software Foundation (ASF) under one 
+  * or more contributor license agreements. See the NOTICE file 
+  * distributed with this work for additional information 
+  * regarding copyright ownership. The ASF licenses this file 
+  * to you under the Apache License, Version 2.0 (the 
+  * "License"); you may not use this file except in compliance 
+  * with the License. You may obtain a copy of the License at 
+  * 
+  * http://www.apache.org/licenses/LICENSE-2.0 
+  * 
+  * Unless required by applicable law or agreed to in writing, 
+  * software distributed under the License is distributed on an 
+  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+  * KIND, either express or implied. See the License for the 
+  * specific language governing permissions and limitations 
+  * under the License. 
+  */
 package org.apache.cxf.dosgi.dsw.handlers;
 
 import java.lang.reflect.Method;

Modified: cxf/dosgi/trunk/samples/greeter_rest/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/rest/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/samples/greeter_rest/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/rest/Activator.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/samples/greeter_rest/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/rest/Activator.java
(original)
+++ cxf/dosgi/trunk/samples/greeter_rest/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/rest/Activator.java
Tue Aug 25 17:13:37 2009
@@ -23,6 +23,7 @@
 import org.apache.cxf.dosgi.samples.greeter.rest.GreeterException;
 import org.apache.cxf.dosgi.samples.greeter.rest.GreeterInfo;
 import org.apache.cxf.dosgi.samples.greeter.rest.GreeterService;
+import org.apache.cxf.dosgi.samples.greeter.rest.GreeterService2;
 import org.apache.cxf.dosgi.samples.greeter.rest.GreetingPhrase;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -31,6 +32,7 @@
 
 public class Activator implements BundleActivator {    
     private ServiceTracker tracker;
+    private ServiceTracker tracker2;
 
     public void start(final BundleContext bc) {
         tracker = new ServiceTracker(bc, GreeterService.class.getName(), null) {
@@ -38,16 +40,27 @@
             public Object addingService(ServiceReference reference) {
                 Object result = super.addingService(reference);
 
-                useService(bc, reference);
+                useGreeterService(bc, reference);
                 
                 return result;
             }
         };
         tracker.open();
         
+        tracker2 = new ServiceTracker(bc, GreeterService2.class.getName(), null) {
+            @Override
+            public Object addingService(ServiceReference reference) {
+                Object result = super.addingService(reference);
+
+                useGreeterService2(bc, reference);
+                
+                return result;
+            }
+        };
+        tracker2.open();
     }
 
-    protected void useService(final BundleContext bc, ServiceReference reference) {
+    protected void useGreeterService(final BundleContext bc, ServiceReference reference)
{
         Object svc = bc.getService(reference);
         if (!(svc instanceof GreeterService)) {
             return;
@@ -61,6 +74,21 @@
         });
         t.start();
     }
+    
+    protected void useGreeterService2(final BundleContext bc, ServiceReference reference)
{
+        Object svc = bc.getService(reference);
+        if (!(svc instanceof GreeterService2)) {
+            return;
+        }
+        final GreeterService2 greeter = (GreeterService2) svc;
+
+        Thread t = new Thread(new Runnable() {
+            public void run() {
+                greeter2UI(bc, greeter);
+            }
+        });
+        t.start();
+    }
 
     private void greeterUI(final BundleContext bc, final GreeterService greeter) {
         while (true) {
@@ -84,8 +112,32 @@
             }
         }
     }
+    
+    private void greeter2UI(final BundleContext bc, final GreeterService2 greeter) {
+        while (true) {
+            System.out.println("*** Opening greeter2 client dialog ***");
+            String name = JOptionPane.showInputDialog("Greeter2 : Enter name");
+            if (name == null) {
+                break;
+            } else {
+                System.out.println("*** Invoking greeter2 ***");
+                try {
+                    GreeterInfo info = greeter.greetMe(name);
+    
+                    System.out.println("greetMe(\"" + name + "\") returns:");
+                    for (GreetingPhrase greeting: info.getGreetings()) {
+                        System.out.println("  " + greeting.getPhrase() 
+                                + " " + greeting.getName());
+                    }
+                } catch (GreeterException ex) {
+                    System.out.println("GreeterException : " + ex.toString());
+                }
+            }
+        }
+    }
 
     public void stop(BundleContext bc) throws Exception {
         tracker.close();
+        tracker2.close();
     }
 }

Modified: cxf/dosgi/trunk/samples/greeter_rest/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/samples/greeter_rest/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/samples/greeter_rest/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml
(original)
+++ cxf/dosgi/trunk/samples/greeter_rest/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml
Tue Aug 25 17:13:37 2009
@@ -20,5 +20,14 @@
     <property name="service.exported.configs">org.apache.cxf.rs</property>
     <property name="service.exported.intents">HTTP</property>
     <property name="org.apache.cxf.rs.address">http://localhost:9090/greeter</property>
+    <property name="org.apache.cxf.rs.databinding">aegis</property> 
+  </service-description>
+  <service-description>
+    <provide interface="org.apache.cxf.dosgi.samples.greeter.rest.GreeterService2" />
+    <property name="service.exported.interfaces">*</property>
+    <property name="service.exported.configs">org.apache.cxf.rs</property>
+    <property name="service.exported.intents">HTTP</property>
+    <property name="org.apache.cxf.rs.address">http://localhost:9091/greeter2</property>
+    <property name="org.apache.cxf.rs.databinding">aegis</property> 
   </service-description>
 </service-descriptions>

Modified: cxf/dosgi/trunk/samples/greeter_rest/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/rest/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/samples/greeter_rest/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/rest/Activator.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/samples/greeter_rest/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/rest/Activator.java
(original)
+++ cxf/dosgi/trunk/samples/greeter_rest/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/rest/Activator.java
Tue Aug 25 17:13:37 2009
@@ -23,39 +23,40 @@
 import java.util.Hashtable;
 
 import org.apache.cxf.dosgi.samples.greeter.rest.GreeterService;
+import org.apache.cxf.dosgi.samples.greeter.rest.GreeterService2;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
-//TODO: remove the comments asap once the synchronization is complete
 public class Activator implements BundleActivator {
     private ServiceRegistration registration;
-    //private ServiceRegistration registration2;
+    private ServiceRegistration registration2;
 
     public void start(BundleContext bc) throws Exception {
         Dictionary props = getProperties("http://localhost:9090/greeter");
         registration = bc.registerService(GreeterService.class.getName(), 
                                           new GreeterServiceImpl(), props);
         
-//        props = getProperties("http://localhost:9089/greeter");
-//        registration2 = bc.registerService(GreeterService2.class.getName(), 
-//                                          new GreeterServiceImpl2(), props);
+        props = getProperties("http://localhost:9091/greeter2");
+        registration2 = bc.registerService(GreeterService2.class.getName(), 
+                                          new GreeterServiceImpl2(), props);
         
     }
 
-    private Dictionary getProperties(String address) { 
+    @SuppressWarnings("unchecked")
+	private Dictionary getProperties(String address) { 
     	Dictionary props = new Hashtable();
 
         props.put("service.exported.interfaces", "*");
         props.put("service.exported.configs", "org.apache.cxf.rs");
         props.put("service.exported.intents", "HTTP");
         props.put("org.apache.cxf.rs.address", address);
-        //props.put("org.apache.cxf.rs.httpservice.context", "/greeter");
+        props.put("org.apache.cxf.rs.databinding", "aegis");
         return props;
     }
     
     public void stop(BundleContext bc) throws Exception {
         registration.unregister();
-        //registration2.unregister();
+        registration2.unregister();
     }
 }

Modified: cxf/dosgi/trunk/samples/greeter_rest/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/rest/GreeterServiceImpl2.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/samples/greeter_rest/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/rest/GreeterServiceImpl2.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/samples/greeter_rest/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/rest/GreeterServiceImpl2.java
(original)
+++ cxf/dosgi/trunk/samples/greeter_rest/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/rest/GreeterServiceImpl2.java
Tue Aug 25 17:13:37 2009
@@ -27,6 +27,7 @@
 	private GreeterServiceImpl greeter = new GreeterServiceImpl();
 	
     public GreeterInfo greetMe(String name) throws GreeterException {
+    	System.out.println("Delegating from GreeterServiceImpl2 to GreeterServiceImpl");
         return greeter.greetMe(name);
     }
 

Modified: cxf/dosgi/trunk/systests/common_rest/src/main/java/org/apache/cxf/dosgi/systests/common/rest/AbstractJaxRsPublishHookTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests/common_rest/src/main/java/org/apache/cxf/dosgi/systests/common/rest/AbstractJaxRsPublishHookTest.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests/common_rest/src/main/java/org/apache/cxf/dosgi/systests/common/rest/AbstractJaxRsPublishHookTest.java
(original)
+++ cxf/dosgi/trunk/systests/common_rest/src/main/java/org/apache/cxf/dosgi/systests/common/rest/AbstractJaxRsPublishHookTest.java
Tue Aug 25 17:13:37 2009
@@ -60,7 +60,6 @@
         assertEquals(1, srefs.length);
         ManagedService ms = (ManagedService)bundleContext.getService(srefs[0]);
         ms.updated(props);
-        
         ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(JAXRSClientFactoryBean.class.getClassLoader());
         installBundle("org.apache.cxf.dosgi.samples", "cxf-dosgi-ri-samples-greeter-rest-impl",
null, "jar");
@@ -71,14 +70,16 @@
         
         //do the invocation using a CXF api 
         GreeterService greeter1 = null;
+        boolean serviceUsed = false;
         try {
         	JAXRSClientFactoryBean factory = new JAXRSClientFactoryBean();
             factory.setServiceClass(GreeterService.class);
             factory.setAddress(address);
             factory.setProvider(new AegisElementProvider());
             greeter1 = (GreeterService)factory.create();
-            useService(greeter1);
+            serviceUsed = useService(greeter1);
         } finally {
+        	assertTrue(serviceUsed);
             Thread.currentThread().setContextClassLoader(contextLoader);
         }
             
@@ -108,15 +109,16 @@
         fail();
     }
     
-    private void useService(GreeterService greeter) throws Exception {
+    private boolean useService(GreeterService greeter) throws Exception {
         assertNotNull(greeter);
         
         GreeterInfo info = greeter.greetMe("Fred");
-        
+        assertTrue(info.getGreetings().size() > 0);
         for (GreetingPhrase greeting: info.getGreetings()) {
         	assertEquals("Fred", greeting.getName());
             System.out.println("  " + greeting.getPhrase() 
                     + " " + greeting.getName());
         }
+        return true;
     }
 }

Modified: cxf/dosgi/trunk/systests/common_rest/src/main/java/org/apache/cxf/dosgi/systests/common/rest/AbstractListenerHookServiceListenerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests/common_rest/src/main/java/org/apache/cxf/dosgi/systests/common/rest/AbstractListenerHookServiceListenerTest.java?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests/common_rest/src/main/java/org/apache/cxf/dosgi/systests/common/rest/AbstractListenerHookServiceListenerTest.java
(original)
+++ cxf/dosgi/trunk/systests/common_rest/src/main/java/org/apache/cxf/dosgi/systests/common/rest/AbstractListenerHookServiceListenerTest.java
Tue Aug 25 17:13:37 2009
@@ -20,6 +20,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.Callable;
@@ -73,7 +74,8 @@
     public void testBasicInvocation() throws Exception {
 
         Thread.currentThread().setContextClassLoader(JAXRSClientFactoryBean.class.getClassLoader());
-
+        bundleContext.registerService(new String[]{"javax.ws.rs.ext.MessageBodyReader"},

+       		new AegisElementProvider(), new Hashtable()); 
         Server server1 = null;
         Server server2 = null;
         ServiceTracker tracker = null;
@@ -138,7 +140,8 @@
     public void testMultiServiceProxification() throws Exception {
 
         Thread.currentThread().setContextClassLoader(JAXRSClientFactoryBean.class.getClassLoader());
-
+        bundleContext.registerService(new String[]{"javax.ws.rs.ext.MessageBodyReader"},

+        		new AegisElementProvider(), new Hashtable()); 
         installDswIfNeeded();
 
         // sleep for a bit

Modified: cxf/dosgi/trunk/systests/single_bundle_distro_rest/src/test/resources/OSGI-INF/remote-service/remote-services.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests/single_bundle_distro_rest/src/test/resources/OSGI-INF/remote-service/remote-services.xml?rev=807720&r1=807719&r2=807720&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests/single_bundle_distro_rest/src/test/resources/OSGI-INF/remote-service/remote-services.xml
(original)
+++ cxf/dosgi/trunk/systests/single_bundle_distro_rest/src/test/resources/OSGI-INF/remote-service/remote-services.xml
Tue Aug 25 17:13:37 2009
@@ -20,6 +20,8 @@
     <property name="service.exported.intents">HTTP</property>
     <property name="service.exported.configs">org.apache.cxf.rs</property>
     <property name="org.apache.cxf.rs.address">http://localhost:9090/greeter</property>
+    <property name="org.apache.cxf.rs.databinding">aegis</property>
+    <property name="org.apache.cxf.rs.provider.globalquery">false</property>
   </service-description>
   <service-description>
     <provide interface="org.apache.cxf.dosgi.samples.greeter.rest.GreeterService" />



Mime
View raw message