[jboss-svn-commits] JBL Code SVN: r34462 - in labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap: proxy and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Aug 2 10:24:13 EDT 2010


Author: mageshbk at jboss.com
Date: 2010-08-02 10:24:12 -0400 (Mon, 02 Aug 2010)
New Revision: 34462

Added:
   labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSDLLocatorImpl.java
Modified:
   labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/CXFSOAPProcessor.java
   labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java
   labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java
Log:
[JBESB-3414] - Added JBossWSDLLocater implementation that resolves imported wsdls.

Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/CXFSOAPProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/CXFSOAPProcessor.java	2010-08-02 13:23:00 UTC (rev 34461)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/CXFSOAPProcessor.java	2010-08-02 14:24:12 UTC (rev 34462)
@@ -88,7 +88,7 @@
             {
                 String wsdlLocation = WebServiceUtils.getWsdlLocation(endpoint);
                 URL wsdlUrl = new URL(wsdlLocation);
-                Definition definition = new JBossWSDLReader().readWSDL(wsdlLocation);
+                Definition definition = WebServiceUtils.readWSDL(wsdlUrl);
                 javax.wsdl.Service wsdlService = (javax.wsdl.Service)definition.getServices().values().iterator().next();
                 QName serviceName = wsdlService.getQName();
                 port = (Port)wsdlService.getPorts().values().iterator().next();

Added: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSDLLocatorImpl.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSDLLocatorImpl.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSDLLocatorImpl.java	2010-08-02 14:24:12 UTC (rev 34462)
@@ -0,0 +1,164 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.soa.esb.actions.soap;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.wsdl.xml.WSDLLocator;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.core.utils.ResourceURL;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+
+/**
+ * A WSDLLocator that can handle wsdl imports
+ *
+ * @author <a href="mailto:mageshbk at jboss.com">Magesh Kumar B</a>
+ */
+public class JBossWSDLLocatorImpl implements WSDLLocator
+{
+   // provide logging
+   private static final Logger log = Logger.getLogger(JBossWSDLLocatorImpl.class);
+
+   private EntityResolver entityResolver;
+   private URL wsdlLocation;
+   private String latestImportURI;
+
+   public JBossWSDLLocatorImpl(EntityResolver entityResolver, URL wsdlLocation)
+   {
+      if (wsdlLocation == null)
+         throw new IllegalArgumentException("WSDL file argument cannot be null");
+
+      this.entityResolver = entityResolver;
+      this.wsdlLocation = wsdlLocation;
+   }
+
+   public InputSource getBaseInputSource()
+   {
+      log.trace("getBaseInputSource [wsdlUrl=" + wsdlLocation + "]");
+      try
+      {
+         InputStream inputStream = new ResourceURL(wsdlLocation).openStream();
+         if (inputStream == null)
+            throw new IllegalArgumentException("Cannot obtain wsdl from [" + wsdlLocation + "]");
+
+         return new InputSource(inputStream);
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException("Cannot access wsdl from [" + wsdlLocation + "], " + e.getMessage());
+      }
+   }
+
+   public String getBaseURI()
+   {
+      return wsdlLocation.toExternalForm();
+   }
+
+   public InputSource getImportInputSource(String parent, String resource)
+   {
+      log.trace("getImportInputSource [parent=" + parent + ",resource=" + resource + "]");
+
+      URL parentURL = null;
+      try
+      {
+         parentURL = new URL(parent);
+      }
+      catch (MalformedURLException e)
+      {
+         log.error("Not a valid URL: " + parent);
+         return null;
+      }
+
+      String wsdlImport = null;
+      String external = parentURL.toExternalForm();
+
+      // An external URL
+      if (resource.startsWith("http://") || resource.startsWith("https://"))
+      {
+         wsdlImport = resource;
+      }
+
+      // Absolute path
+      else if (resource.startsWith("/"))
+      {
+         String beforePath = external.substring(0, external.indexOf(parentURL.getPath()));
+         wsdlImport = beforePath + resource;
+      }
+
+      // A relative path
+      else
+      {
+         String parentDir = external.substring(0, external.lastIndexOf("/"));
+
+         // remove references to current dir
+         while (resource.startsWith("./"))
+            resource = resource.substring(2);
+
+         // remove references to parentdir
+         while (resource.startsWith("../"))
+         {
+            parentDir = parentDir.substring(0, parentDir.lastIndexOf("/"));
+            resource = resource.substring(3);
+         }
+
+         wsdlImport = parentDir + "/" + resource;
+      }
+
+      try
+      {
+         log.trace("Trying to resolve: " + wsdlImport);
+         InputSource inputSource = entityResolver.resolveEntity(wsdlImport, wsdlImport);
+         if (inputSource != null)
+         {
+            latestImportURI = wsdlImport;
+         }
+         else
+         {
+            throw new IllegalArgumentException("Cannot resolve imported resource: " + wsdlImport);
+         }
+
+         return inputSource;
+      }
+      catch (RuntimeException rte)
+      {
+         throw rte;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Cannot access imported wsdl [" + wsdlImport + "], " + e.getMessage());
+      }
+   }
+
+   public String getLatestImportURI()
+   {
+      return latestImportURI;
+   }
+
+   public void close()
+   {
+   }
+}

Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java	2010-08-02 13:23:00 UTC (rev 34461)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java	2010-08-02 14:24:12 UTC (rev 34462)
@@ -23,13 +23,17 @@
 
 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;
@@ -37,6 +41,7 @@
 import org.xml.sax.helpers.XMLReaderFactory;
 
 import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.ws.core.utils.JBossWSEntityResolver;
 import org.jboss.wsf.spi.SPIProvider;
 import org.jboss.wsf.spi.SPIProviderResolver;
 import org.jboss.wsf.spi.deployment.ArchiveDeployment;
@@ -127,4 +132,19 @@
         }
         return wsdlFile;
     }
+    
+
+    /**
+     * Parse and create wsdl4j Definition from a given WSDL URL.
+     *
+     * @param wsdlURL The URL to WSDL.
+     * @return If found, the wsdl4j Definition.
+     */
+    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;
+    }
 }
\ No newline at end of file

Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java	2010-08-02 13:23:00 UTC (rev 34461)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java	2010-08-02 14:24:12 UTC (rev 34462)
@@ -35,7 +35,6 @@
 import javax.wsdl.Operation;
 import javax.wsdl.Port;
 import javax.wsdl.Service;
-import javax.wsdl.WSDLException;
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.extensions.soap.SOAPAddress;
 import javax.wsdl.extensions.soap.SOAPOperation;
@@ -49,7 +48,7 @@
 import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;
 import org.jboss.soa.esb.actions.ActionLifecycleException;
 import org.jboss.soa.esb.actions.ActionProcessingException;
-import org.jboss.soa.esb.actions.soap.JBossWSDLReader;
+import org.jboss.soa.esb.actions.soap.WebServiceUtils;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.http.HttpRequest;
 import org.jboss.soa.esb.listeners.message.MessageDeliverException;
@@ -180,8 +179,7 @@
 		try
 		{
 			wsdl_loader.load(false);
-			URL wsdl_url = wsdl_loader.getURL();
-			wsdl_def = new JBossWSDLReader().readWSDL(wsdl_url.toString());
+			wsdl_def = WebServiceUtils.readWSDL(wsdl_loader.getURL());
 		}
 		catch (Exception ioe)
 		{



More information about the jboss-svn-commits mailing list