[jboss-svn-commits] JBL Code SVN: r31129 - in labs/jbossesb/branches/JBESB_4_7_CP/product: rosetta/src/org/jboss/soa/esb/listeners/gateway/http and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jan 18 23:27:54 EST 2010


Author: dward
Date: 2010-01-18 23:27:53 -0500 (Mon, 18 Jan 2010)
New Revision: 31129

Added:
   labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/proxy/
   labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyUnitTest.java
Modified:
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractInfo.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpGatewayServlet.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/publish/ContractInfoUnitTest.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java
Log:
Fix for JBESB-3076 ( https://jira.jboss.org/jira/browse/JBESB-3076 ).


Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractInfo.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractInfo.java	2010-01-19 03:09:25 UTC (rev 31128)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/internal/soa/esb/publish/ContractInfo.java	2010-01-19 04:27:53 UTC (rev 31129)
@@ -19,6 +19,10 @@
  */
 package org.jboss.internal.soa.esb.publish;
 
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.jboss.internal.soa.esb.assertion.AssertArgument;
 
 /**
@@ -30,8 +34,14 @@
  */
 public class ContractInfo {
 
-    private String mimeType;
-    private String data;
+    private String mimeType = null;
+    private String data = null;
+    private Map<String,File> fileResources = new HashMap<String,File>();
+    
+    /**
+     * Public constructor.
+     */
+    public ContractInfo() {}
 
     /**
      * Public constructor.
@@ -39,11 +49,10 @@
      * @param data Contract data.
      */
     public ContractInfo(String mimeType, String data) {
-        AssertArgument.isNotNullAndNotEmpty(mimeType, "mimeType");
-        AssertArgument.isNotNullAndNotEmpty(data, "data");
-
-        this.mimeType = mimeType;
-        this.data = data;
+		AssertArgument.isNotNullAndNotEmpty(mimeType, "mimeType");
+		AssertArgument.isNotNullAndNotEmpty(data, "data");
+    	setMimeType(mimeType);
+    	setData(data);
     }
 
     /**
@@ -53,6 +62,14 @@
     public String getMimeType() {
         return mimeType;
     }
+    
+    /**
+     * Set the contract data MIME type.
+     * @param mimeType Contract data mime type.
+     */
+    public void setMimeType(String mimeType) {
+    	this.mimeType = mimeType;
+    }
 
     /**
      * Get the contract data.
@@ -61,4 +78,31 @@
     public String getData() {
         return data;
     }
+    
+    /**
+     * Set the contract data.
+     * @param data Contract data.
+     */
+    public void setData(String data) {
+    	this.data = data;
+    }
+    
+    /**
+     * Gets a file resource.
+     * @param the file resource key
+     * @return the file resource value
+     */
+    public File getFileResource(String key) {
+    	return fileResources.get(key);
+    }
+    
+    /**
+     * Puts a file resource.
+     * @param key the file resource key
+     * @param value the file resource value
+     */
+    public void putFileResource(String key, File value) {
+    	fileResources.put(key, value);
+    }
+    
 }

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpGatewayServlet.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpGatewayServlet.java	2010-01-19 03:09:25 UTC (rev 31128)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpGatewayServlet.java	2010-01-19 04:27:53 UTC (rev 31129)
@@ -19,9 +19,13 @@
  */
 package org.jboss.soa.esb.listeners.gateway.http;
 
+import java.io.BufferedReader;
 import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Reader;
 import java.io.Writer;
 import java.util.Enumeration;
 import java.util.Map;
@@ -99,9 +103,8 @@
         
         try {
         	ContractProvider contractProvider = ContractProviderLifecycleResource.getContractProvider(serviceCategory, serviceName);
-        	String endpointAddress = config.getInitParameter(Servlet.ENDPOINT_ADDRESS);
         	if (contractProvider != null) {
-        		contract = contractProvider.provideContract(endpointAddress);
+        		contract = contractProvider.provideContract(config.getInitParameter(Servlet.ENDPOINT_ADDRESS));
         	}
         } catch (LifecycleResourceException lre) {
         	throw new ServletException(lre);
@@ -153,15 +156,9 @@
 
     protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
     	// if it's a wsdl request, serve up the contract then short-circuit
-    	if ("wsdl".equalsIgnoreCase(req.getQueryString())) {
-    		resp.setCharacterEncoding("UTF-8");
-    		String mimeType = (contract != null ? contract.getMimeType() : "text/xml");
-    		resp.setContentType(mimeType);
-    		String data = (contract != null ? contract.getData() : "<definitions/>");
-    		resp.setContentLength(data.length());
-    		Writer writer = new BufferedWriter(resp.getWriter());
-    		writer.write(data);
-    		writer.flush();
+    	String query = req.getQueryString();
+    	if (query != null && query.toLowerCase().startsWith("wsdl")) {
+    		handleWsdlRequest(req, resp);
     		return;
     	}
     	
@@ -274,4 +271,38 @@
             }
         }
     }
