[jboss-svn-commits] JBL Code SVN: r35880 - in labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap: src/main/java/org/jboss/soa/esb/actions/soap and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Nov 5 11:01:03 EDT 2010


Author: kevin.conner at jboss.com
Date: 2010-11-05 11:01:01 -0400 (Fri, 05 Nov 2010)
New Revision: 35880

Added:
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/JBossWSFactory.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/CXFFactory.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/wsnative/NativeFactory.java
Modified:
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/cxf/java/org/jboss/internal/soa/esb/soap/cxf/ESBCXFServletExt.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/RemoteWsdlLoader.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/SOAPProcessorFactory.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/JBossWSCXFFactory.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/ServletControllerExtProviderFactory.java
   labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java
Log:
Fix WSDL handling for native and CXF: JBESB-3503

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/cxf/java/org/jboss/internal/soa/esb/soap/cxf/ESBCXFServletExt.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/cxf/java/org/jboss/internal/soa/esb/soap/cxf/ESBCXFServletExt.java	2010-11-05 13:25:12 UTC (rev 35879)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/cxf/java/org/jboss/internal/soa/esb/soap/cxf/ESBCXFServletExt.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -25,6 +25,7 @@
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
+import org.apache.cxf.Bus;
 import org.jboss.wsf.spi.deployment.Endpoint;
 import org.jboss.wsf.stack.cxf.CXFServletExt;
 import org.jboss.wsf.stack.cxf.ServletControllerExt;
@@ -40,6 +41,7 @@
         if (extensions != null)
         {
             extensions.put(ServletControllerExt.class, controller) ;
+            extensions.put(Bus.class, bus) ;
         }
     }
     

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/RemoteWsdlLoader.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/RemoteWsdlLoader.java	2010-11-05 13:25:12 UTC (rev 35879)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/RemoteWsdlLoader.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -36,6 +36,7 @@
 import org.jboss.internal.soa.esb.util.StreamUtils;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.actions.routing.http.HttpMethodFactory;
+import org.jboss.soa.esb.actions.soap.adapter.JBossWSFactory;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.http.HttpClientFactory;
 import org.jboss.soa.esb.util.ClassUtil;
@@ -68,8 +69,11 @@
         byte[] originalBytes = null;
         String charsetNameDetected = null;
         
