[jbossws-commits] JBossWS SVN: r11911 - in stack/cxf/trunk/modules: server/src/main/java/org/jboss/wsf/stack/cxf and 2 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Mar 31 12:14:58 EDT 2010


Author: alessio.soldano at jboss.com
Date: 2010-03-31 12:14:58 -0400 (Wed, 31 Mar 2010)
New Revision: 11911

Added:
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/JBossWSServiceFactoryBean.java
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/WSDLFilePublisher.java
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/JBossWSServerCXFConfigurer.java
Removed:
   stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/BusHolder.java
Modified:
   stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/JBossWSCXFConfigurer.java
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/BusDeploymentAspect.java
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/DescriptorDeploymentAspect.java
   stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDEndpoint.java
Log:
[JBWS-2971]
- configuring the jaxws:endpoint in the generated jbossws-cxf.xml file with a custom ServiceFactoryBean
- refactoring JBossWSCXFConfigurer and moving the configuration required on server side only to a separate configurer
- refactoring BusHolder 
- added WSDLFilePublisher extending the abstract one in jbossws-common


Deleted: stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/BusHolder.java
===================================================================
--- stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/BusHolder.java	2010-03-31 15:55:22 UTC (rev 11910)
+++ stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/BusHolder.java	2010-03-31 16:14:58 UTC (rev 11911)
@@ -1,229 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.wsf.stack.cxf.client.configuration;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.binding.soap.SoapTransportFactory;
-import org.apache.cxf.bus.spring.BusApplicationContext;
-import org.apache.cxf.bus.spring.SpringBusFactory;
-import org.apache.cxf.configuration.Configurer;
-import org.apache.cxf.resource.ResourceManager;
-import org.apache.cxf.resource.ResourceResolver;
-import org.apache.cxf.transport.DestinationFactory;
-import org.apache.cxf.transport.DestinationFactoryManager;
-import org.apache.cxf.transport.servlet.ServletTransportFactory;
-import org.jboss.logging.Logger;
-import org.jboss.ws.Constants;
-import org.jboss.wsf.spi.binding.BindingCustomization;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.core.io.InputStreamResource;
-
-/**
- * An wrapper of the Bus for performing most of the configurations required on it by JBossWS
- * 
- * @author alessio.soldano at jboss.com
- * @since 25-Mar-2010
- *
- */
-public class BusHolder
-{
-   private static final Logger log = Logger.getLogger(BusHolder.class);
-   public static final String PARAM_CXF_BEANS_URL = "jbossws.cxf.beans.url";
-   private boolean configured = false;
-   protected BusApplicationContext ctx ;
-   protected List<GenericApplicationContext> additionalCtx = new LinkedList<GenericApplicationContext>();
-   protected Bus bus;
-   
-   /**
-    * Private constructor
-    */
-   private BusHolder()
-   {
-      //NOP
-   }
-   
-   /**
-    * Creates a new BusHolder instance; a new Bus is created using the
-    * provided location for loading additional configurations
-    * 
-    * @param location
-    * @return
-    */
-   public static BusHolder create(URL location)
-   {
-      BusHolder holder = new BusHolder();
-      holder.createBus(location);
-      return holder;
-   }
-   
-   /**
-    * Creates a new BusHolder instance using the provided Bus
-    * 
-    * @param bus
-    * @return
-    */
-   public static BusHolder create(Bus bus)
-   {
-      BusHolder holder = new BusHolder();
-      holder.setBus(bus);
-      holder.setContext(bus.getExtension(BusApplicationContext.class));
-      return holder;
-   }
-   
-   /**
-    * Update the Bus held by the this instance using the provided parameters.
-    * This basically prepares the bus for being used with JBossWS.
-    * 
-    * @param jbossCxfXml    The location of the jboss-cxf.xml configuration file
-    * @param soapTransportFactory   The SoapTransportFactory to configure, if any
-    * @param resolver               The ResourceResolver to configure, if any
-    * @param customization          The BindingCustomization to configure, if any
-    * @throws IOException           Throws IOException if the jboss-cxf.xml file can't be read
-    */
-   public void configure(URL jbossCxfXml, SoapTransportFactory soapTransportFactory, ResourceResolver resolver, BindingCustomization customization) throws IOException
-   {
-      if (configured)
-      {
-         throw new IllegalStateException("Underlying bus is already configured for JBossWS use!");
-      }
-      setSoapTransportFactory(bus, soapTransportFactory);
-      setResourceResolver(bus, resolver);
-      setBindingCustomization(bus, customization);
-      if (jbossCxfXml != null)
-      {
-         additionalCtx.add(loadAdditionalConfig(ctx, jbossCxfXml));
-      }
-      configured = true;
-   }
-   
-   /**
-    * Performs close operations (currently implies destroying additional contexts)
-    * 
-    */
-   public void close()
-   {
-      for (GenericApplicationContext gac : additionalCtx)
-      {
-         gac.destroy();
-      }
-   }
-   
-   /**
-    * Creates the Bus using a SpringBusFactory with no specific Spring application context.
-    * Then loads additional configurations from the provided location
-    * 
-    * @param location
-    * @return
-    */
-   protected void createBus(URL location)
-   {
-      bus = new SpringBusFactory().createBus();
-      ctx = bus.getExtension(BusApplicationContext.class);
-      //Load additional configurations from cxf-servlet.xml
-      if (location != null)
-      {
-         try
-         {
-            additionalCtx.add(loadAdditionalConfig(ctx, location));
-         }
-         catch (IOException e)
-         {
-            if (log.isTraceEnabled())
-               log.trace("Could not load additional config from location: " + location, e);
-         }
-      }
-      //Force servlet transport to prevent CXF from using Jetty as a transport
-      DestinationFactory factory = new ServletTransportFactory(bus);
-      for (String s : factory.getTransportIds()) {
-          registerTransport(factory, s);
-      }
-   }
-   
-   protected static void setResourceResolver(Bus bus, ResourceResolver resourceResolver)
-   {
-      if (resourceResolver != null)
-      {
-         bus.getExtension(ResourceManager.class).addResourceResolver(resourceResolver);
-      }
-   }
-   
-   protected static void setSoapTransportFactory(Bus bus, SoapTransportFactory factory)
-   {
-      if (factory != null)
-      {
-         DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
-         factory.setBus(bus);
-         dfm.registerDestinationFactory(Constants.NS_SOAP11, factory);
-         dfm.registerDestinationFactory(Constants.NS_SOAP12, factory);
-      }
-   }
-   
-   protected static void setBindingCustomization(Bus bus, BindingCustomization customization)
-   {
-      if (customization != null) {
-         Configurer prev = bus.getExtension(Configurer.class);
-         JBossWSCXFConfigurer jbosswsConfigurer = (prev instanceof JBossWSCXFConfigurer) ? (JBossWSCXFConfigurer)prev : new JBossWSCXFConfigurer(prev);
-         jbosswsConfigurer.setBindingCustomization(customization);
-         bus.setExtension(jbosswsConfigurer, Configurer.class);
-      }
-   }
-   
-   protected static GenericApplicationContext loadAdditionalConfig(ApplicationContext ctx, URL locationUrl) throws IOException
-   {
-      if (locationUrl == null) throw new IllegalArgumentException("Cannot load additional config from null location!");
-      InputStream is = locationUrl.openStream();
-      GenericApplicationContext childCtx = new GenericApplicationContext(ctx);
-      XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(childCtx);
-      reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
-      reader.loadBeanDefinitions(new InputStreamResource(is));
-      childCtx.refresh();
-      return childCtx;
-   }
-
-   private void registerTransport(DestinationFactory factory, String namespace)
-   {
-      bus.getExtension(DestinationFactoryManager.class).registerDestinationFactory(namespace, factory);
-   }
-
-   public Bus getBus()
-   {
-      return bus;
-   }
-   
-   private void setBus(Bus bus)
-   {
-      this.bus = bus;
-   }
-   
-   private void setContext(BusApplicationContext ctx)
-   {
-      this.ctx = ctx;
-   }
-}

