[DOSGI-229] Allow to use more than one interface for import
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/api/DistributionProvider.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/api/DistributionProvider.java
index fad6b03..9a8c0ca 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/api/DistributionProvider.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/api/DistributionProvider.java
@@ -32,7 +32,7 @@
      * @param sref reference of the service to be exported
      * @param effectiveProperties combined properties of the service and additional properties from rsa
      * @param exportedInterface name of the interface to be exported
-     * @return
+     * @return closeable Endpoint that represents the service that is exposed to the outside world
      */
     Endpoint exportService(ServiceReference<?> sref, 
                            Map<String, Object> effectiveProperties,
@@ -40,13 +40,13 @@
 
     /**
      * @param sref reference of the service offered to the requesting bundle
-     * @param iClass interface of the service to proxy
+     * @param interfaces interfaces of the service to proxy
      * @param endpoint description of the remote endpoint
      * @return service proxy to be given to the requesting bundle
      * @throws IntentUnsatisfiedException
      */
     Object importEndpoint(BundleContext consumerContext, 
-                          Class<?> iClass, 
+                          Class<?>[] interfaces, 
                           EndpointDescription endpoint)
         throws IntentUnsatisfiedException;
     
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java
index dad4a89..0be2fbf 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/CXFDistributionProvider.java
@@ -79,7 +79,7 @@
     }
 
     @Override
-    public Object importEndpoint(BundleContext consumerContext, Class<?> iClass, EndpointDescription endpoint)
+    public Object importEndpoint(BundleContext consumerContext, Class<?>[] iClass, EndpointDescription endpoint)
         throws IntentUnsatisfiedException {
         List<String> configurationTypes = determineConfigTypesForImport(endpoint);
         DistributionProvider handler = getHandler(configurationTypes, endpoint.getProperties());
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
index 3c95200..e67bc31 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSPojoConfigurationTypeHandler.java
@@ -56,8 +56,9 @@
     }
 
     public Object importEndpoint(BundleContext consumerContext,
-                              Class<?> iClass,
+                              Class<?>[] interfaces,
                               EndpointDescription endpoint) {
+        Class<?> iClass = interfaces[0];
         String address = getPojoAddress(endpoint, iClass);
         if (address == null) {
             LOG.warn("Remote address is unavailable");
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
index fefa0ee..0451a8e 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
@@ -55,8 +55,9 @@
     }
 
     public Object importEndpoint(BundleContext consumerContext,
-                              Class<?> iClass,
+                              Class<?>[] interfaces,
                               EndpointDescription endpoint) throws IntentUnsatisfiedException {
+        Class<?> iClass = interfaces[0];
         Map<String, Object> sd = endpoint.getProperties();
         String address = getClientAddress(sd);
         if (address == null) {
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
index ec0f638..9384958 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
@@ -55,8 +55,9 @@
     }
 
     public Object importEndpoint(BundleContext consumerContext,
-                              Class<?> iClass,
+                              Class<?>[] interfaces,
                               EndpointDescription endpoint) {
+        Class<?> iClass = interfaces[0];
         String wsdlAddressProp = getWsdlAddress(endpoint, iClass);
         if (wsdlAddressProp == null) {
             LOG.warn("WSDL address is unavailable");
diff --git a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
index 343c406..b482b64 100644
--- a/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
+++ b/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
@@ -20,6 +20,7 @@
 
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -52,14 +53,17 @@
     }
 
     public Object getService(final Bundle requestingBundle, final ServiceRegistration sreg) {
-        List<String> interfaces = endpoint.getInterfaces();
-        String interfaceName = interfaces == null || interfaces.isEmpty() ? null : interfaces.get(0);
-        LOG.debug("getService() from serviceFactory for {}", interfaceName);
+        List<String> interfaceNames = endpoint.getInterfaces();
         try {
-            final Class<?> iClass = requestingBundle.loadClass(interfaceName);
+            LOG.debug("getService() from serviceFactory for {}", interfaceNames);
+            final List<Class<?>> interfaces = new ArrayList<Class<?>>();
+            for (String ifaceName : interfaceNames) {
+                interfaces.add(requestingBundle.loadClass(ifaceName));
+            }
             Object proxy = AccessController.doPrivileged(new PrivilegedAction<Object>() {
                 public Object run() {
-                    return handler.importEndpoint(requestingBundle.getBundleContext(), iClass, endpoint);
+                    Class<?>[] ifAr = interfaces.toArray(new Class[]{});
+                    return handler.importEndpoint(requestingBundle.getBundleContext(), ifAr, endpoint);
                 }
             });
 
@@ -69,9 +73,9 @@
             return proxy;
         } catch (IntentUnsatisfiedException iue) {
             LOG.info("Did not create proxy for {} because intent {} could not be satisfied",
-                    interfaceName, iue.getIntent());
+                    interfaceNames, iue.getIntent());
         } catch (Exception e) {
-            LOG.warn("Problem creating a remote proxy for {}", interfaceName, e);
+            LOG.warn("Problem creating a remote proxy for {}", interfaceNames, e);
         }
         return null;
     }
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
index afc45d1..8de459d 100644
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
+++ b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactoryTest.java
@@ -18,12 +18,15 @@
  */
 package org.apache.cxf.dosgi.dsw.handlers;
 
+
 import java.util.HashMap;
 import java.util.Map;
 
 import junit.framework.TestCase;
 
 import org.apache.cxf.dosgi.dsw.api.DistributionProvider;
+import org.apache.cxf.dosgi.dsw.api.Endpoint;
+import org.apache.cxf.dosgi.dsw.api.IntentUnsatisfiedException;
 import org.apache.cxf.dosgi.dsw.service.ClientServiceFactory;
 import org.apache.cxf.dosgi.dsw.service.ImportRegistrationImpl;
 import org.easymock.EasyMock;
@@ -31,6 +34,7 @@
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
@@ -41,17 +45,10 @@
      "rawtypes", "unchecked"
     })
     public void testGetService() throws ClassNotFoundException {
-        Object myTestProxyObject = new Object();
+        final Object myTestProxyObject = new Object();
 
         IMocksControl control = EasyMock.createControl();
-        Map<String, Object> map = new HashMap<String, Object>();
-        map.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
-        map.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "myGreatConfiguration");
-        map.put(Constants.OBJECTCLASS, new String[]{String.class.getName()});
-
-        EndpointDescription endpoint = new EndpointDescription(map);
-        
-
+        EndpointDescription endpoint = createTestEndpointDesc();
         ImportRegistrationImpl iri = new ImportRegistrationImpl(endpoint, null);
 
         BundleContext requestingContext = control.createMock(BundleContext.class);