-        if(url.startsWith("file")) {
+        // file, vfs, vfsfile, vfsjar, vfsmemory, vfszip, zip
+        if(url.startsWith("file") || url.startsWith("vfs") || url.startsWith("zip")) {
             originalStream = new URL(url).openStream();
+        } else if(url.startsWith(JBossWSFactory.ESB_INTERNAL_URI)) {
+            originalStream = JBossWSFactory.getFactory().getWsdl(url) ;
         } else if(url.startsWith("classpath://")) {
         	originalStream = ClassUtil.getResource(url.substring(12, url.length()), getClass()).openStream();
         } else {

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java	2010-11-05 13:25:12 UTC (rev 35879)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -36,6 +36,7 @@
 import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;
 import org.jboss.soa.esb.actions.ActionProcessingException;
 import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.actions.soap.adapter.JBossWSFactory;
 import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorFactory;
 import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorHttpServletRequest;
 import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorHttpServletResponse;
@@ -279,17 +280,11 @@
     {
         if (JBossDeployerUtil.isWebMetaDataPresent())
         {
-            final Deployment deployment = endpoint.getService().getDeployment();
-            final JBossWebMetaData attachment = deployment.getAttachment(JBossWebMetaData.class);
-            
-            if (attachment != null)
+            final ClassLoader tccl = JBossWSFactory.getFactory().getClassLoader(endpoint) ;
+            if (tccl != null)
             {
-                final ClassLoader tccl = attachment.getENCLoader() ;
-                if (tccl != null)
-                {
-                    Thread.currentThread().setContextClassLoader(tccl);
-                    return ;
-                }
+                Thread.currentThread().setContextClassLoader(tccl);
+                return ;
             }
             throw new ActionProcessingException("Could not locate ENC ClassLoader for service endpoint '" + jbossws_endpoint + "'.");
         }

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java	2010-11-05 13:25:12 UTC (rev 35879)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -21,35 +21,19 @@
  */
 package org.jboss.soa.esb.actions.soap;
 
-import java.io.File;
-import java.io.IOException;
 import java.net.URL;
 import java.util.Set;
 
 import javax.management.ObjectName;
 import javax.wsdl.Definition;
 import javax.wsdl.WSDLException;
-import javax.xml.namespace.QName;
 
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.DefaultHandler;
-import org.xml.sax.helpers.XMLReaderFactory;
-
-import org.jboss.soa.esb.actions.ActionProcessingException;
-import org.jboss.ws.core.utils.JBossWSEntityResolver;
+import org.jboss.soa.esb.actions.soap.adapter.JBossWSFactory;
 import org.jboss.wsf.spi.SPIProvider;
 import org.jboss.wsf.spi.SPIProviderResolver;
-import org.jboss.wsf.spi.deployment.ArchiveDeployment;
 import org.jboss.wsf.spi.deployment.Endpoint;
 import org.jboss.wsf.spi.management.EndpointRegistry;
 import org.jboss.wsf.spi.management.EndpointRegistryFactory;
-import org.jboss.wsf.spi.management.ServerConfig;
-import org.jboss.wsf.spi.management.ServerConfigFactory;
 
 /**
  * Holds reusable utilities and constants needed by SOAP services.
@@ -111,58 +95,6 @@
     }
 
     /**
-     * Get the internal File system location of the WSDL for a given endpoint.
-     *
-     * @param endpoint Service Endpoint.
-     * @return If found, the File URI else null.
-     */
-    public static String getWsdlLocation(Endpoint endpoint)
-    {
-        SPIProvider spiProv = SPIProviderResolver.getInstance().getProvider();
-        // Code lifted from org.jboss.ws.core.utils.AbstractWSDLFilePublisher that is common for all WS stacks
-        ServerConfig serverConfig = spiProv.getSPI(ServerConfigFactory.class).getServerConfig();
-        ArchiveDeployment dep = (ArchiveDeployment)endpoint.getService().getDeployment();
-        String deploymentDir = (dep.getParent() != null ? dep.getParent().getSimpleName() : dep.getSimpleName());
-        String wsdlLocation = null;
-        try
-        {
-            File rootDir = new File(serverConfig.getServerDataDir().getCanonicalPath() + "/wsdl/" + deploymentDir);
-            wsdlLocation = getWsdlFile(rootDir, endpoint.getShortName());
-        }
-        catch (IOException ioe)
-        {
-            throw new RuntimeException(ioe);
-        }
-        return wsdlLocation;
-    }
-
-    /**
-     * Recursively search a given root directory for a file with .wsdl extension that matches the endpoint name.
-     *
-     * @param rootDir The root directory to search from.
-     * @param endpointName Service Endpoint name.
-     * @return If found, the File URI else null.
-     */
-    private static String getWsdlFile(File rootDir, String endpointName)
-    {
-        String wsdlFile = null;
-        for (File file : rootDir.listFiles())
-        {
-            if (file.isDirectory())
-            {
-                wsdlFile = getWsdlFile(file, endpointName);
-            }
-            else
-            {
-                if (file.getName().endsWith(".wsdl") && file.getName().startsWith(endpointName))
-                    wsdlFile = file.toURI().toString();
-            }
-        }
-        return wsdlFile;
-    }
-    
-
-    /**
      * Parse and create wsdl4j Definition from a given WSDL URL.
      *
      * @param wsdlURL The URL to WSDL.
@@ -170,9 +102,6 @@
      */
     public static Definition readWSDL(URL wsdlURL) throws WSDLException
     {
-        EntityResolver entityResolver = new JBossWSEntityResolver();
-        JBossWSDLReader wsdlReader = new JBossWSDLReader();
-        Definition definition = wsdlReader.readWSDL(new JBossWSDLLocatorImpl(entityResolver, wsdlURL));
-        return definition;
+        return JBossWSFactory.getFactory().readWSDL(wsdlURL) ;
     }
 }
\ No newline at end of file

Added: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/JBossWSFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/JBossWSFactory.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/JBossWSFactory.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+
+package org.jboss.soa.esb.actions.soap.adapter;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.JBossDeployerUtil;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.soa.esb.actions.soap.JBossWSDLLocatorImpl;
+import org.jboss.soa.esb.actions.soap.JBossWSDLReader;
+import org.jboss.soa.esb.actions.soap.adapter.wsnative.NativeFactory;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.jboss.ws.core.utils.JBossWSEntityResolver;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.xml.sax.EntityResolver;
+
+/**
+ * Factory for providing a common abstraction for all native/CXF functions.
+ *  
+ * @author <a href="mailto:kevin.conner at jboss.com">Kevin Conner</a>
+ */
+public abstract class JBossWSFactory
+{
+    /**
+     * The logger for the soap processor factory implementations.
+     */
+    private static final Logger LOGGER = Logger.getLogger(JBossWSFactory.class) ;
+    /**
+     * The internal URI that should be returned as the WSDL location if a subsequent request
+     * should be make through the getWsdl method.
+     */
+    public static final String ESB_INTERNAL_URI = "esbinternal" ;
+    
+    /**
+     * The implementation factory.
+     */
+    private static final JBossWSFactory FACTORY ;
+    
+    /**
+     * Get the factory singleton.
+     * @return The factory singleton.
+     */
+    public static JBossWSFactory getFactory()
+    {
+        return FACTORY ;
+    }
+    
+    /**
+     * Get the SOAP Processor factory for the specific implementation.
+     * @return The SOAP Processor factory.
+     */
+    public abstract SOAPProcessorFactory getSOAPProcessorFactory() ;
+    
+    /**
+     * Get the URI representing the WSDL location for the specified endpoint
+     * @param endpoint The specific endpoint.
+     * @return The WSDL location or null if unknown.
+     */
+    public abstract String getWsdlLocation(final Endpoint endpoint, final String endpointName) ;
+    
+    /**
+     * Get the WSDL for the specified endpoint.
+     * @param uri The URI representing the endpoint.
+     * @return The WSDL or null if unknown.
+     * @throws IOException for errors creating the stream
+     */
+    public abstract InputStream getWsdl(final String uri)
+        throws IOException ;
+    
+    /**
+     * Get the definition for the WSDL at the specific location.
+     * @param wsdlURL The WSDL URL.
+     * @return The definition.
+     * @throws WSDLException For errors parsing the WSDL.
+     */
+    public abstract Definition readWSDL(URL wsdlURL)
+        throws WSDLException ;
+    
+    /**
+     * Get the context ClassLoader for the specified endpoint
+     * @param endpoint The specific endpoint.
+     * @return The context ClassLoader.
+     */
+    public ClassLoader getClassLoader(final Endpoint endpoint)
+    {
+        if (JBossDeployerUtil.isWebMetaDataPresent())
+        {
+            final Deployment deployment = endpoint.getService().getDeployment();
+            final JBossWebMetaData attachment = deployment.getAttachment(JBossWebMetaData.class);
+            
+            if (attachment != null)
+            {
+                return attachment.getENCLoader() ;
+            }
+        }
+        return null ;
+    }
+    
+    static
+    {
+        JBossWSFactory factory = null ;
+
+        if (JBossDeployerUtil.getWSImpl().equals(JBossDeployerUtil.WSIMPL_CXF))
+        {
+            try
+            {
+                // Load using reflection as it will not be present on 1.5 compilations
+                final Class<?> factoryClass = ClassUtil.forName("org.jboss.soa.esb.actions.soap.adapter.cxf.CXFFactory", JBossWSFactory.class) ;
+                factory = JBossWSFactory.class.cast(factoryClass.newInstance()) ;
+            }
+            catch (final Throwable th)
+            {
+                if (LOGGER.isDebugEnabled())
+                {
+                    LOGGER.debug("Failed to load CXF factory", th) ;
+                }
+            }
+        }
+        if (factory == null)
+        {
+            factory = new NativeFactory() ;
+        }
+        FACTORY = factory ;
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/JBossWSFactory.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/SOAPProcessorFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/SOAPProcessorFactory.java	2010-11-05 13:25:12 UTC (rev 35879)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/SOAPProcessorFactory.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -20,10 +20,6 @@
 
 import javax.servlet.ServletContext;
 
-import org.apache.log4j.Logger;
-import org.jboss.internal.soa.esb.util.JBossDeployerUtil;
-import org.jboss.soa.esb.actions.soap.adapter.wsnative.JBossWSNativeFactory;
-import org.jboss.soa.esb.util.ClassUtil;
 import org.jboss.wsf.spi.deployment.Endpoint;
 
 /**
@@ -35,22 +31,12 @@
 public abstract class SOAPProcessorFactory
 {
     /**
-     * The logger for the soap processor factory implementations.
-     */
-    private static final Logger LOGGER = Logger.getLogger(SOAPProcessorFactory.class) ;
-    
-    /**
-     * The implementation factory.
-     */
-    private static final SOAPProcessorFactory FACTORY ;
-    
-    /**
      * Get the factory singleton.
      * @return The factory singleton.
      */
     public static SOAPProcessorFactory getFactory()
     {
-        return FACTORY ;
+        return JBossWSFactory.getFactory().getSOAPProcessorFactory() ;
     }
     
     /**
@@ -59,32 +45,4 @@
      * @return The servlet context.
      */
     public abstract ServletContext createServletContext(final Endpoint endpoint) ;
-    
-    static
-    {
-        SOAPProcessorFactory factory = null ;
-
-        if (JBossDeployerUtil.getWSImpl().equals(JBossDeployerUtil.WSIMPL_CXF))
-        {
-            try
-            {
-                // Load using reflection as it will not be present on 1.5 compilations
-                final Class<?> factoryClass = ClassUtil.forName("org.jboss.soa.esb.actions.soap.adapter.cxf.JBossWSCXFFactory", SOAPProcessorFactory.class) ;
-                factory = SOAPProcessorFactory.class.cast(factoryClass.newInstance()) ;
-            }
-            catch (final Throwable th)
-            {
-                if (LOGGER.isDebugEnabled())
-                {
-                    LOGGER.debug("Failed to load CXF factory", th) ;
-                }
-            }
-        }
-        if (factory == null)
-        {
-            factory = new JBossWSNativeFactory() ;
-        }
-        FACTORY = factory ;
-        
-    }
 }

Added: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/CXFFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/CXFFactory.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/CXFFactory.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -0,0 +1,273 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+
+package org.jboss.soa.esb.actions.soap.adapter.cxf;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.wsdl.xml.WSDLWriter;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.endpoint.ServerRegistry;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.wsdl.WSDLManager;
+import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.JBossDeployerUtil;
+import org.jboss.soa.esb.actions.soap.WebServiceUtils;
+import org.jboss.soa.esb.actions.soap.adapter.JBossWSFactory;
+import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorFactory;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.stack.cxf.configuration.BusHolder;
+
+/**
+ * Factory for JBossWS CXF specific details.
+ *  
+ * @author <a href="mailto:kevin.conner at jboss.com">Kevin Conner</a>
+ */
+public class CXFFactory extends JBossWSFactory
+{
+    /**
+     * The SOAP Processor factory.
+     */
+    private final SOAPProcessorFactory soapProcessorFactory = new JBossWSCXFFactory() ;
+    /**
+     * The factory for accessing the Bus.
+     */
+    private static final BusFactory BUS_FACTORY ;
+    /**
+     * The Logger for this class.
+     */
+    private static final Logger LOGGER = Logger.getLogger(CXFFactory.class) ;
+    
+    @Override
+    public SOAPProcessorFactory getSOAPProcessorFactory()
+    {
+        return soapProcessorFactory ;
+    }
+
+    @Override
+    public String getWsdlLocation(final Endpoint endpoint, final String endpointName)
+    {
+        final ClassLoader old = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            initialiseContextClassLoader(endpoint);
+            final Definition definition = getDefinition(endpoint) ;
+            if (definition != null)
+            {
+                final String documentBaseURI = definition.getDocumentBaseURI() ;
+                try
+                {
+                    return (documentBaseURI == null ? new URI(ESB_INTERNAL_URI, endpointName, null).toString() : documentBaseURI) ;
+                }
+                catch (final URISyntaxException urise)
+                {
+                    throw new IllegalArgumentException("Could not create internal URI reference for endpoint " + endpointName, urise) ;
+                }
+            }
+            return null ;
+        }
+        finally
+        {
+            Thread.currentThread().setContextClassLoader(old);
+        }
+    }
+
+    @Override
+    public InputStream getWsdl(final String uri)
+        throws IOException
+    {
+        final URI endpointURI ;
+        try
+        {
+            endpointURI = new URI(uri) ;
+        }
+        catch (final URISyntaxException urise)
+        {
+            final IOException ioe = new IOException("Failed to parse endpoint URI") ;
+            ioe.initCause(urise) ;
+            throw ioe ;
+        }
+        final String endpointName = endpointURI.getSchemeSpecificPart() ;
+        final Endpoint endpoint = WebServiceUtils.getDeploymentEndpoint(endpointName) ;
+        
+        final ClassLoader old = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            initialiseContextClassLoader(endpoint);
+            final Definition definition = getDefinition(endpoint) ;
+            if (definition != null)
+            {
+                final Bus bus = BUS_FACTORY.getBus(endpoint) ;
+                
+                final WSDLManager wsdlManager = bus.getExtension(WSDLManager.class) ;
+                final  WSDLWriter wsdlWriter = wsdlManager.getWSDLFactory().newWSDLWriter();
+                definition.setExtensionRegistry(wsdlManager.getExtensionRegistry());
+                final ByteArrayOutputStream baos = new ByteArrayOutputStream() ;
+                try
+                {
+                    wsdlWriter.writeWSDL(definition, baos);
+                }
+                catch (final WSDLException wsdle)
+                {
+                    final IOException ioe = new IOException("Failed to generate WSDL") ;
+                    ioe.initCause(wsdle) ;
+                    throw ioe ;
+                }
+                return new ByteArrayInputStream(baos.toByteArray()) ;
+            }
+            return null ;
+        }
+        finally
+        {
+            Thread.currentThread().setContextClassLoader(old);
+        }
+    }
+
+    @Override
+    public Definition readWSDL(final URL wsdlURL)
+        throws WSDLException
+    {
+        WSDLFactory wsdlFactory = WSDLFactory.newInstance();
+        WSDLReader reader = wsdlFactory.newWSDLReader();
+        reader.setFeature("javax.wsdl.verbose", false);
+        return reader.readWSDL(wsdlURL.toString());
+    }
+
+    protected Definition getDefinition(final Endpoint endpoint)
+    {
+        final Bus bus = BUS_FACTORY.getBus(endpoint) ;
+        
+        final ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class) ;
+        final String address = endpoint.getAddress() ;
+        final EndpointInfo endpointInfo = getEndpointInfo(address, serverRegistry) ;
+        if (endpointInfo != null)
+        {
+            final ServiceInfo serviceInfo = endpointInfo.getService() ;
+            final ServiceWSDLBuilder serviceWSDLBuilder = new ServiceWSDLBuilder(bus, serviceInfo) ;
+            try
+            {
+                return serviceWSDLBuilder.build() ;
+            }
+            catch (final WSDLException wsdle)
+            {
+                throw new IllegalStateException("Failed to generate WSDL", wsdle) ;
+            }
+        }
+        return null ;
+    }
+
+    protected EndpointInfo getEndpointInfo(final String address, final ServerRegistry serverRegistry)
+    {
+        if (address != null)
+        {
+            final List<Server> servers = serverRegistry.getServers() ;
+            if (servers != null)
+            {
+                for(Server server: servers)
+                {
+                    final EndpointInfo endpointInfo = server.getEndpoint().getEndpointInfo() ;
+                    if (address.equals(endpointInfo.getAddress()))
+                    {
+                        return endpointInfo ;
+                    }
+                }
+            }
+        }
+        return null ;
+    }
+    
+    private void initialiseContextClassLoader(final Endpoint endpoint)
+    {
+        if (JBossDeployerUtil.isWebMetaDataPresent())
+        {
+            final ClassLoader tccl = JBossWSFactory.getFactory().getClassLoader(endpoint) ;
+            if (tccl != null)
+            {
+                Thread.currentThread().setContextClassLoader(tccl) ;
+                return ;
+            }
+            throw new IllegalStateException("Could not locate ENC ClassLoader for service endpoint.") ;
+        }
+    }
+    
+    private interface BusFactory
+    {
+        public Bus getBus(final Endpoint endpoint) ;
+    }
+    
+    private static final class BusHolderFactory implements BusFactory
+    {
+        public Bus getBus(final Endpoint endpoint)
+        {
+            final BusHolder busHolder = endpoint.getAttachment(BusHolder.class) ;
+            return busHolder.getBus() ;
+        }
+    }
+    
+    private static final class BusExtensionFactory implements BusFactory
+    {
+        public Bus getBus(final Endpoint endpoint)
+        {
+            final Map<Class<?>, Object> extensions = endpoint.getAttachment(Map.class) ;
+            final Bus bus = (extensions == null ? null : (Bus) extensions.get(Bus.class)) ;
+            if (bus == null)
+            {
+                LOGGER.error("CXF Bus not present in endpoint attachments.  Has the CXF integration bean configured?  See ESB documentation for details.") ;
+                throw new IllegalStateException("Could not locate CXF Bus attachment") ;
+            }
+            return bus ;
+        }
+    }
+    
+    static
+    {
+        boolean busHolderExists = false ;
+        try
+        {
+            ClassUtil.forName("org.jboss.wsf.stack.cxf.configuration.BusHolder", ServletControllerExtProviderFactory.class) ;
+            busHolderExists = true ;
+        }
+        catch (final Throwable th) {} // ignore
+        
+        if (busHolderExists)
+        {
+            BUS_FACTORY = new BusHolderFactory() ;
+        }
+        else
+        {
+            BUS_FACTORY = new BusExtensionFactory() ;
+        }
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/CXFFactory.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/JBossWSCXFFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/JBossWSCXFFactory.java	2010-11-05 13:25:12 UTC (rev 35879)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/JBossWSCXFFactory.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -28,7 +28,7 @@
  *  
  * @author <a href="mailto:kevin.conner at jboss.com">Kevin Conner</a>
  */
-public class JBossWSCXFFactory extends SOAPProcessorFactory
+class JBossWSCXFFactory extends SOAPProcessorFactory
 {
     public ServletContext createServletContext(final Endpoint endpoint)
     {

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/ServletControllerExtProviderFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/ServletControllerExtProviderFactory.java	2010-11-05 13:25:12 UTC (rev 35879)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/cxf/ServletControllerExtProviderFactory.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -18,22 +18,13 @@
 
 package org.jboss.soa.esb.actions.soap.adapter.cxf;
 
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
 import java.util.Map;
-import java.util.Set;
 
-import javax.servlet.RequestDispatcher;
-import javax.servlet.Servlet;
 import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.transport.DestinationFactory;
 import org.apache.cxf.transport.DestinationFactoryManager;
-import org.apache.cxf.transport.servlet.ServletController;
 import org.apache.cxf.transport.servlet.ServletTransportFactory;
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.util.ClassUtil;
@@ -138,7 +129,7 @@
         ServletControllerExtImpl(final Endpoint endpoint, final ServletContext context)
         {
             final Map<Class<?>, Object> extensions = endpoint.getAttachment(Map.class) ;
-            servletControllerExt = (ServletControllerExt) extensions.get(ServletControllerExt.class) ;
+            servletControllerExt = (extensions == null ? null : (ServletControllerExt) extensions.get(ServletControllerExt.class)) ;
             if (servletControllerExt == null)
             {
                 LOGGER.error("ServletControllerExt not present in endpoint attachments.  Has the CXF integration bean configured?  See ESB documentation for details.") ;

Added: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/wsnative/NativeFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/wsnative/NativeFactory.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/wsnative/NativeFactory.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+
+package org.jboss.soa.esb.actions.soap.adapter.wsnative;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+
+import org.jboss.soa.esb.actions.soap.JBossWSDLLocatorImpl;
+import org.jboss.soa.esb.actions.soap.JBossWSDLReader;
+import org.jboss.soa.esb.actions.soap.adapter.JBossWSFactory;
+import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorFactory;
+import org.jboss.ws.core.utils.JBossWSEntityResolver;
+import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.xml.sax.EntityResolver;
+
+/**
+ * Factory for creating JBossWS native specific details.
+ *  
+ * @author <a href="mailto:kevin.conner at jboss.com">Kevin Conner</a>
+ */
+public class NativeFactory extends JBossWSFactory
+{
+    /**
+     * The SOAP Processor factory.
+     */
+    private final SOAPProcessorFactory soapProcessorFactory = new JBossWSNativeFactory() ;
+    
+    @Override
+    public SOAPProcessorFactory getSOAPProcessorFactory()
+    {
+        return soapProcessorFactory ;
+    }
+
+    @Override
+    public String getWsdlLocation(final Endpoint endpoint, final String endpointName)
+    {
+        final ServerEndpointMetaData serverEndpointMetaData = endpoint.getAttachment(ServerEndpointMetaData.class);
+        if (serverEndpointMetaData != null)
+        {
+            return serverEndpointMetaData.getServiceMetaData().getWsdlLocation().toExternalForm() ;
+        }
+        else
+        {
+            return null ;
+        }
+    }
+
+    @Override
+    public InputStream getWsdl(final String uri)
+        throws IOException
+    {
+        throw new UnsupportedOperationException("getWsdl should not be called for native webservices, uri is " + uri) ;
+    }
+
+    @Override
+    public Definition readWSDL(URL wsdlURL) throws WSDLException
+    {
+        EntityResolver entityResolver = new JBossWSEntityResolver();
+        JBossWSDLReader wsdlReader = new JBossWSDLReader();
+        Definition definition = wsdlReader.readWSDL(new JBossWSDLLocatorImpl(entityResolver, wsdlURL));
+        return definition;
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/adapter/wsnative/NativeFactory.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java	2010-11-05 13:25:12 UTC (rev 35879)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java	2010-11-05 15:01:01 UTC (rev 35880)
@@ -53,6 +53,7 @@
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.actions.soap.AuthBASICWsdlContractPublisher;
 import org.jboss.soa.esb.actions.soap.WebServiceUtils;
+import org.jboss.soa.esb.actions.soap.adapter.JBossWSFactory;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.http.HttpClientFactory;
 import org.jboss.soa.esb.http.configurators.Connection;
@@ -476,12 +477,13 @@
 			Endpoint end = WebServiceUtils.getDeploymentEndpoint(end_name);
 			if (end != null)
 			{
-				return WebServiceUtils.getWsdlLocation(end);
+				final String wsdlLocation = JBossWSFactory.getFactory().getWsdlLocation(end, end_name);
+				if (wsdlLocation != null)
+				{
+					return wsdlLocation ;
+				}
 			}
-			else
-			{
-				throw new RuntimeException("unrecognized internal endpoint: " + end_name);
-			}
+			throw new IllegalStateException("unrecognized internal endpoint: " + end_name);
 		}
 		
 	}



More information about the jboss-svn-commits mailing list