Modified: stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/JBossWSCXFConfigurer.java
===================================================================
--- stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/JBossWSCXFConfigurer.java	2010-03-31 15:55:22 UTC (rev 11910)
+++ stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/JBossWSCXFConfigurer.java	2010-03-31 16:14:58 UTC (rev 11911)
@@ -38,7 +38,7 @@
  */
 public class JBossWSCXFConfigurer implements Configurer
 {
-   private BindingCustomization customization;
+   protected BindingCustomization customization;
    private Configurer delegate;
 
    public JBossWSCXFConfigurer(Configurer delegate)
@@ -46,30 +46,34 @@
       this.delegate = delegate;
    }
    
-   public void setBindingCustomization(BindingCustomization customization)
+   public JBossWSCXFConfigurer(Configurer delegate, BindingCustomization customization)
    {
+      this(delegate);
       this.customization = customization;
    }
    
+   @Override
    public void configureBean(Object beanInstance)
    {
-      if (beanInstance instanceof AbstractWSDLBasedEndpointFactory)
-      {
-         configureEndpointFactory((AbstractWSDLBasedEndpointFactory)beanInstance);
-      }
-      else if (beanInstance instanceof ClientProxyFactoryBean)
-      {
-         configureClientProxyFactoryBean((ClientProxyFactoryBean)beanInstance);
-      }
-      //add other beans configuration here below
+      internalConfigure(beanInstance);
       if (delegate != null)
       {
          delegate.configureBean(beanInstance);
       }
    }
 