+    
+    private void handleWsdlRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+		resp.setCharacterEncoding("UTF-8");
+		String mimeType = (contract != null ? contract.getMimeType() : "text/xml");
+		resp.setContentType(mimeType);
+		String data = null;
+		String resource = req.getParameter("resource");
+		if (resource == null) {
+			data = (contract != null ? contract.getData() : "<definitions/>");
+		} else {
+			if (contract != null) {
+				File file = contract.getFileResource(resource);
+				if (file != null && file.exists() && file.canRead()) {
+					Reader reader = null;
+					try {
+						reader = new BufferedReader(new FileReader(file));
+						data = StreamUtils.readReader(reader);
+					} finally {
+						try { if (reader != null) reader.close(); } catch (Throwable t) {}
+					}
+				}
+			}
+		}
+		if (data != null) {
+			data = data.replaceAll( "@REQUEST_URL@", req.getRequestURL().toString() );
+		} else {
+			data = "";
+		}
+		resp.setContentLength(data.length());
+		Writer writer = new BufferedWriter(resp.getWriter());
+		writer.write(data);
+		writer.flush();
+    }
+    
 }

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/publish/ContractInfoUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/publish/ContractInfoUnitTest.java	2010-01-19 03:09:25 UTC (rev 31128)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/publish/ContractInfoUnitTest.java	2010-01-19 04:27:53 UTC (rev 31129)
@@ -25,7 +25,7 @@
 import junit.framework.TestCase;
 
 /**
- * @author
+ * ContractInfo unit test.
  */
 public class ContractInfoUnitTest extends TestCase {
 
@@ -35,8 +35,8 @@
         assertContractorArgChecksOK("a", null);
         assertContractorArgChecksOK("a", " ");
 
-        ContractInfo contractInfo = new ContractInfo("mime", "data");
-        assertEquals("mime", contractInfo.getMimeType());
+        ContractInfo contractInfo = new ContractInfo("mimeType", "data");
+        assertEquals("mimeType", contractInfo.getMimeType());
         assertEquals("data", contractInfo.getData());
     }
 

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java	2010-01-19 03:09:25 UTC (rev 31128)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractWsdlContractPublisher.java	2010-01-19 04:27:53 UTC (rev 31129)
@@ -19,34 +19,35 @@
  */
 package org.jboss.soa.esb.actions.soap;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.net.URI;
+import java.util.Properties;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.log4j.Logger;
 import org.jboss.internal.soa.esb.publish.ActionContractPublisher;
 import org.jboss.internal.soa.esb.publish.ContractInfo;
 import org.jboss.internal.soa.esb.publish.ServletContractPublisher;
 import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.http.HttpClientFactory;
 import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
 import org.jboss.soa.esb.listeners.config.Action;
 import org.jboss.soa.esb.smooks.resource.SmooksResource;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.http.HttpClientFactory;
-import org.jboss.soa.esb.addressing.EPR;
+import org.milyn.Smooks;
+import org.milyn.container.ExecutionContext;
 import org.xml.sax.SAXException;
