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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Sep 30 18:36:09 EDT 2009


Author: dward
Date: 2009-09-30 18:36:09 -0400 (Wed, 30 Sep 2009)
New Revision: 29518

Added:
   labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AuthBASICWsdlContractPublisher.java
   labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java
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/SOAPProxyWsdlContractPublisher.java
   labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/WiseWsdlContractPublisher.java
Log:
Fix for https://jira.jboss.org/jira/browse/JBESB-2855


Added: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AuthBASICWsdlContractPublisher.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AuthBASICWsdlContractPublisher.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AuthBASICWsdlContractPublisher.java	2009-09-30 22:36:09 UTC (rev 29518)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.soa.esb.actions.soap;
+
+import java.util.Properties;
+
+/**
+ * AuthBASIC WSDL contract publisher.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class AuthBASICWsdlContractPublisher extends WsdlContractPublisher {
+
+    public Properties getHttpClientProperties() {
+        Properties httpClientProperties = (Properties) getActionProperties().clone();
+        String configurators = httpClientProperties.getProperty("configurators");
+
+        // Handle potential Http BASIC Auth....
+        if(httpClientProperties.containsKey("username")) {
+            httpClientProperties.setProperty("auth-username", httpClientProperties.getProperty("username"));
+            if(httpClientProperties.containsKey("password")) {
+                httpClientProperties.setProperty("auth-password", httpClientProperties.getProperty("password"));
+            }
+
+            // Only auto-configure the configurators if they're not already configured.
+            // If they're configured in any way at all, we don't modify that.  If they're
+            // not configured and a username/password is supplied, we assume BASIC Auth...
+            if(configurators == null) {
+                configurators = "AuthBASIC";
+            }
+        }
+
+        if(configurators != null) {
+            httpClientProperties.setProperty("configurators", configurators);
+        }
+
+        return httpClientProperties;
+    }
+
+}


Property changes on: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AuthBASICWsdlContractPublisher.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

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	2009-09-30 19:03:31 UTC (rev 29517)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxy.java	2009-09-30 22:36:09 UTC (rev 29518)
@@ -20,10 +20,8 @@
 package org.jboss.soa.esb.actions.soap.proxy;
 
 import java.io.ByteArrayInputStream;
-import java.io.File;
 import java.io.IOException;
 import java.io.StringReader;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
@@ -47,7 +45,6 @@
 import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
 import org.jboss.ws.metadata.wsdl.WSDLEndpoint;
 import org.jboss.ws.metadata.wsdl.WSDLService;
-import org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
@@ -68,7 +65,15 @@
  * <ol>
  * <li><b>wsdl</b> (required): The original wsdl {@link URL url} whose WS endpoint will get re-written and exposed as new wsdl from
  * the ESB.  Depending upon the &lt;definitions&gt;&lt;service&gt;&lt;port&gt;&lt;soap:address location attribute's protocol (for
- * example "http"), a protocol-specific {@link SOAPProxyTransport} implementation is used.</li>
+ * example "http"), a protocol-specific {@link SOAPProxyTransport} implementation is used.  The value can reference a location based on
+ * five different schemes: http, https, file, classpath or internal (JBossWS).  Here are some examples:<br/>
+ * <ul>
+ * <li>http://localhost:8080/Quickstart_webservice_proxy_basic/HelloWorldWS?wsdl</li>
+ * <li>https://localhost:8443/webservice_proxy_security/HelloWorldWS?wsdl</li>
+ * <li>file:///tmp/HelloWorldWS.wsdl</li>
+ * <li>classpath://META-INF/HelloWorldWS.wsdl</li>
+ * <li>internal://jboss.ws:context=Quickstart_webservice_proxy_basic_ws,endpoint=HelloWorldWS</li>
+ * </ul></li>
  * <li><b>wsdlTransform</b> (optional): A &lt;smooks-resource-list&gt; xml config file allowing for flexible wsdl transformation.</li>
  * <li><b>*</b> (optional): Any of the HttpRouter properties can be applied, if the wsdl specifies an http transport.</li>
  * <li><b>endpointUrl</b> (optional): Example of an HttpRouter property, but useful when domain name matching is important for SSL certs.</li>
@@ -111,21 +116,7 @@
 	public SOAPProxy(ConfigTree config) throws ConfigurationException
 	{
 		payloadProxy = new MessagePayloadProxy(config);
-		WSDLDefinitionsFactory wsdl_def_fact = WSDLDefinitionsFactory.newInstance();
-		File wsdl_file = SOAPProxyWsdlContractPublisher.createLocalWsdlFile(config);
-		WSDLDefinitions wsdl_def;
-		try
-		{
-			wsdl_def = wsdl_def_fact.parse( wsdl_file.toURL() );
-		}
-		catch (MalformedURLException mue)
-		{
-			throw new ConfigurationException(mue);
-		}
-		finally
-		{
-			wsdl_file.delete();
-		}
+		WSDLDefinitions wsdl_def = SOAPProxyWsdlLoader.loadDefinitions(config);
 		for ( WSDLBinding wsdl_bind : wsdl_def.getBindings() )
 		{
 			for ( WSDLBindingOperation wsdl_bind_oper : wsdl_bind.getOperations() )

Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java	2009-09-30 19:03:31 UTC (rev 29517)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java	2009-09-30 22:36:09 UTC (rev 29518)
@@ -19,74 +19,11 @@
  */
 package org.jboss.soa.esb.actions.soap.proxy;
 
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Properties;
+import org.jboss.soa.esb.actions.soap.AuthBASICWsdlContractPublisher;
 
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.actions.soap.wise.WiseWsdlContractPublisher;
-import org.jboss.soa.esb.helpers.ConfigTree;
-
 /**
- * Provides convenience method to load the remote wsdl respecting all configured HttpClient properties.
+ * SOAPProxy WSDL contract publisher.
  * 
  * @author dward at jboss.org
  */
