cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r958546 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
Date Mon, 28 Jun 2010 11:20:25 GMT
Author: davidb
Date: Mon Jun 28 11:20:24 2010
New Revision: 958546

URL: http://svn.apache.org/viewvc?rev=958546&view=rev
Log:
Fix for DOSGI-72. Applied on behalf of Julien Vey.

Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java?rev=958546&r1=958545&r2=958546&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandler.java
Mon Jun 28 11:20:24 2010
@@ -25,6 +25,7 @@ import java.util.Hashtable;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
@@ -36,6 +37,7 @@ import org.apache.cxf.dosgi.dsw.service.
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.endpoint.ServerLifeCycleListener;
 import org.apache.cxf.endpoint.ServerLifeCycleManager;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.frontend.ServerFactoryBean;
 import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
@@ -45,6 +47,7 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.service.http.HttpContext;
 import org.osgi.service.http.HttpService;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
 import org.osgi.util.tracker.ServiceTracker;
 
 public class HttpServiceConfigurationTypeHandler extends AbstractPojoConfigurationTypeHandler
{
@@ -75,7 +78,41 @@ public class HttpServiceConfigurationTyp
 
     public Object createProxy(ServiceReference serviceReference, BundleContext dswContext,
                               BundleContext callingContext, Class<?> iClass, EndpointDescription
sd) {
-        // This handler doesn't make sense on the client side
+        String address = getHttpServiceAddress(sd.getProperties(), iClass);
+        if (address == null) {
+            LOG.warning("Remote address is unavailable");
+            // TODO: fire Event
+            return null;
+        }
+
+        LOG.info("Creating a " + iClass.getName() + " client, endpoint address is " + address);
+
+        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            DataBinding databinding;
+            String dataBindingImpl = (String)serviceReference.getProperty(Constants.WS_DATABINDING_PROP_KEY);
+            if ("jaxb".equals(dataBindingImpl)) {
+                databinding = new JAXBDataBinding();
+            } else {
+                databinding = new AegisDatabinding();
+            }
+            String frontEndImpl = (String)serviceReference.getProperty(Constants.WS_FRONTEND_PROP_KEY);
+            ClientProxyFactoryBean factory = createClientProxyFactoryBean(frontEndImpl);
+            factory.setServiceClass(iClass);
+            factory.setAddress(address);
+            factory.getServiceFactory().setDataBinding(databinding);
+
+            applyIntents(dswContext, callingContext, factory.getFeatures(), factory.getClientFactoryBean(),
+                         sd.getProperties());
+
+            Thread.currentThread().setContextClassLoader(ClientProxyFactoryBean.class.getClassLoader());
+            Object proxy = getProxy(factory.create(), iClass);
+            return proxy;
+        } catch (Exception e) {
+            LOG.log(Level.WARNING, "proxy creation failed", e);
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldClassLoader);
+        }
         return null;
     }
 
@@ -228,4 +265,39 @@ public class HttpServiceConfigurationTyp
         HttpContext httpContext = httpService.createDefaultHttpContext();
         return new SecurityDelegatingHttpContext(bundleContext, httpContext);
     }
