cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r809664 - 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 17:10:41 GMT
Author: sergeyb
Date: Mon Aug 31 17:10:41 2009
New Revision: 809664

URL: http://svn.apache.org/viewvc?rev=809664&view=rev
Log:
Support for registering providers from DS

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=809664&r1=809663&r2=809664&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 17:10:41 2009
@@ -63,18 +63,14 @@
         	sd.getProperty(org.apache.cxf.dosgi.dsw.Constants.RS_PROVIDER_PROP_KEY);
         if (serviceProviders != null) {
         	if (serviceProviders.getClass().isArray()) {
-        	    providers.addAll(Arrays.asList((Object[])serviceProviders));
+        		if (serviceProviders.getClass().getComponentType() == String.class) {
+        			loadProviders(callingContext, providers, (String[])serviceProviders);	
+        		} else {
+        	        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");
-        			}
-        		}
+        		loadProviders(callingContext, providers, classNames);
         	}
         }
 		
@@ -106,6 +102,23 @@
 		return providers;
     }
 	
+	private static void loadProviders(BundleContext callingContext, 
+			                          List<Object> providers,
+			                          String[] classNames) {
+		for (String className : classNames) {
+			try {
+				String realName = className.trim();
+				if (realName.length() > 0) {
+				    Class<?> pClass = callingContext.getBundle().loadClass(realName);
+				    providers.add(pClass.newInstance());
+				}
+			} catch (Exception ex) {
+				ex.printStackTrace();
+				LOG.warning("JAXRS Provider " + className.trim() + " can not be loaded or created");
+			}
+		}
+	}
+	
 	public static List<UserResource> getModel(BundleContext callingContext, Class<?>
iClass) {
 		String classModel = MODEL_FOLDER + iClass.getSimpleName() + "-model.xml";
 		List<UserResource> list = getModel(callingContext, iClass, classModel);

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=809664&r1=809663&r2=809664&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 17:10:41 2009
@@ -66,6 +66,7 @@
         assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
 	}
 	
+	
 	public void testServiceProviderProperty() throws Exception {
 		
 		BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
@@ -92,6 +93,34 @@
         assertEquals(JAXBElementProvider.class.getName(), providers.get(1).getClass().getName());
 	}
 	
+    public void testServiceProviderStrings() 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,
+        		  new String[] {
+        		    "\r\n org.apache.cxf.jaxrs.provider.AegisElementProvider", 
+        		    "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