@@ -60,12 +57,47 @@
         EasyMock.expect(requestingBundle.getBundleContext()).andReturn(requestingContext);
         ServiceRegistration sreg = control.createMock(ServiceRegistration.class);
 
-        DistributionProvider handler = control.createMock(DistributionProvider.class);
-        handler.importEndpoint(requestingContext, String.class, endpoint);
-        EasyMock.expectLastCall().andReturn(myTestProxyObject);
+        DistributionProvider handler = mockDistributionProvider(myTestProxyObject);
         control.replay();
 
         ClientServiceFactory csf = new ClientServiceFactory(endpoint, handler, iri);
         assertSame(myTestProxyObject, csf.getService(requestingBundle, sreg));
     }
+
+    /**
+     * Creating dummy class as I was not able to really mock it
+     * @param myTestProxyObject
+     * @return
+     */
+    private DistributionProvider mockDistributionProvider(final Object myTestProxyObject) {
+        return new DistributionProvider() {
+            
+            @Override
+            public Object importEndpoint(BundleContext consumerContext, Class<?>[] interfaces,
+                                         EndpointDescription endpoint)
+                throws IntentUnsatisfiedException {
+                return myTestProxyObject;
+            }
+            
+            @Override
+            public String[] getSupportedTypes() {
+                return null;
+            }
+            
+            @Override
+            public Endpoint exportService(ServiceReference<?> sref, Map<String, Object> effectiveProperties,
+                                          String exportedInterface) {
+                return null;
+            }
+        };
+    }
+
+    private EndpointDescription createTestEndpointDesc() {
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
+        map.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "myGreatConfiguration");
+        map.put(Constants.OBJECTCLASS, new String[]{String.class.getName()});
+        EndpointDescription endpoint = new EndpointDescription(map);
+        return endpoint;
+    }
 }
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
index 8e9d64d..4058de4 100644
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
+++ b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
@@ -148,7 +148,7 @@
         EasyMock.expectLastCall().atLeastOnce();
 
         c.replay();
-        Object proxy = p.importEndpoint(requestingContext, CharSequence.class, endpoint);
+        Object proxy = p.importEndpoint(requestingContext, new Class<?>[]{CharSequence.class}, endpoint);
         assertNotNull(proxy);
         assertTrue("Proxy is not of the requested type! ", proxy instanceof CharSequence);
         c.verify();