[jboss-svn-commits] JBL Code SVN: r34648 - labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Aug 11 15:08:30 EDT 2010
Author: dward
Date: 2010-08-11 15:08:30 -0400 (Wed, 11 Aug 2010)
New Revision: 34648
Modified:
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-3455 ( https://jira.jboss.org/browse/JBESB-3455 ).
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-08-11 18:41:44 UTC (rev 34647)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/proxy/SOAPProxyWsdlLoader.java 2010-08-11 19:08:30 UTC (rev 34648)
@@ -23,18 +23,24 @@
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.Map.Entry;
import javax.management.JMException;
import javax.management.MBeanServer;
@@ -136,7 +142,9 @@
public File createTempFile(String prefix, String suffix) throws IOException
{
- return File.createTempFile( prefix + "-", suffix, getTempDir() );
+ File file = File.createTempFile( prefix + "-", suffix, getTempDir() );
+ cleanup_files.add(file);
+ return file;
}
public ContractInfo load(boolean rewriteLocation) throws IOException
@@ -146,9 +154,14 @@
String address = getAddress();
String protocol = URI.create(address).getScheme();
primary_file = createTempFile(protocol, ".wsdl");
- cleanup_files.add(primary_file);
getPuller().pull(address, primary_file);
- primary_file = filterFile(address, primary_file, ".wsdl", protocol);
+ Map<String,File> fileMap = new LinkedHashMap<String,File>();
+ fileMap.put(address, primary_file);
+ pullLocations(primary_file, address, protocol, fileMap);
+ for ( Entry<String,File> entry : fileMap.entrySet() )
+ {
+ editLocations(entry.getValue(), entry.getKey(), protocol, fileMap);
+ }
// populate the primary member variables (mimeType + data)
String mimeType = "text/xml";
String data = null;
@@ -171,46 +184,98 @@
return contract;
}
- private File filterFile(String url, File origFile, String suffix, String protocol) throws IOException
+ private void pullLocations(File file, String address, String protocol, Map<String,File> fileMap) throws IOException
{
- BufferedInputStream bis = null;
- Element wsdlElement;
+ InputStream is = null;
+ Element parentElement;
try
{
- bis = new BufferedInputStream( origFile.toURL().openStream() );
- wsdlElement = DOMUtils.parse(bis);
+ is = new BufferedInputStream( new FileInputStream(file) );
+ parentElement = DOMUtils.parse(is);
}
finally
{
- try { if (bis != null) bis.close(); } catch (Throwable t) {}
+ try { if (is != null) is.close(); } catch (Throwable t) {}
}
- if ( findRelative(url, wsdlElement, protocol) )
+ pullLocations(parentElement, address, protocol, fileMap);
+ }
+
+ private void pullLocations(Element parentElement, String address, String protocol, Map<String,File> fileMap) throws IOException
+ {
+ NodeList nlist = parentElement.getChildNodes();
+ for (int i = 0; i < nlist.getLength(); i++)
{
- File rewriteFile = createTempFile(protocol, suffix);
- cleanup_files.add(rewriteFile);
- BufferedOutputStream bos = null;
- try
+ Node childNode = nlist.item(i);
+ if (childNode.getNodeType() == Node.ELEMENT_NODE)
{
- bos = new BufferedOutputStream( new FileOutputStream(rewriteFile) );
- DOMWriter writer = new DOMWriter(bos);
- writer.setPrettyprint(true);
- writer.print(wsdlElement);
+ 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( address, locationAttr.getNodeValue() );
+ if ( !fileMap.containsKey(location) )
+ {
+ File locationFile = createTempFile(protocol, ".tmp");
+ getPuller().pull(location, locationFile);
+ fileMap.put(location, locationFile);
+ pullLocations(locationFile, location, protocol, fileMap);
+ }
+ }
+ }
+ pullLocations(childElement, address, protocol, fileMap);
}
- finally
+ }
+ }
+
+ private void editLocations(File file, String address, String protocol, Map<String,File> fileMap) throws IOException
+ {
+ InputStream is = null;
+ Element parentElement;
+ try
+ {
+ is = new BufferedInputStream( new FileInputStream(file) );
+ parentElement = DOMUtils.parse(is);
+ }
+ finally
+ {
+ try { if (is != null) is.close(); } catch (Throwable t) {}
+ }
+ if ( editLocations(parentElement, address, protocol, fileMap) )
+ {
+ OutputStream os1 = new BufferedOutputStream( new FileOutputStream(file) );
+ ByteArrayOutputStream os2 = new ByteArrayOutputStream();
+ for (OutputStream os : new OutputStream[]{os1, os2})
{
- try { if (bos != null) bos.close(); } catch (Throwable t) {}
+ try
+ {
+ DOMWriter writer = new DOMWriter(os);
+ writer.setPrettyprint(true);
+ writer.print(parentElement);
+ }
+ finally
+ {
+ try { if (os != null) os.close(); } catch (Throwable t) {}
+ }
}
- origFile.delete();
- cleanup_files.remove(origFile);
- origFile = rewriteFile;
+ contract.putResource( file.getName(), os2.toString("UTF-8") );
}
- return origFile;
+ else
+ {
+ contract.putResource( file.getName(), getPuller().pull(file) );
+ }
}
- private boolean findRelative(String url, Element wsdlElement, String protocol) throws IOException
+ private boolean editLocations(Element parentElement, String address, String protocol, Map<String,File> fileMap) throws IOException
{
boolean rewrite = false;
- NodeList nlist = wsdlElement.getChildNodes();
+ NodeList nlist = parentElement.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++)
{
Node childNode = nlist.item(i);
@@ -227,16 +292,11 @@
}
if (locationAttr != null)
{
- String location = fixRelative( url, locationAttr.getNodeValue() );
- File locationFile = createTempFile(protocol, ".tmp");
- cleanup_files.add(locationFile);
- getPuller().pull(location, locationFile);
- locationFile = filterFile(location, locationFile, ".tmp", protocol);
+ String location = fixRelative( address, locationAttr.getNodeValue() );
+ File locationFile = fileMap.get(location);
String locationFileName = locationFile.getName();
if (rewriteLocation)
{
- String locationResource = getPuller().pull(locationFile);
- contract.putResource(locationFileName, locationResource);
StringBuilder locationBuilder = new StringBuilder("@REQUEST_URL@?wsdl");
locationBuilder.append("&resource=").append(locationFileName);
if (serviceCat != null)
@@ -258,7 +318,7 @@
rewrite = true;
}
}
- if ( findRelative(url, childElement, protocol) )
+ if ( editLocations(childElement, address, protocol, fileMap) )
{
rewrite = true;
}
@@ -305,7 +365,7 @@
public URL getURL() throws MalformedURLException
{
- return primary_file.toURL();
+ return primary_file.toURI().toURL();
}
public void cleanup()
More information about the jboss-svn-commits
mailing list