-import org.milyn.container.ExecutionContext;
-import org.milyn.Smooks;
-import org.apache.log4j.Logger;
 
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.StringReader;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.Properties;
-import java.lang.reflect.Proxy;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
 /**
  * Abstract WSDL contract publisher.
  * 
@@ -130,28 +131,39 @@
 
     public ContractInfo getContractInfo(EPR epr, HttpServletRequest servletRequest) {
         String wsdlAddress = getWsdlAddress();
-
-        if(wsdlAddress != null) {
+        if (wsdlAddress != null) {
             String targetServiceCat = servletRequest.getParameter("serviceCat");
             String targetServiceName = servletRequest.getParameter("serviceName");
             String targetProtocol = servletRequest.getParameter("protocol");
-
+            ContractInfo contract;
             try {
                 // Generate the WSDL...
-                String wsdl = getWsdl(wsdlAddress);
-
-                wsdl = updateWsdl(wsdl, epr, targetServiceCat, targetServiceName, targetProtocol);
-
-                return new ContractInfo("text/xml", wsdl);
+                contract = getContractInfo(wsdlAddress);
+                String data = contract.getData();
+                if (data != null) {
+                	contract.setData( updateWsdl(data, epr, targetServiceCat, targetServiceName, targetProtocol) );
+                } else {
+                	if ( wsdlAddress.startsWith("classpath://") ) {
+                    	contract.setMimeType("text/plain");
+                    	contract.setData("'" + wsdlAddress + "' unavailable: WSDL address URI format unsupported by contract application unless 'http-gateway' is employed.");
+                	} else {
+                		throw new Exception("null Contract data");
+                	}
+                }
             } catch (Exception e) {
-                logger.error("Failed to load WSDL contract information from WS Endpoint '" + wsdlAddress + "'.", e);
-                return new ContractInfo("text/plain", "Unavailable: " + e.getMessage());
+                logger.error("Failed to load WSDL contract information from address '" + wsdlAddress + "'.", e);
+            	contract = new ContractInfo("text/plain", "'" + wsdlAddress + "' unavailable: " + e.getMessage() );
             }
+            return contract;
         } else {
-            logger.warn("Requested contract info for unknown webservice endpoint'.");
+            logger.warn("Requested contract info for unknown webservice endpoint.");
             return null;
         }
     }
+    
+    public ContractInfo getContractInfo(String wsdlAddress) throws IOException {
+    	return new ContractInfo( "text/xml", getWsdl(wsdlAddress) );
+    }
 
     /**
      * Get the WSDL.

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java	2010-01-19 03:09:25 UTC (rev 31128)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlContractPublisher.java	2010-01-19 04:27:53 UTC (rev 31129)
@@ -23,6 +23,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
+import java.net.URL;
 import java.util.Properties;
 
 import org.jboss.internal.soa.esb.publish.ContractInfo;
@@ -42,9 +43,8 @@
 {
 	
 	@Override
-	public String getWsdl(String wsdlAddress) throws IOException
+	public ContractInfo getContractInfo(String wsdlAddress) throws IOException
 	{
-		String wsdl;
 		Properties properties = getActionProperties();
 		ConfigTree config = new ConfigTree("config");
 		for ( Object key : properties.keySet() )
@@ -53,19 +53,28 @@
 			String value = properties.getProperty(name);
 			config.setAttribute(name, value);
 		}
-		SOAPProxyWsdlLoader loader = SOAPProxyWsdlLoader.newLoader(config);
+		ContractInfo contract = new ContractInfo();
+		SOAPProxyWsdlLoader loader = SOAPProxyWsdlLoader.newLoader(config, contract);
+		String mimeType = "text/xml";
+		String data = null;
 		InputStream is = null;
 		try
 		{
-			is = new BufferedInputStream( loader.getURL().openStream() );
-			wsdl = StreamUtils.readStreamString(is, "UTF-8");
+			URL url = loader.getURL();
+			if (url != null)
+			{
+				is = new BufferedInputStream( url.openStream() );
+				data = StreamUtils.readStreamString(is, "UTF-8");
+			}
 		}
 		finally
 		{
 			try { if (is != null) is.close(); } catch (Throwable t) {}
 			loader.cleanup();
 		}
-		return wsdl;
+		contract.setMimeType(mimeType);
+		contract.setData(data);
+		return contract;
 	}
 	
 	public void setContractProperties(Properties contractProperties)

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java	2010-01-19 03:09:25 UTC (rev 31128)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java	2010-01-19 04:27:53 UTC (rev 31129)
@@ -27,17 +27,22 @@
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
+import org.jboss.internal.soa.esb.publish.ContractInfo;
 import org.jboss.mx.util.MBeanServerLocator;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.actions.soap.AuthBASICWsdlContractPublisher;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.util.ClassUtil;
+import org.jboss.util.xml.DOMUtils;
+import org.jboss.util.xml.DOMWriter;
 import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
 import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
 import org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory;
@@ -46,6 +51,10 @@
 import org.jboss.wsf.spi.deployment.Endpoint;
 import org.jboss.wsf.spi.management.EndpointRegistry;
 import org.jboss.wsf.spi.management.EndpointRegistryFactory;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 /**
  * SOAPProxy WSDL loader.
@@ -71,21 +80,24 @@
 						tempDir = (File)mbeanServer.getAttribute(new ObjectName("jboss.system:type=ServerConfig"), "ServerTempDir");
 					}
 					catch (JMException ignored) {}
+					String tempName = SOAPProxyWsdlLoader.class.getName();
 					if ( tempDir == null || !tempDir.exists() )
 					{
-						File tempFile = File.createTempFile(SOAPProxyWsdlLoader.class.getName() + "-", ".tmp");
+						File tempFile = File.createTempFile(tempName + "-", ".tmp");
 						tempDir = tempFile.getParentFile();
 						tempFile.delete();
 					}
+					tempDir = new File(tempDir, tempName);
+					tempDir.mkdirs();
 				}
 			}
 		}
 		return tempDir;
 	}
 	
-	public File createTempFile() throws IOException
+	public File createTempFile(String prefix, String suffix) throws IOException
 	{
-		return File.createTempFile( SOAPProxyWsdlLoader.class.getName() + "-", ".wsdl", getTempDir() );
+		return File.createTempFile( prefix + "-", suffix, getTempDir() );
 	}
 	
 	public abstract URL getURL() throws MalformedURLException;
@@ -94,7 +106,7 @@
 	
 	public static WSDLDefinitions loadDefinitions(ConfigTree config) throws IOException
 	{
-		SOAPProxyWsdlLoader loader = newLoader(config);
+		SOAPProxyWsdlLoader loader = newLoader(config, null);
 		WSDLDefinitions definitions;
 		try
 		{
@@ -108,7 +120,7 @@
 		return definitions;
 	}
 	
-	public static SOAPProxyWsdlLoader newLoader(ConfigTree config) throws IOException
+	public static SOAPProxyWsdlLoader newLoader(ConfigTree config, ContractInfo contract) throws IOException
 	{
 		String address;
 		try
@@ -121,7 +133,7 @@
 		}
 		if ( address.startsWith("http://") || address.startsWith("https://") )
 		{
-			return new HttpSOAPProxyWsdlLoader(address, config);
+			return new HttpSOAPProxyWsdlLoader(address, config, contract);
 		}
 		else if ( address.startsWith("file://") )
 		{
@@ -138,15 +150,18 @@
 		throw new IOException("unrecognized wsdl address: " + address);
 	}
 	
-	private static class HttpSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
+	static class HttpSOAPProxyWsdlLoader extends SOAPProxyWsdlLoader
 	{
 		
+		private AuthBASICWsdlContractPublisher file_puller;
+		private ContractInfo contract;
 		private File wsdl_temp_file;
+		private List<File> cleanup_files = new ArrayList<File>();
 		
-		public HttpSOAPProxyWsdlLoader(String url, final ConfigTree config) throws IOException
+		public HttpSOAPProxyWsdlLoader(String url, final ConfigTree config, ContractInfo contract) throws IOException
 		{
 			// re-using the HTTPClient and AuthBASIC stuff...
-			AuthBASICWsdlContractPublisher wsdl_helper = new AuthBASICWsdlContractPublisher()
+			file_puller = new AuthBASICWsdlContractPublisher()
 			{
 				@Override
 				public Properties getActionProperties()
@@ -163,14 +178,22 @@
 					return props;
 				}
 			};
+			this.contract = contract;
+			wsdl_temp_file = createTempFile("http", ".wsdl");
+			cleanup_files.add(wsdl_temp_file);
+			pullFile(url, wsdl_temp_file);
+			wsdl_temp_file = filterFile(url, wsdl_temp_file, ".wsdl");
+		}
+			
+		private void pullFile(String url, File file) throws IOException
+		{
 			BufferedInputStream bis = null;
 			BufferedOutputStream bos = null;
 			try
 			{
-				String wsdl_string = wsdl_helper.getWsdl(url);
+				String wsdl_string = file_puller.getWsdl(url);
 				bis = new BufferedInputStream( new ByteArrayInputStream(wsdl_string.getBytes()) );
-				wsdl_temp_file = createTempFile();
-				bos = new BufferedOutputStream( new FileOutputStream(wsdl_temp_file) );
+				bos = new BufferedOutputStream( new FileOutputStream(file) );
 				byte[] buf = new byte[1024];
 				int read = 0;
 				while ( (read = bis.read(buf)) != -1 )
@@ -186,6 +209,130 @@
 			}
 		}
 		
+		// JBESB-3076
+		private File filterFile(String url, File origFile, String suffix) throws IOException
+		{
+			BufferedInputStream bis = null;
+			Element wsdlElement;
+			try
+			{
+				bis = new BufferedInputStream( origFile.toURL().openStream() );
+				wsdlElement = DOMUtils.parse(bis);
+			}
+			finally
+			{
+				try { if (bis != null) bis.close(); } catch (Throwable t) {}
+			}
+			if ( findRelative(url, wsdlElement) )
+			{
+				File rewriteFile = createTempFile("http", suffix);
+				cleanup_files.add(rewriteFile);
+				BufferedOutputStream bos = null;
+				try
+				{
+					bos = new BufferedOutputStream( new FileOutputStream(rewriteFile) );
+					DOMWriter writer = new DOMWriter(bos);
+					writer.setPrettyprint(true);
+					writer.print(wsdlElement);
+				}
+				finally
+				{
+					try { if (bos != null) bos.close(); } catch (Throwable t) {}
+				}
+				origFile.delete();
+				cleanup_files.remove(origFile);
+				origFile = rewriteFile;
+			}
+			return origFile;
+		}
+		
+		private boolean findRelative(String url, Element wsdlElement) throws IOException
+		{
+			boolean rewrite = false;
+			NodeList nlist = wsdlElement.getChildNodes();
+			for (int i = 0; i < nlist.getLength(); i++)
+			{
+				Node childNode = nlist.item(i);
+				if (childNode.getNodeType() == Node.ELEMENT_NODE)
+				{
+					Element childElement = (Element)childNode;
+					String nodeName = childElement.getLocalName();
+					if ( "import".equals(nodeName) || "include".equals(nodeName) )
+					{
+						Attr locationAttr = childElement.getAttributeNode("schemaLocation");
+						if (locationAttr == null)
+						{
+							locationAttr = childElement.getAttributeNode("location");
+						}
+						if (locationAttr != null)
+						{
+							String location = fixRelative( url, locationAttr.getNodeValue() );
+							int locationSuffixPos = location.lastIndexOf(".");
+							String locationSuffix = (locationSuffixPos > -1 ? location.substring(locationSuffixPos, location.length()) : ".tmp");
+							locationSuffix = locationSuffix.trim();
+							if (locationSuffix.length() == 0)
+							{
+								locationSuffix = ".tmp";
+							}
+							File locationFile = createTempFile("http", locationSuffix);
+							cleanup_files.add(locationFile);
+							pullFile(location, locationFile);
+							locationFile = filterFile(location, locationFile, locationSuffix);
+							String locationFileName = locationFile.getName();
+							if (contract != null)
+							{
+								contract.putFileResource(locationFileName, locationFile);
+								locationAttr.setNodeValue("@REQUEST_URL@?wsdl&resource=" + locationFileName);
+							}
+							else
+							{
+								locationAttr.setNodeValue(locationFileName);		
+							}
+							rewrite = true;
+						}
+					}
+					if ( findRelative(url, childElement) )
+					{
+						rewrite = true;
+					}
+				}
+			}
+			return rewrite;
+		}
+		
+		static String fixRelative(String wsdl_url, String location)
+		{
+			location = location.replaceAll("/./", "/");
+			if ( !location.startsWith("http://") && !location.startsWith("https://") )
+			{
+				String wsdl_host = wsdl_url.substring( 0, wsdl_url.indexOf("/", wsdl_url.indexOf("://")+3) );
+				while ( location.startsWith("./") )
+				{
+					location = location.substring( 2, location.length() );
+				}
+				if (location.startsWith("/"))
+				{
+					location = wsdl_host + location;
+				}
+				else
+				{
+					int count = 0;
+					while ( location.startsWith("../") )
+					{
+						location = location.substring( 3, location.length() );
+						count++;
+					}
+					String newLocation = wsdl_url.substring( 0, wsdl_url.lastIndexOf("/") );
+					for (int c = 0; c < count; c++)
+					{
+						newLocation = newLocation.substring( 0, newLocation.lastIndexOf("/") );
+					}
+					location = newLocation + "/" + location;
+				}
+			}
+			return location;
+		}
+		
 		public URL getURL() throws MalformedURLException
 		{
 			return wsdl_temp_file.toURL();
@@ -194,7 +341,17 @@
 		@Override
 		public void cleanup()
 		{
-			wsdl_temp_file.delete();
+			for (File file : cleanup_files)
+			{
+				if (contract == null)
+				{
+					file.delete();
+				}
+				else
+				{
+					file.deleteOnExit();
+				}
+			}
 		}
 		
 	}

Added: labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyUnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyUnitTest.java	2010-01-19 04:27:53 UTC (rev 31129)
@@ -0,0 +1,65 @@
+/*
+ * 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-2010
+ */
+package org.jboss.soa.esb.actions.soap.proxy;
+
+import static org.junit.Assert.assertEquals;
+import junit.framework.JUnit4TestAdapter;
+
+import org.junit.Test;
+
+/**
+ * SOAPProxy unit test.
+ * 
+ * @author dward at jboss.org
+ */
+public class SOAPProxyUnitTest
+{
+	
+	@Test
+	public void testHttp_fixRelative()
+	{
+		String[][] relativeHttpResources = new String[][] {
+				new String[] {"http://foo.com/services/MyService.wsdl", "/schemas/MySchema.xsd", "http://foo.com/schemas/MySchema.xsd"},
+				new String[] {"http://foo.com/services/MyService.wsdl", "../schemas/MySchema.xsd", "http://foo.com/schemas/MySchema.xsd"},
+				new String[] {"http://foo.com/services/MyService.wsdl", "schemas/MySchema.xsd", "http://foo.com/services/schemas/MySchema.xsd"},
+				new String[] {"http://foo.com/services/MyService.wsdl", "/MySchema.xsd", "http://foo.com/MySchema.xsd"},
+				new String[] {"http://foo.com/services/old/MyService.wsdl", "../new/MySchema.xsd", "http://foo.com/services/new/MySchema.xsd"},
+				new String[] {"http://foo.com/services/MyService.wsdl", "/test/MySchema.xsd", "http://foo.com/test/MySchema.xsd"},
+				new String[] {"http://foo.com/services/old/MyService.wsdl", "../../test/MySchema.xsd", "http://foo.com/test/MySchema.xsd"},
+				new String[] {"http://foo.com/services/MyService.wsdl", "./MySchema.xsd", "http://foo.com/services/MySchema.xsd"},
+				new String[] {"http://foo.com/services/old/MyService.wsdl", "./../test/MySchema.xsd", "http://foo.com/services/test/MySchema.xsd"},
+				new String[] {"http://foo.com/services/old/MyService.wsdl", ".././test/MySchema.xsd", "http://foo.com/services/test/MySchema.xsd"},
+				new String[] {"http://foo.com/services/old/MyService.wsdl", ".././../test/MySchema.xsd", "http://foo.com/test/MySchema.xsd"},
+				new String[] {"http://foo.com/services/old/MyService.wsdl", ".././../test/./MySchema.xsd", "http://foo.com/test/MySchema.xsd"},
+		};
+		for (String[] r : relativeHttpResources)
+		{
+			String actual = SOAPProxyWsdlLoader.HttpSOAPProxyWsdlLoader.fixRelative(r[0], r[1]);
+			String expected = r[2];
+			assertEquals(expected, actual);
+		}
+	}
+	
+    public static junit.framework.Test suite()
+    {
+        return new JUnit4TestAdapter(SOAPProxyUnitTest.class);
+    }
+
+}


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



More information about the jboss-svn-commits mailing list