-public class SOAPProxyWsdlContractPublisher extends WiseWsdlContractPublisher
-{
-	
-	static File createLocalWsdlFile(ConfigTree config) throws ConfigurationException
-	{
-		File wsdl_file;
-		Writer writer = null;
-		try
-		{
-			WsdlLoader loader = new WsdlLoader(config);
-			String wsdl_attr = config.getRequiredAttribute("wsdl");
-			String wsdl_data = loader.getWsdl(wsdl_attr);
-			wsdl_file = File.createTempFile(SOAPProxyWsdlContractPublisher.class.getName() + "-", ".wsdl");
-			writer = new BufferedWriter( new FileWriter(wsdl_file) );
-			writer.write(wsdl_data);
-			writer.flush();
-		}
-		catch (IOException ioe)
-		{
-			throw new ConfigurationException(ioe);
-		}
-		finally
-		{
-			try { if (writer != null) writer.close(); } catch (Throwable t) {}
-		}
-		return wsdl_file;
-	}
-	
-	private static class WsdlLoader extends SOAPProxyWsdlContractPublisher
-	{
-		
-		private ConfigTree config;
-		
-		private WsdlLoader(ConfigTree config)
-		{
-			this.config = config;
-		}
-		
-		public Properties getActionProperties()
-		{
-			Properties props = new Properties();
-			for ( String key : config.getAttributeNames() )
-			{
-				String value = config.getAttribute(key);
-				if (value != null)
-				{
-					props.setProperty(key, value);
-				}
-			}
-			return props;
-		}
-		
-	}
-
-}
+public class SOAPProxyWsdlContractPublisher extends AuthBASICWsdlContractPublisher {}