+   @Override
    public void configureBean(String name, Object beanInstance)
    {
+      internalConfigure(beanInstance);
+      if (delegate != null)
+      {
+         delegate.configureBean(name, beanInstance);
+      }
+   }
+   
+   protected void internalConfigure(Object beanInstance)
+   {
       if (beanInstance instanceof AbstractWSDLBasedEndpointFactory)
       {
          configureEndpointFactory((AbstractWSDLBasedEndpointFactory)beanInstance);
@@ -79,39 +83,15 @@
          configureClientProxyFactoryBean((ClientProxyFactoryBean)beanInstance);
       }
       //add other beans configuration here below
-      if (delegate != null)
-      {
-         delegate.configureBean(name, beanInstance);
-      }
    }
    
    /**
-    * Configure the endpoint factory; currently set the binding customization in the databinding (Server Side).
+    * Configure the endpoint factory
     * 
     * @param factory
     */
    protected synchronized void configureEndpointFactory(AbstractWSDLBasedEndpointFactory factory)
    {
-      //Configure binding customization
-      if (customization != null)
-      {
-         //customize default databinding (early pulls in ServiceFactory default databinding and configure it, as it's lazily loaded)
-         ReflectionServiceFactoryBean serviceFactory = factory.getServiceFactory();
-         serviceFactory.reset();
-         DataBinding serviceFactoryDataBinding = serviceFactory.getDataBinding(true);
-         setBindingCustomization(serviceFactoryDataBinding, customization);
-         serviceFactory.setDataBinding(serviceFactoryDataBinding);
-         //customize user provided databinding (CXF later overrides the ServiceFactory databinding using the user provided one) 
-         if (factory.getDataBinding() == null)
-         {
-            //set the service factory's databinding to prevent CXF resetting everything because user did not provide anything
-            factory.setDataBinding(serviceFactoryDataBinding);
-         }
-         else
-         {
-            setBindingCustomization(factory.getDataBinding(), customization);
-         }
-      }
       //add other configurations here below
    }
    
@@ -134,7 +114,7 @@
          //customize user provided databinding (CXF later overrides the ServiceFactory databinding using the user provided one) 
          if (factory.getDataBinding() == null)
          {
-            //set the service factory's databinding to prevent CXF resetting everything because user did not provide anything
+            //set the endpoint factory's databinding to prevent CXF resetting everything because user did not provide anything
             factory.setDataBinding(serviceFactoryDataBinding);
          }
          else
@@ -145,6 +125,7 @@
       //add other configurations here below
    }
    
+   @SuppressWarnings("unchecked")
    protected static void setBindingCustomization(DataBinding db, BindingCustomization customization)
    {
       //JAXB
@@ -157,4 +138,9 @@
       }
       //add other binding customizations here below
    }
+   
+   public void setBindingCustomization(BindingCustomization customization)
+   {
+      this.customization = customization;
+   }
 }

Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/BusDeploymentAspect.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/BusDeploymentAspect.java	2010-03-31 15:55:22 UTC (rev 11910)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/BusDeploymentAspect.java	2010-03-31 16:14:58 UTC (rev 11911)
@@ -34,7 +34,8 @@
 import org.jboss.wsf.spi.deployment.Deployment;
 import org.jboss.wsf.spi.deployment.Endpoint;
 import org.jboss.wsf.spi.deployment.ResourceResolver;
