cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1228198 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw: Constants.java handlers/AbstractPojoConfigurationTypeHandler.java handlers/WsdlConfigurationTypeHandler.java
Date Fri, 06 Jan 2012 14:27:09 GMT
Author: sergeyb
Date: Fri Jan  6 14:27:09 2012
New Revision: 1228198

URL: http://svn.apache.org/viewvc?rev=1228198&view=rev
Log:
[DOSGI-107] Prototyping the code for a wsdl configuration type

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/handlers/AbstractPojoConfigurationTypeHandler.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java

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=1228198&r1=1228197&r2=1228198&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 Fri
Jan  6 14:27:09 2012
@@ -39,7 +39,9 @@ public class Constants {
     public static final String WSDL_CONFIG_TYPE = "wsdl";
     public static final String WSDL_CONFIG_PREFIX = "osgi.remote.configuration" + "." + WSDL_CONFIG_TYPE;
     public static final String SERVICE_NAMESPACE = WSDL_CONFIG_PREFIX + ".service.ns";
-    
+    public static final String SERVICE_NAME = WSDL_CONFIG_PREFIX + ".service.name";
+    public static final String PORT_NAME = WSDL_CONFIG_PREFIX + ".port.name";
+    public static final String WSDL_LOCATION = WSDL_CONFIG_PREFIX + ".location";
     // Provider prefix
     public static final String PROVIDER_PREFIX = "org.apache.cxf";
     

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java?rev=1228198&r1=1228197&r2=1228198&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
Fri Jan  6 14:27:09 2012
@@ -226,5 +226,51 @@ public abstract class AbstractPojoConfig
         return intentMap;
     }    
 
-
+    protected String getPojoAddress(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;
+        }
+        
+        
+        if (address == null) {
+            String port = null;
+            Object p = sd.get(Constants.WS_PORT_PROPERTY);
+            if (p instanceof String) {
+                port = (String) p;
+            }
+            
+            address = getDefaultAddress(iClass, port);
+            if (address != null) {
+                LOG.info("Using a default address : " + address);
+            }
+        }
+        return address;
+    }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java?rev=1228198&r1=1228197&r2=1228198&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
Fri Jan  6 14:27:09 2012
@@ -28,14 +28,19 @@ import javax.xml.ws.Service;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.dosgi.dsw.Constants;
 import org.apache.cxf.dosgi.dsw.OsgiUtils;
 import org.apache.cxf.dosgi.dsw.service.ExportRegistrationImpl;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 
-public class WsdlConfigurationTypeHandler extends AbstractConfigurationHandler {
+public class WsdlConfigurationTypeHandler extends AbstractPojoConfigurationTypeHandler {
     private static final String CONFIGURATION_TYPE = "wsdl";
     private static final Logger LOG = LogUtils.getL7dLogger(WsdlConfigurationTypeHandler.class);
     
@@ -77,9 +82,16 @@ public class WsdlConfigurationTypeHandle
             serviceNs = PackageUtils.getNamespace(
                             PackageUtils.getPackageName(iClass));
         }
-        QName serviceQname = new QName(serviceNs, iClass.getSimpleName());
+        String serviceName = OsgiUtils.getProperty(sd, Constants.SERVICE_NAME);
+        if (serviceName == null) {
+        	serviceName = iClass.getSimpleName();	
+        }
+        QName serviceQname = getServiceQName(iClass, sd.getProperties());
+        QName portQname = getPortQName(serviceQname.getNamespaceURI(), sd.getProperties());
         Service service = createWebService(wsdlAddress, serviceQname);
-        Object proxy = getProxy(service.getPort(iClass), iClass);
+        Object proxy = getProxy(
+            portQname == null ? service.getPort(iClass) : service.getPort(portQname, iClass),

+        	iClass);
         //MARC: FIXME !!!! getDistributionProvider().addRemoteService(serviceReference);
         return proxy;
         
@@ -90,6 +102,27 @@ public class WsdlConfigurationTypeHandle
         return Service.create(wsdlAddress, serviceQname);
     }
 
+    private QName getServiceQName(Class<?> iClass, Map sd) {
+    	String serviceNs = OsgiUtils.getProperty(sd, Constants.SERVICE_NAMESPACE);
+        if (serviceNs == null) {
+            serviceNs = PackageUtils.getNamespace(
+                            PackageUtils.getPackageName(iClass));
+        }
+        String serviceName = OsgiUtils.getProperty(sd, Constants.SERVICE_NAME);
+        if (serviceName == null) {
+        	serviceName = iClass.getSimpleName();	
+        }
+        return new QName(serviceNs, serviceName);
+    }
+    
+    private QName getPortQName(String ns, Map sd) {
+    	String portName = OsgiUtils.getProperty(sd, Constants.PORT_NAME);
+        if (portName == null) {
+        	return null;	
+        }
+        return new QName(ns, portName);
+    }
+    
     public void createServer(ExportRegistrationImpl exportRegistration,
                                BundleContext dswContext,
                                BundleContext callingContext,
@@ -97,8 +130,67 @@ public class WsdlConfigurationTypeHandle
                                Class<?> iClass, 
                                Object serviceBean) {
         
-        throw new UnsupportedOperationException("No WSDL configuration is currently supported
for"
-                  + " creating service endpoints");
+    	String location = OsgiUtils.getProperty(sd, Constants.WSDL_LOCATION);
+    	if (location == null) {
+    		LOG.warning("WSDL location is unavailable");
+            exportRegistration.setException(new Throwable("WSDL location is unavailable"));
+            return;
+    	}
+        URL wsdlURL = dswContext.getBundle().getResource(location);
+        if (wsdlURL == null) {
+    		LOG.warning("WSDL resource is unavailable");
+            exportRegistration.setException(new Throwable("WSDL resource is unavailable"));
+            return;
+    	}
+        
+    	String address = getPojoAddress(sd, iClass);
+        if (address == null) {
+            LOG.warning("Remote address is unavailable");
+            exportRegistration.setException(new Throwable("Remote address is unavailable"));
+            return;
+        }
+
+        LOG.info("Creating a " + iClass.getName() + " endpoint from CXF PublishHook, address
is " + address);
+
+        DataBinding databinding = new JAXBDataBinding();
+        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
+
+        factory.setServiceClass(iClass);
+        factory.setAddress(address);
+        factory.getServiceFactory().setDataBinding(databinding);
+        factory.setServiceBean(serviceBean);
+
+        QName serviceQname = getServiceQName(iClass, sd);
+        factory.setServiceName(serviceQname);
+        
+        QName portQname = getPortQName(serviceQname.getNamespaceURI(), sd);
+        if (portQname != null) {
+        	factory.setEndpointName(portQname);
+        }
+        
+        factory.setWsdlURL(wsdlURL.toString());
+        
+        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            String[] intents = applyIntents(dswContext, callingContext, factory.getFeatures(),
factory, sd);
+
+            // The properties for the EndpointDescription
+            Map<String, Object> endpointProps = createEndpointProps(sd, iClass, new
String[]{Constants.WS_CONFIG_TYPE}, address,intents);
+            
+            Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
+            Server server = factory.create();
+
+            exportRegistration.setServer(server);
+            
+            //  add the information on the new Endpoint to the export registration
+            EndpointDescription ed = new EndpointDescription(endpointProps);
+            exportRegistration.setEndpointdescription(ed);
+            
+        } catch (IntentUnsatifiedException iue) {
+            exportRegistration.setException(iue);
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldClassLoader);
+        }
     }
     
     private String getWsdlAddress(EndpointDescription sd, Class<?> iClass) {



Mime
View raw message