Added: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java	2009-09-30 22:36:09 UTC (rev 29518)
@@ -0,0 +1,260 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., 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.
+ * 
+ * (C) 2005-2009
+ */
+package org.jboss.soa.esb.actions.soap.proxy;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+import javax.management.ObjectName;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
+import org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.management.EndpointRegistry;
+import org.jboss.wsf.spi.management.EndpointRegistryFactory;
+
+/**
+ * SOAPProxy WSDL loader.
+ * 
+ * @author dward at jboss.org
+ */
+public abstract class SOAPProxyWsdlLoader
+{
+	
+	public abstract URL getWsdlURL() throws MalformedURLException;
+	
+	public void cleanup() {}
+	
+	public File createTempFile() throws IOException
+	{
+		return File.createTempFile(SOAPProxyWsdlLoader.class.getName() + "-", ".wsdl");
+	}
+	
+	public static WSDLDefinitions loadDefinitions(ConfigTree config) throws ConfigurationException
+	{
+		String wsdl_location = config.getRequiredAttribute("wsdl");
+		SOAPProxyWsdlLoader wsdl_loader;
+		if ( wsdl_location.startsWith("http://") || wsdl_location.startsWith("https://") )
+		{
+			wsdl_loader = new HttpSOAPProxyWsdlLoader(wsdl_location, config);
+		}
+		else if ( wsdl_location.startsWith("file://") )
+		{
+			wsdl_loader = new FileSOAPProxyWsdlLoader( wsdl_location.substring(7, wsdl_location.length()) );
+		}
+		else if ( wsdl_location.startsWith("classpath://") )
+		{
+			wsdl_loader = new ClasspathSOAPProxyWsdlLoader( wsdl_location.substring(12, wsdl_location.length()) );
+		}
+		else if ( wsdl_location.startsWith("internal://") )
+		{
+			wsdl_loader = new InternalSOAPProxyWsdlLoader( wsdl_location.substring(11, wsdl_location.length()) );
+		}
+		else
+		{
+			throw new ConfigurationException("unrecognized wsdl location: " + wsdl_location);
+		}
+		WSDLDefinitions wsdl_definitions;
+		try
+		{
+			URL wsdl_url = wsdl_loader.getWsdlURL();
+			wsdl_definitions = WSDLDefinitionsFactory.newInstance().parse(wsdl_url);
+		}
+		catch (MalformedURLException mue)
+		{
+			throw new ConfigurationException(mue);
+		}
+		finally
+		{
+			wsdl_loader.cleanup();
+		}
+		return wsdl_definitions;
+	}
+	
+	private static class HttpSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
+	{
+		
+		private File wsdl_temp_file;
+		
+		public HttpSOAPProxyWsdlLoader(String url, final ConfigTree config) throws ConfigurationException
+		{
+			// re-using the HTTPClient and AuthBASIC stuff...
+			SOAPProxyWsdlContractPublisher wsdl_helper = new SOAPProxyWsdlContractPublisher()
+			{
+				@Override
+				public Properties getActionProperties()
+				{
+					Properties props = new Properties();
+					for ( String key : config.getAttributeNames() )
+					{
+						String value = config.getAttribute(key);
+						if (value != null)
+						{
+							props.setProperty(key, value);
+						}
+					}
+					return props;
+				}
+			};
+			BufferedInputStream bis = null;
+			BufferedOutputStream bos = null;
+			try
+			{
+				String wsdl_string = wsdl_helper.getWsdl(url);
+				bis = new BufferedInputStream( new ByteArrayInputStream(wsdl_string.getBytes()) );
+				wsdl_temp_file = createTempFile();
+				bos = new BufferedOutputStream( new FileOutputStream(wsdl_temp_file) );
+				byte[] buf = new byte[1024];
+				int read = 0;
+				while ( (read = bis.read(buf)) != -1 )
+				{
+					bos.write(buf, 0, read);
+				}
+				bos.flush();
+			}
+			catch (IOException ioe)
+			{
+				throw new ConfigurationException(ioe);
+			}
+			finally
+			{	
+				try { if (bos != null) bos.close(); } catch (Throwable t) {}
+				try { if (bis != null) bis.close(); } catch (Throwable t) {}
+			}
+		}
+		
+		public URL getWsdlURL() throws MalformedURLException
+		{
+			return wsdl_temp_file.toURL();
+		}
+		
+		@Override
+		public void cleanup()
+		{
+			wsdl_temp_file.delete();
+		}
+		
+	}
+	
+	private static class FileSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
+	{
+		
+		private File wsdl_orig_file;
+		
+		public FileSOAPProxyWsdlLoader(String path) throws ConfigurationException
+		{
+			wsdl_orig_file = new File(path);
+		}
+		
+		public URL getWsdlURL() throws MalformedURLException
+		{
+			return wsdl_orig_file.toURL();
+		}
+		
+	}
+	
+	private static class ClasspathSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
+	{
+		
+		private URL wsdl_url;
+		
+		public ClasspathSOAPProxyWsdlLoader(String resource) throws ConfigurationException
+		{
+			wsdl_url = ClassUtil.getResource(resource, SOAPProxyWsdlLoader.class);
+		}
+		
+		public URL getWsdlURL() throws MalformedURLException
+		{
+			return wsdl_url;
+		}
+		
+	}
+	
+	private static class InternalSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
+	{
+		
+		private File wsdl_temp_file;
+		
+		public InternalSOAPProxyWsdlLoader(String end_name) throws ConfigurationException
+		{
+			SPIProvider spi_prov = SPIProviderResolver.getInstance().getProvider();
+			EndpointRegistryFactory end_reg_fact = spi_prov.getSPI(EndpointRegistryFactory.class);
+			EndpointRegistry end_reg = end_reg_fact.getEndpointRegistry();
+			Endpoint end = null;
+			for ( ObjectName obj_name : end_reg.getEndpoints() )
+			{
+				//if ( end_name.equals(obj_name.getKeyProperty(Endpoint.SEPID_PROPERTY_ENDPOINT)) )
+				if ( obj_name.toString().equals(end_name) )
+				{
+					end = end_reg.getEndpoint(obj_name);
+					break;
+				}
+			}
+			if (end != null)
+			{
+				BufferedOutputStream bos = null;
+				try
+				{
+					wsdl_temp_file = createTempFile();
+					bos = new BufferedOutputStream( new FileOutputStream(wsdl_temp_file) );
+					end.getRequestHandler().handleWSDLRequest(end, bos, null);
+					bos.flush();
+				}
+				catch (IOException ioe)
+				{
+					throw new ConfigurationException(ioe);
+				}
+				finally
+				{
+					try { if (bos != null) bos.close(); } catch (Throwable t) {}
+				}
+			}
+			else
+			{
+				throw new ConfigurationException("unrecognized internal endpoint: " + end_name);
+			}
+		}
+		
+		public URL getWsdlURL() throws MalformedURLException
+		{
+			return wsdl_temp_file.toURL();
+		}
+		
+		@Override
+		public void cleanup()
+		{
+			wsdl_temp_file.delete();
+		}
+		
+	}
+
+}