-import org.jboss.wsf.stack.cxf.client.configuration.BusHolder;
+import org.jboss.wsf.stack.cxf.client.configuration.JBossWSCXFConfigurer;
+import org.jboss.wsf.stack.cxf.configuration.BusHolder;
 
 /**
  * A deployment aspect that creates the CXF Bus early and attaches it to the endpoints (wrapped in a BusHolder)
@@ -56,10 +57,11 @@
       ClassLoader origClassLoader = SecurityActions.getContextClassLoader();
       try
       {
+         ArchiveDeployment aDep = (ArchiveDeployment)dep;
          //set the runtime classloader (pointing to the deployment unit) to allow CXF accessing to the classes
          SecurityActions.setContextClassLoader(dep.getRuntimeClassLoader());
          
-         ResourceResolver deploymentResolver = ((ArchiveDeployment)dep).getResourceResolver();
+         ResourceResolver deploymentResolver = aDep.getResourceResolver();
 
          URL cxfServletURL = null;
          try
@@ -68,7 +70,7 @@
          }
          catch (IOException e)
          {
-         } //ignore, cxf-servlet.xml is optional
+         } //ignore, cxf-servlet.xml is optional, we might even decide not to support this
 
          holder = BusHolder.create(cxfServletURL);
 
@@ -77,8 +79,8 @@
          {
             URL jbossCxfXml = deploymentResolver.resolve(contextParams.get(BusHolder.PARAM_CXF_BEANS_URL));
             org.apache.cxf.resource.ResourceResolver resolver = new JBossWSResourceResolver(deploymentResolver);
-            BindingCustomization customizations = dep.getAttachment(BindingCustomization.class);
-            holder.configure(jbossCxfXml, new SoapTransportFactoryExt(), resolver, customizations);
+            JBossWSCXFConfigurer configurer = holder.createConfigurer(dep.getAttachment(BindingCustomization.class), new WSDLFilePublisher(aDep));
+            holder.configure(jbossCxfXml, new SoapTransportFactoryExt(), resolver, configurer);
          }
          catch (IOException e)
          {

Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java	2010-03-31 15:55:22 UTC (rev 11910)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java	2010-03-31 16:14:58 UTC (rev 11911)
@@ -54,7 +54,8 @@
 import org.jboss.wsf.spi.invocation.RequestHandler;
 import org.jboss.wsf.spi.management.EndpointRegistry;
 import org.jboss.wsf.spi.management.EndpointRegistryFactory;
-import org.jboss.wsf.stack.cxf.client.configuration.BusHolder;
+import org.jboss.wsf.stack.cxf.client.configuration.JBossWSCXFConfigurer;
+import org.jboss.wsf.stack.cxf.configuration.BusHolder;
 import org.jboss.wsf.stack.cxf.management.InstrumentationManagerExtImpl;
 import org.springframework.context.ApplicationContext;
 
@@ -133,7 +134,8 @@
       {
          ResourceResolver resolver = endpoint.getAttachment(ResourceResolver.class);
          BindingCustomization customizations = endpoint.getAttachment(BindingCustomization.class);
-         lazyLoadedBusHolder.configure(new URL(jbossCxfXml), new SoapTransportFactoryExt(), resolver, customizations);
+         JBossWSCXFConfigurer configurer = lazyLoadedBusHolder.createConfigurer(customizations, null);
+         lazyLoadedBusHolder.configure(new URL(jbossCxfXml), new SoapTransportFactoryExt(), resolver, configurer);
       }
       catch (IOException e)
       {

Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/DescriptorDeploymentAspect.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/DescriptorDeploymentAspect.java	2010-03-31 15:55:22 UTC (rev 11910)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/DescriptorDeploymentAspect.java	2010-03-31 16:14:58 UTC (rev 11911)
@@ -37,7 +37,7 @@
 import org.jboss.wsf.spi.deployment.Deployment;
 import org.jboss.wsf.spi.deployment.Endpoint;
 import org.jboss.wsf.spi.deployment.Deployment.DeploymentType;
-import org.jboss.wsf.stack.cxf.client.configuration.BusHolder;
+import org.jboss.wsf.stack.cxf.configuration.BusHolder;
 import org.jboss.wsf.stack.cxf.metadata.services.DDBeans;
 import org.jboss.wsf.stack.cxf.metadata.services.DDEndpoint;
 
@@ -171,7 +171,7 @@
 
          boolean mtomEnabled = isMtomEnabled(ep.getTargetBeanClass());
 
-         DDEndpoint ddep = new DDEndpoint(id, address, implementor, mtomEnabled);
+         DDEndpoint ddep = new DDEndpoint(id, address, implementor, mtomEnabled, JBossWSServiceFactoryBean.class.getName());
 
          if (depType == DeploymentType.JAXWS_EJB3)
          {

Added: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/JBossWSServiceFactoryBean.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/JBossWSServiceFactoryBean.java	                        (rev 0)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/JBossWSServiceFactoryBean.java	2010-03-31 16:14:58 UTC (rev 11911)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf;
+
+import java.io.IOException;
+
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.endpoint.EndpointException;
+import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.jboss.logging.Logger;
+
+/**
+ * A service factory bean that performs additional operations
+ * required by the JBossWS integration when creating a service.
+ * 
+ * @author alessio.soldano at jboss.com
+ * @since 30-Mar-2010
+ *
+ */
+public class JBossWSServiceFactoryBean extends JaxWsServiceFactoryBean
+{
+   private WSDLFilePublisher wsdlPublisher;
+   
+   @Override
+   public Endpoint createEndpoint(EndpointInfo ei) throws EndpointException
+   {
+      Endpoint endpoint = super.createEndpoint(ei);
+      Service service = endpoint.getService();
+      // Publish wsdl after endpoint deployment, as required by JSR-109, section 8.2
+      if (wsdlPublisher != null)
+      {
+         String wsdlLocation = isFromWsdl() ? getWsdlURL() : null;
+         try
+         {
+            wsdlPublisher.publishWsdlFiles(service.getName(), wsdlLocation, BusFactory.getThreadDefaultBus(false), service.getServiceInfos());
+         }
+         catch (IOException ioe)
+         {
+            throw new RuntimeException("Error while publishing wsdl for service " + service.getName(), ioe);
+         }
+      }
+      else
+      {
+         Logger.getLogger(JBossWSServiceFactoryBean.class).warn("WSDLPublisher not configured, unable to publish contract!");
+      }
+      return endpoint;
+   }
+   
+   public void setWsdlPublisher(WSDLFilePublisher wsdlPublisher)
+   {
+      this.wsdlPublisher = wsdlPublisher;
+   }
+   
+}