+    
+    protected String getHttpServiceAddress(Map sd, Class<?> iClass) {
+        String address = OsgiUtils.getProperty(sd, RemoteConstants.ENDPOINT_ID);
+        if(address == null && sd.get(RemoteConstants.ENDPOINT_ID)!=null ){
+            LOG.severe("Could not use address property " + RemoteConstants.ENDPOINT_ID );
+            return null;
+        }
+        
+        
+        if (address == null) {
+            address = OsgiUtils.getProperty(sd, Constants.WS_ADDRESS_PROPERTY);
+        }
+        if(address == null && sd.get(Constants.WS_ADDRESS_PROPERTY)!=null ){
+            LOG.severe("Could not use address property " + Constants.WS_ADDRESS_PROPERTY
);
+            return null;
+        }
+        
+        if (address == null) {
+            address = OsgiUtils.getProperty(sd, Constants.WS_ADDRESS_PROPERTY_OLD);
+        }
+        if(address == null && sd.get(Constants.WS_ADDRESS_PROPERTY_OLD)!=null ){
+            LOG.severe("Could not use address property " + Constants.WS_ADDRESS_PROPERTY_OLD);
+            return null;
+        }
+        
+        if (address == null) {
+            address = OsgiUtils.getProperty(sd, Constants.RS_ADDRESS_PROPERTY);
+        }
+        if(address == null && sd.get(Constants.RS_ADDRESS_PROPERTY)!=null ){
+            LOG.severe("Could not use address property " + Constants.RS_ADDRESS_PROPERTY);
+            return null;
+        }
+
+        return address;
+    }
 }

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=958546&r1=958545&r2=958546&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
Mon Jun 28 11:20:24 2010
@@ -32,23 +32,22 @@ import org.apache.cxf.endpoint.AbstractE
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
 import org.apache.cxf.transport.Destination;
 import org.apache.cxf.ws.addressing.AttributedURIType;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.easymock.IAnswer;
 import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.HttpService;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
 public class HttpServiceConfigurationTypeHandlerTest extends TestCase {
     
-    public void testDUMMY(){
-        assertTrue(true);
-    }
-    
     public void testServer() throws Exception {
         BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
         EasyMock.expect(dswContext.getProperty("org.osgi.service.http.port")).
@@ -322,6 +321,64 @@ public class HttpServiceConfigurationTyp
         EasyMock.replay(server);
         return server;
     }
+    
+    public void testCreateProxy() {
+        IMocksControl c = EasyMock.createNiceControl();
+        BundleContext bc1 = c.createMock(BundleContext.class);
+        BundleContext bc2 = c.createMock(BundleContext.class);
+
+        HttpService httpService = c.createMock(HttpService.class);
+
+        ServiceReference httpSvcSR = c.createMock(ServiceReference.class);
+        EasyMock.expect(bc1.getService(httpSvcSR)).andReturn(httpService).anyTimes();
+
+        final ClientProxyFactoryBean cpfb = c.createMock(ClientProxyFactoryBean.class);
+        ReflectionServiceFactoryBean sf = c.createMock(ReflectionServiceFactoryBean.class);
+        EasyMock.expect(cpfb.getServiceFactory()).andReturn(sf).anyTimes();
+
+        ServiceReference sr = c.createMock(ServiceReference.class);
+
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(RemoteConstants.ENDPOINT_ID, "http://google.de/");
+        props.put(org.osgi.framework.Constants.OBJECTCLASS, new String[] { "my.class" });
+        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(CharSequence.class));
+        EasyMock.expectLastCall().atLeastOnce();
+
+        c.replay();
+
+        Map<String, Object> handlerProps = new HashMap<String, Object>();
+        HttpServiceConfigurationTypeHandler h = new HttpServiceConfigurationTypeHandler(bc1,
handlerProps) {
+            @Override
+            ClientProxyFactoryBean createClientProxyFactoryBean(String frontend) {
+                return cpfb;
+            }
+
+            @Override
+            String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
+                    List<AbstractFeature> features, AbstractEndpointFactory factory,
Map sd) {
+                return new String[] { "a.b.c" };
+            }
+        };
+
+        h.httpServiceReferences.add(httpSvcSR);
+
+        Object proxy = h.createProxy(sr, bc1, bc2, CharSequence.class, endpoint);
+        assertNotNull(proxy);
+
+        if (proxy instanceof CharSequence) {
+            CharSequence cs = (CharSequence) proxy;
+        } else {
+            assertTrue("Proxy is not of the requested type! ", false);
+        }
+
+        c.verify();
+    }
 
     // TODO these tests still need to be written...
     /*



Mime
View raw message