cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r809540 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtils.java test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
Date Mon, 31 Aug 2009 11:25:02 GMT
Author: sergeyb
Date: Mon Aug 31 11:25:02 2009
New Revision: 809540

URL: http://svn.apache.org/viewvc?rev=809540&view=rev
Log:
Support for setting jaxrs providers using declarative properties

Modified:
    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/handlers/JaxRSUtilsTest.java

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=809540&r1=809539&r2=809540&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
Mon Aug 31 11:25:02 2009
@@ -62,7 +62,20 @@
         Object serviceProviders = 
         	sd.getProperty(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_PROP_KEY);
         if (serviceProviders != null) {
-        	providers.addAll(Arrays.asList((Object[])serviceProviders));
+        	if (serviceProviders.getClass().isArray()) {
+        	    providers.addAll(Arrays.asList((Object[])serviceProviders));
+        	} else {
+        		String[] classNames = serviceProviders.toString().split(",");
+        		for (String className : classNames) {
+        			try {
+        			    Class<?> pClass = callingContext.getBundle().loadClass(className.trim());
+        			    providers.add(pClass.newInstance());
+        			} catch (Exception ex) {
+        				ex.printStackTrace();
+        				LOG.warning("JAXRS Provider " + className.trim() + " can not be loaded or created");
+        			}
+        		}
+        	}
         }
 		
 		Object globalQueryProp = 

Modified: 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=809540&r1=809539&r2=809540&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
Mon Aug 31 11:25:02 2009
@@ -27,7 +27,9 @@
 import org.apache.cxf.dosgi.dsw.Constants;
 import org.apache.cxf.dosgi.dsw.service.ServiceEndpointDescriptionImpl;
 import org.apache.cxf.jaxrs.provider.AegisElementProvider;
+import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.easymock.EasyMock;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.discovery.ServiceEndpointDescription;
@@ -64,6 +66,32 @@
         assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
 	}
 	
+	public void testServiceProviderProperty() throws Exception {
+		
+		BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+		Bundle bundle = EasyMock.createNiceMock(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 org.apache.cxf.jaxrs.provider.AegisElementProvider , \r\n" 
+        		+ "org.apache.cxf.jaxrs.provider.JAXBElementProvider\r\n");
+        
+        props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
+        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("MyInterface",
props);
+        
+        List<Object> providers = JaxRSUtils.getProviders(bc, null, sd);
+        assertEquals(2, providers.size());
+        assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
+        assertEquals(JAXBElementProvider.class.getName(), providers.get(1).getClass().getName());
+	}
+	
 	public void testCustomGlobalProvider() throws Exception {
 		ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
 		BundleContext bc = EasyMock.createNiceMock(BundleContext.class);



Mime
View raw message