Property changes on: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/JBossWSServiceFactoryBean.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/WSDLFilePublisher.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/WSDLFilePublisher.java	                        (rev 0)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/WSDLFilePublisher.java	2010-03-31 16:14:58 UTC (rev 11911)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.wsdl.xml.WSDLWriter;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.wsdl.WSDLManager;
+import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
+import org.jboss.logging.Logger;
+import org.jboss.util.NotImplementedException;
+import org.jboss.ws.core.utils.AbstractWSDLFilePublisher;
+import org.jboss.wsf.spi.deployment.ArchiveDeployment;
+import org.w3c.dom.Document;
+
+/**
+ * A WSDL file publisher for CXF based stack
+ * 
+ * @author alessio.soldano at jboss.com
+ * @since 25-Mar-2010
+ *
+ */
+public class WSDLFilePublisher extends AbstractWSDLFilePublisher
+{
+   private static final Logger log = Logger.getLogger(WSDLFilePublisher.class);
+   
+   public WSDLFilePublisher(ArchiveDeployment dep)
+   {
+      super(dep);
+   }
+   
+   /** Publish the deployed wsdl file to the data directory
+    */
+   public void publishWsdlFiles(QName serviceName, String wsdlLocation, Bus bus, List<ServiceInfo> serviceInfos) throws IOException
+   {
+      String deploymentName = dep.getCanonicalName();
+      File wsdlFile = getPublishLocation(serviceName.getLocalPart(), deploymentName, wsdlLocation);
+      wsdlFile.getParentFile().mkdirs();
+      try
+      {
+         // Write the wsdl def to file
+         ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, serviceInfos);
+         Definition def = builder.build();
+
+         Document doc = getWsdlDocument(bus, def);
+         writeDocument(doc, wsdlFile);
+
+         URL wsdlPublishURL = wsdlFile.toURI().toURL();
+         log.info("WSDL published to: " + wsdlPublishURL);
+
+         // Process the wsdl imports
+         if (def != null)
+         {
+            List<String> published = new LinkedList<String>();
+            publishWsdlImports(wsdlPublishURL, def, published);
+
+            // Publish XMLSchema imports
+            publishSchemaImports(wsdlPublishURL, doc.getDocumentElement(), published);
+         }
+         else
+         {
+            throw new NotImplementedException("WSDL-2.0 imports");
+         }
+      }
+      catch (RuntimeException rte)
+      {
+         throw rte;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Cannot publish wsdl to: " + wsdlFile, e);
+      }
+   }
+   
+   private static Document getWsdlDocument(Bus bus, Definition def) throws WSDLException
+   {
+      WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
+      def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
+      return wsdlWriter.getDocument(def);
+   }
+   
+   private static void writeDocument(Document doc, File file) throws IOException, XMLStreamException
+   {
+      String enc = null;
+      try
+      {
+         enc = doc.getXmlEncoding();
+      }
+      catch (Exception ex)
+      {
+         //ignore - not dom level 3
+      }
+      if (enc == null)
+      {
+         enc = "utf-8";
+      }
+      FileOutputStream fos = new FileOutputStream(file);
+      try
+      {
+         XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(fos, enc);
+         StaxUtils.writeNode(doc, writer, true);
+         writer.flush();
+      }
+      finally
+      {
+         fos.close();
+      }
+   }
+   
+   /**
+    * Get the file publish location
+    */
+   private File getPublishLocation(String serviceName, String archiveName, String wsdlLocation) throws IOException
+   {
+      if (wsdlLocation == null && serviceName == null)
+      {
+         log.warn("Cannot get wsdl publish location for null wsdl location and serviceName!");
+         return null;
+      }
+
+      //JBWS-2829: windows issue
+      if (archiveName.startsWith("http://"))
+      {
+         archiveName = archiveName.replace("http://", "http-");
+      }
+
+      File locationFile = new File(serverConfig.getServerDataDir().getCanonicalPath() + "/wsdl/" + archiveName);
+
+      File result;
+      if (wsdlLocation != null && wsdlLocation.indexOf(expLocation) >= 0)
+      {
+         wsdlLocation = wsdlLocation.substring(wsdlLocation.indexOf(expLocation) + expLocation.length());
+         result = new File(locationFile + "/" + wsdlLocation);
+      }
+      else if (wsdlLocation != null && (wsdlLocation.startsWith("vfsfile:") || wsdlLocation.startsWith("file:") || wsdlLocation.startsWith("jar:") || wsdlLocation.startsWith("vfszip:")))
+      {
+         wsdlLocation = wsdlLocation.substring(wsdlLocation.lastIndexOf("/") + 1);
+         result = new File(locationFile + "/" + wsdlLocation);
+      }
+      else
+      {
+         result = new File(locationFile + "/" + serviceName + ".wsdl");
+      }
+
+      return result;
+   }
+}