Property changes on: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/WiseWsdlContractPublisher.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/WiseWsdlContractPublisher.java	2009-09-30 19:03:31 UTC (rev 29517)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/WiseWsdlContractPublisher.java	2009-09-30 22:36:09 UTC (rev 29518)
@@ -19,41 +19,11 @@
  */
 package org.jboss.soa.esb.actions.soap.wise;
 
-import java.util.Properties;
+import org.jboss.soa.esb.actions.soap.AuthBASICWsdlContractPublisher;
 
-import org.jboss.soa.esb.actions.soap.WsdlContractPublisher;
-
 /**
- * WSDL contract publisher.
+ * Wise WSDL contract publisher.
  *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
-public class WiseWsdlContractPublisher extends WsdlContractPublisher {
-
-    public Properties getHttpClientProperties() {
-        Properties httpClientProperties = (Properties) getActionProperties().clone();
-        String configurators = httpClientProperties.getProperty("configurators");
-
-        // Handle potential Http BASIC Auth....
-        if(httpClientProperties.containsKey("username")) {
-            httpClientProperties.setProperty("auth-username", httpClientProperties.getProperty("username"));
-            if(httpClientProperties.containsKey("password")) {
-                httpClientProperties.setProperty("auth-password", httpClientProperties.getProperty("password"));
-            }
-
-            // Only auto-configure the configurators if they're not already configured.
-            // If they're configured in any way at all, we don't modify that.  If they're
-            // not configured and a username/password is supplied, we assume BASIC Auth...
-            if(configurators == null) {
-                configurators = "AuthBASIC";
-            }
-        }
-
-        if(configurators != null) {
-            httpClientProperties.setProperty("configurators", configurators);
-        }
-
-        return httpClientProperties;
-    }
-
-}
+public class WiseWsdlContractPublisher extends AuthBASICWsdlContractPublisher {}



More information about the jboss-svn-commits mailing list