WSDL Import: get better names for WSDLs whose URI looks like "myWs?WSDL"
diff --git a/plugins/org.eclipse.bpel.common.wsdl/src/org/eclipse/bpel/common/wsdl/helpers/UriAndUrlHelper.java b/plugins/org.eclipse.bpel.common.wsdl/src/org/eclipse/bpel/common/wsdl/helpers/UriAndUrlHelper.java
index 39f5fd6..36592b7 100644
--- a/plugins/org.eclipse.bpel.common.wsdl/src/org/eclipse/bpel/common/wsdl/helpers/UriAndUrlHelper.java
+++ b/plugins/org.eclipse.bpel.common.wsdl/src/org/eclipse/bpel/common/wsdl/helpers/UriAndUrlHelper.java
@@ -79,10 +79,14 @@
/**
* Extracts the file name from a URI or URL given as a string.
+ * <p>
+ * If the file name contains invalid characters, such as a question mark,
+ * this methods modifies the file name so that is is a valid file name.
+ * </p>
* @param uriAsString the URI or URL given as a string
* @return the file name (never null)
*/
- public static String extractFileName( String uriAsString ) {
+ public static String extractOrGenerateFileName( String uriAsString ) {
String fileName = uriAsString;
if( fileName.endsWith( "/" ))
@@ -93,14 +97,27 @@
fileName = fileName.substring( ++ index );
// Handle cases like "jsp?value="
- index = fileName.lastIndexOf( '?' );
- if( index != -1 )
- fileName = fileName.substring( ++ index );
+ if( fileName.toLowerCase().endsWith( "?wsdl" )) {
+ fileName = fileName.substring( 0, fileName.length() - 5 ) + ".wsdl";
+
+ } else {
+ index = fileName.lastIndexOf( '?' );
+ if( index != -1 )
+ fileName = fileName.substring( ++ index );
+ }
// Handle empty values
if( fileName.trim().length() == 0 )
fileName = "importedFile__" + new Date().getTime();
+ // Replace invalid characters
+ index = fileName.lastIndexOf( '.' );
+ if( index != -1 ) {
+ String ext = fileName.substring( index );
+ String fwe = fileName.substring( 0, index );
+ fileName = fwe.replaceAll( "[^-0-9a-zA-Z_]", "-" ) + ext;
+ }
+
return fileName;
}
diff --git a/plugins/org.eclipse.bpel.common.wsdl/src/org/eclipse/bpel/common/wsdl/importhelpers/WsdlImportHelper.java b/plugins/org.eclipse.bpel.common.wsdl/src/org/eclipse/bpel/common/wsdl/importhelpers/WsdlImportHelper.java
index 8dc1558..807056e 100644
--- a/plugins/org.eclipse.bpel.common.wsdl/src/org/eclipse/bpel/common/wsdl/importhelpers/WsdlImportHelper.java
+++ b/plugins/org.eclipse.bpel.common.wsdl/src/org/eclipse/bpel/common/wsdl/importhelpers/WsdlImportHelper.java
@@ -102,12 +102,12 @@
// Get the real relative file path
String relativeFilePath = entry.getValue().getRelativePathToTargetDirectory();
if( relativeFilePath.length() == 0 )
- relativeFilePath = UriAndUrlHelper.extractFileName( entry.getKey());
+ relativeFilePath = UriAndUrlHelper.extractOrGenerateFileName( entry.getKey());
// Imported files which are above the target directory will be put inside a specific directory
IPath path = rootPath.append( relativeFilePath );
if( ! rootPath.isPrefixOf( path ))
- relativeFilePath = RELOCATED_DIRECTORY + "/" + UriAndUrlHelper.extractFileName( entry.getKey());
+ relativeFilePath = RELOCATED_DIRECTORY + "/" + UriAndUrlHelper.extractOrGenerateFileName( entry.getKey());
// Prevent conflicts with existing files and files to be written
File targetFile;
diff --git a/tests/org.eclipse.bpel.common.wsdl.tests/src/org/eclipse/bpel/common/wsdl/importhelpers/WsdlImportHelperTest.java b/tests/org.eclipse.bpel.common.wsdl.tests/src/org/eclipse/bpel/common/wsdl/importhelpers/WsdlImportHelperTest.java
index 6dcd5c0..f1c5d3e 100644
--- a/tests/org.eclipse.bpel.common.wsdl.tests/src/org/eclipse/bpel/common/wsdl/importhelpers/WsdlImportHelperTest.java
+++ b/tests/org.eclipse.bpel.common.wsdl.tests/src/org/eclipse/bpel/common/wsdl/importhelpers/WsdlImportHelperTest.java
@@ -46,7 +46,12 @@
Assert.assertEquals( map.size(), 1 );
Assert.assertEquals( tmpDir.listFiles().length, 1 );
- testWsdlParsing( map.values().iterator().next(), 1 );
+
+ File f = map.values().iterator().next();
+ Assert.assertNotNull( f );
+ Assert.assertEquals( f.getName(), "tuxDroid.wsdl" );
+
+ testWsdlParsing( f, 1 );
} finally {
deleteFilesRecursively( tmpDir );
@@ -70,14 +75,23 @@
Map<String,File> map = new WsdlImportHelper().importWsdlOrXsdAndDependencies( tmpDir, url.toString());
Assert.assertEquals( map.size(), 1 );
- testWsdlParsing( map.values().iterator().next(), 1 );
+ File f = map.values().iterator().next();
+ Assert.assertNotNull( f );
+ Assert.assertEquals( f.getName(), "tuxDroid.wsdl" );
+
+ testWsdlParsing( f, 1 );
// Second import: should be renamed
map = new WsdlImportHelper().importWsdlOrXsdAndDependencies( tmpDir, url.toString());
Assert.assertEquals( map.size(), 1 );
Assert.assertEquals( tmpDir.listFiles().length, 2 );
- testWsdlParsing( map.values().iterator().next(), 1 );
+
+ f = map.values().iterator().next();
+ Assert.assertNotNull( f );
+ Assert.assertNotSame( f.getName(), "tuxDroid.wsdl" );
+
+ testWsdlParsing( f, 1 );
} finally {
deleteFilesRecursively( tmpDir );
@@ -102,6 +116,10 @@
Assert.assertEquals( map.size(), 1 );
Assert.assertEquals( tmpDir.listFiles().length, 1 );
+ File f = map.values().iterator().next();
+ Assert.assertNotNull( f );
+ Assert.assertEquals( f.getName(), "testwsdl20.wsdl" );
+
} finally {
deleteFilesRecursively( tmpDir );
Assert.assertFalse( tmpDir.exists());
@@ -308,6 +326,8 @@
File f = map.get( url.toString());
Assert.assertNotNull( f );
+ Assert.assertEquals( f.getName(), "ToConcrete.wsdl" );
+
testWsdlParsing( f, 2 );
} finally {
@@ -339,6 +359,8 @@
File f = map.get( url.toString());
Assert.assertNotNull( f );
+ Assert.assertEquals( f.getName(), "ToConcrete.wsdl" );
+
testWsdlParsing( f, 2 );
} finally {
@@ -370,6 +392,37 @@
File f = map.get( url.toString());
Assert.assertNotNull( f );
+ Assert.assertEquals( f.getName(), "GetQuantityAndSendOrder.wsdl" );
+
+ testWsdlParsing( f, 1 );
+
+ } finally {
+ deleteFilesRecursively( tmpDir );
+ Assert.assertFalse( tmpDir.exists());
+ }
+ }
+
+
+ /**
+ * Tests a WSDL 1.1 on a remote server (renaming test).
+ * @throws Exception
+ */
+ @Test
+ public void testWsdlImport13() throws Exception {
+
+ File tmpDir = new File( System.getProperty( "java.io.tmpdir" ), UUID.randomUUID().toString());
+ Assert.assertTrue( tmpDir.mkdir());
+ try {
+ URL url = new URL( "http://footballpool.dataaccess.eu/data/info.wso?WSDL" );
+ Map<String,File> map = new WsdlImportHelper().importWsdlOrXsdAndDependencies( tmpDir, url.toString());
+
+ Assert.assertEquals( map.size(), 1 );
+ Assert.assertEquals( tmpDir.listFiles().length, 1 );
+
+ File f = map.get( url.toString());
+ Assert.assertNotNull( f );
+ Assert.assertEquals( f.getName(), "info-wso.wsdl" );
+
testWsdlParsing( f, 1 );
} finally {