Property changes on: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/WSDLFilePublisher.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java	                        (rev 0)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java	2010-03-31 16:14:58 UTC (rev 11911)
@@ -0,0 +1,243 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.configuration;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.binding.soap.SoapTransportFactory;
+import org.apache.cxf.bus.spring.BusApplicationContext;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.configuration.Configurer;
+import org.apache.cxf.resource.ResourceManager;
+import org.apache.cxf.resource.ResourceResolver;
+import org.apache.cxf.transport.DestinationFactory;
+import org.apache.cxf.transport.DestinationFactoryManager;
+import org.apache.cxf.transport.servlet.ServletTransportFactory;
+import org.jboss.logging.Logger;
+import org.jboss.ws.Constants;
+import org.jboss.wsf.spi.binding.BindingCustomization;
+import org.jboss.wsf.stack.cxf.WSDLFilePublisher;
+import org.jboss.wsf.stack.cxf.client.configuration.JBossWSCXFConfigurer;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.InputStreamResource;
+
+/**
+ * An wrapper of the Bus for performing most of the configurations required on it by JBossWS
+ * 
+ * @author alessio.soldano at jboss.com
+ * @since 25-Mar-2010
+ *
+ */
+public class BusHolder
+{
+   private static final Logger log = Logger.getLogger(BusHolder.class);
+   public static final String PARAM_CXF_BEANS_URL = "jbossws.cxf.beans.url";
+   private boolean configured = false;
+   protected BusApplicationContext ctx ;
+   protected List<GenericApplicationContext> additionalCtx = new LinkedList<GenericApplicationContext>();
+   protected Bus bus;
+   
+   /**
+    * Private constructor
+    */
+   private BusHolder()
+   {
+      //NOP
+   }
+   
+   /**
+    * Creates a new BusHolder instance; a new Bus is created using the
+    * provided location for loading additional configurations
+    * 
+    * @param location
+    * @return
+    */
+   public static BusHolder create(URL location)
+   {
+      BusHolder holder = new BusHolder();
+      holder.createBus(location);
+      return holder;
+   }
+   
+   /**
+    * Creates a new BusHolder instance using the provided Bus
+    * 
+    * @param bus
+    * @return
+    */
+   public static BusHolder create(Bus bus)
+   {
+      BusHolder holder = new BusHolder();
+      holder.setBus(bus);
+      holder.setContext(bus.getExtension(BusApplicationContext.class));
+      return holder;
+   }
+   
+   /**
+    * Update the Bus held by the this instance using the provided parameters.
+    * This basically prepares the bus for being used with JBossWS.
+    * 
+    * @param jbossCxfXml    The location of the jboss-cxf.xml configuration file
+    * @param soapTransportFactory   The SoapTransportFactory to configure, if any
+    * @param resolver               The ResourceResolver to configure, if any
+    * @param configurer             The JBossWSCXFConfigurer to install in the bus, if any
+    * @throws IOException           Throws IOException if the jboss-cxf.xml file can't be read
+    */
+   public void configure(URL jbossCxfXml, SoapTransportFactory soapTransportFactory, ResourceResolver resolver, JBossWSCXFConfigurer configurer) throws IOException
+   {
+      if (configured)
+      {
+         throw new IllegalStateException("Underlying bus is already configured for JBossWS use!");
+      }
+      if (configurer != null)
+      {
+         bus.setExtension(configurer, Configurer.class);
+      }
+      setSoapTransportFactory(bus, soapTransportFactory);
+      setResourceResolver(bus, resolver);
+      if (jbossCxfXml != null)
+      {
+         additionalCtx.add(loadAdditionalConfig(ctx, jbossCxfXml));
+      }
+      configured = true;
+   }
+   
+   /**
+    * A convenient method for getting a jbossws cxf configurer delegating to the cxf configurer
+    * that's currently installed in the hold bus.
+    * 
+    * @param customization    The binding customization to set in the configurer, if any
+    * @param wsdlPublisher    The wsdl file publisher to set in the configurer, if any
+    * @return                 The new jbossws cxf configurer
+    */
+   public JBossWSCXFConfigurer createConfigurer(BindingCustomization customization, WSDLFilePublisher wsdlPublisher)
+   {
+      Configurer delegate = bus.getExtension(Configurer.class);
+      return new JBossWSServerCXFConfigurer(delegate, customization, wsdlPublisher);
+   }
+   
+   /**
+    * Performs close operations (currently implies destroying additional contexts)
+    * 
+    */
+   public void close()
+   {
+      for (GenericApplicationContext gac : additionalCtx)
+      {
+         gac.destroy();
+      }
+   }
+   
+   /**
+    * Creates the Bus using a SpringBusFactory with no specific Spring application context.
+    * Then loads additional configurations from the provided location
+    * 
+    * @param location
+    * @return
+    */
+   protected void createBus(URL location)
+   {
+      bus = new SpringBusFactory().createBus();
+      ctx = bus.getExtension(BusApplicationContext.class);
+      //Load additional configurations from cxf-servlet.xml
+      if (location != null)
+      {
+         try
+         {
+            additionalCtx.add(loadAdditionalConfig(ctx, location));
+         }
+         catch (IOException e)
+         {
+            if (log.isTraceEnabled())
+               log.trace("Could not load additional config from location: " + location, e);
+         }
+      }
+      //Force servlet transport to prevent CXF from using Jetty as a transport
+      DestinationFactory factory = new ServletTransportFactory(bus);
+      for (String s : factory.getTransportIds()) {
+          registerTransport(factory, s);
+      }
+   }
+   
+   protected static void setResourceResolver(Bus bus, ResourceResolver resourceResolver)
+   {
+      if (resourceResolver != null)
+      {
+         bus.getExtension(ResourceManager.class).addResourceResolver(resourceResolver);
+      }
+   }
+   
+   protected static void setSoapTransportFactory(Bus bus, SoapTransportFactory factory)
+   {
+      if (factory != null)
+      {
+         DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
+         factory.setBus(bus);
+         dfm.registerDestinationFactory(Constants.NS_SOAP11, factory);
+         dfm.registerDestinationFactory(Constants.NS_SOAP12, factory);
+      }
+   }
+   
+   protected static GenericApplicationContext loadAdditionalConfig(ApplicationContext ctx, URL locationUrl) throws IOException
+   {
+      if (locationUrl == null) throw new IllegalArgumentException("Cannot load additional config from null location!");
+      InputStream is = locationUrl.openStream();
+      GenericApplicationContext childCtx = new GenericApplicationContext(ctx);
+      XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(childCtx);
+      reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
+      reader.loadBeanDefinitions(new InputStreamResource(is));
+      childCtx.refresh();
+      return childCtx;
+   }
+
+   private void registerTransport(DestinationFactory factory, String namespace)
+   {
+      bus.getExtension(DestinationFactoryManager.class).registerDestinationFactory(namespace, factory);
+   }
+
+   /**
+    * Return the hold bus
+    * 
+    * @return
+    */
+   public Bus getBus()
+   {
+      return bus;
+   }
+   
+   private void setBus(Bus bus)
+   {
+      this.bus = bus;
+   }
+   
+   private void setContext(BusApplicationContext ctx)
+   {
+      this.ctx = ctx;
+   }
+}


Property changes on: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/BusHolder.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/JBossWSServerCXFConfigurer.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/JBossWSServerCXFConfigurer.java	                        (rev 0)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/JBossWSServerCXFConfigurer.java	2010-03-31 16:14:58 UTC (rev 11911)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.configuration;
+
+import org.apache.cxf.configuration.Configurer;
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory;
+import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
+import org.jboss.wsf.spi.binding.BindingCustomization;
+import org.jboss.wsf.stack.cxf.JBossWSServiceFactoryBean;
+import org.jboss.wsf.stack.cxf.WSDLFilePublisher;
+import org.jboss.wsf.stack.cxf.client.configuration.JBossWSCXFConfigurer;
+
+/**
+ * A JBossWSCXFConfigured to be used on server side
+ * 
+ * @author alessio.soldano at jboss.com
+ * @since 31-Mar-2010
+ */
+public class JBossWSServerCXFConfigurer extends JBossWSCXFConfigurer
+{
+   private WSDLFilePublisher wsdlPublisher;
+
+   public JBossWSServerCXFConfigurer(Configurer delegate)
+   {
+      super(delegate);
+   }
+   
+   public JBossWSServerCXFConfigurer(Configurer delegate, BindingCustomization customization, WSDLFilePublisher wsdlPublisher)
+   {
+      super(delegate, customization);
+      this.wsdlPublisher = wsdlPublisher;
+   }
+
+   @Override
+   protected synchronized void configureEndpointFactory(AbstractWSDLBasedEndpointFactory factory)
+   {
+      ReflectionServiceFactoryBean serviceFactory = factory.getServiceFactory();
+      //Configure binding customization
+      if (customization != null)
+      {
+         //customize default databinding (early pulls in ServiceFactory default databinding and configure it, as it's lazily loaded)
+         serviceFactory.reset();
+         DataBinding serviceFactoryDataBinding = serviceFactory.getDataBinding(true);
+         setBindingCustomization(serviceFactoryDataBinding, customization);
+         serviceFactory.setDataBinding(serviceFactoryDataBinding);
+         //customize user provided databinding (CXF later overrides the ServiceFactory databinding using the user provided one) 
+         if (factory.getDataBinding() == null)
+         {
+            //set the endpoint factory's databinding to prevent CXF resetting everything because user did not provide anything
+            factory.setDataBinding(serviceFactoryDataBinding);
+         }
+         else
+         {
+            setBindingCustomization(factory.getDataBinding(), customization);
+         }
+      }
+      //Configure wsdl file publisher
+      if (wsdlPublisher != null && serviceFactory instanceof JBossWSServiceFactoryBean)
+      {
+         ((JBossWSServiceFactoryBean)serviceFactory).setWsdlPublisher(wsdlPublisher);
+      }
+      //add other configurations here below
+   }
+   
+   public void setWsdlPublisher(WSDLFilePublisher wsdlPublisher)
+   {
+      this.wsdlPublisher = wsdlPublisher;
+   }
+
+}


Property changes on: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/configuration/JBossWSServerCXFConfigurer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDEndpoint.java
===================================================================
--- stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDEndpoint.java	2010-03-31 15:55:22 UTC (rev 11910)
+++ stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/metadata/services/DDEndpoint.java	2010-03-31 16:14:58 UTC (rev 11911)
@@ -37,13 +37,15 @@
    private String implementor;
    private String invoker;
    private boolean mtomEnabled;
+   private String serviceFactory;
 
-   public DDEndpoint(String id, String address, String implementor, boolean mtomEnabled)
+   public DDEndpoint(String id, String address, String implementor, boolean mtomEnabled, String serviceFactory)
    {
       this.id = id;
       this.address = address;
       this.implementor = implementor;
       this.mtomEnabled = mtomEnabled;
+      this.serviceFactory = serviceFactory;
    }
 
    public void setInvoker(String invoker)
@@ -58,6 +60,8 @@
       writer.write(" implementor='" + this.implementor + "'");
       writer.write(">");
       
+      writer.write("<jaxws:serviceFactory><bean class='" + this.serviceFactory + "'/></jaxws:serviceFactory>");
+      
       if (this.mtomEnabled)
       {
          writer.write("<jaxws:binding>");
@@ -81,6 +85,7 @@
       str.append("\n implementor=" + this.implementor);
       str.append("\n invoker=" + this.invoker);
       str.append("\n mtomEnabled=" + this.mtomEnabled);
+      str.append("\n serviceFactory=" + this.serviceFactory);
       return str.toString();
    }
 }



More information about the jbossws-commits mailing list