dims 2003/01/03 11:54:41
Modified: java/test/wsdl/session session.wsdl
java/src/org/apache/axis/wsdl/toJava Utils.java
Log:
Fix for 15685 - namespaces are truncated in conversion to java packages
from [EMAIL PROTECTED] (Eric Friedman)
Revision Changes Path
1.2 +3 -3 xml-axis/java/test/wsdl/session/session.wsdl
Index: session.wsdl
===================================================================
RCS file: /home/cvs/xml-axis/java/test/wsdl/session/session.wsdl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- session.wsdl 5 Sep 2002 20:05:47 -0000 1.1
+++ session.wsdl 3 Jan 2003 19:54:41 -0000 1.2
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<wsdl:definitions
targetNamespace="http://session.wsdl.test:8080/axis/services/SessionTest"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://session.wsdl.test:8080/axis/services/SessionTest"
xmlns:intf="http://session.wsdl.test:8080/axis/services/SessionTest"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+<wsdl:definitions targetNamespace="http://session.wsdl.test:8080/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://session.wsdl.test:8080/"
xmlns:intf="http://session.wsdl.test:8080/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="doSomethingResponse">
<wsdl:part name="doSomethingReturn" type="xsd:boolean"/>
</wsdl:message>
@@ -16,10 +16,10 @@
<wsdl:operation name="doSomething">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="doSomethingRequest">
- <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://session.wsdl.test:8080/axis/services/SessionTest" use="encoded"/>
+ <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://session.wsdl.test:8080/" use="encoded"/>
</wsdl:input>
<wsdl:output name="doSomethingResponse">
- <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://session.wsdl.test:8080/axis/services/SessionTest" use="encoded"/>
+ <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://session.wsdl.test:8080/" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
1.66 +41 -14 xml-axis/java/src/org/apache/axis/wsdl/toJava/Utils.java
Index: Utils.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/Utils.java,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- Utils.java 30 Dec 2002 14:36:46 -0000 1.65
+++ Utils.java 3 Jan 2003 19:54:41 -0000 1.66
@@ -395,10 +395,13 @@
public static String makePackageName(String namespace)
{
String hostname = null;
+ String path = "";
// get the target namespace of the document
try {
- hostname = new URL(namespace).getHost();
+ URL u = new URL(namespace);
+ hostname = u.getHost();
+ path = u.getPath();
}
catch (MalformedURLException e) {
if (namespace.indexOf(":") > -1) {
@@ -418,6 +421,12 @@
//convert illegal java identifier
hostname = hostname.replace('-', '_');
+ path = path.replace('-', '_');
+
+ // chomp off last forward slash in path, if necessary
+ if (path.length() > 0 && path.charAt(path.length() - 1) == '/') {
+ path = path.substring(0, path.length() - 1);
+ }
// tokenize the hostname and reverse it
StringTokenizer st = new StringTokenizer( hostname, "." );
@@ -425,22 +434,40 @@
for(int i = 0; i < words.length; ++i)
words[i] = st.nextToken();
- StringBuffer sb = new StringBuffer(80);
+ StringBuffer sb = new StringBuffer(namespace.length());
for(int i = words.length-1; i >= 0; --i) {
- String word = words[i];
- if (JavaUtils.isJavaKeyword(word)) {
- word = JavaUtils.makeNonJavaKeyword(word);
- }
- // seperate with dot
- if( i != words.length-1 )
- sb.append('.');
-
- // convert digits to underscores
- if( Character.isDigit(word.charAt(0)) )
- sb.append('_');
- sb.append( word );
+ addWordToPackageBuffer(sb, words[i], (i == words.length -1));
+ }
+
+ // tokenize the path
+ StringTokenizer st2 = new StringTokenizer( path, "/" );
+ while (st2.hasMoreTokens()) {
+ addWordToPackageBuffer(sb, st2.nextToken(), false);
}
return sb.toString();
+ }
+
+ /**
+ * Massage <tt>word</tt> into a form suitable for use in a Java package name.
+ * Append it to the target string buffer with a <tt>.</tt> delimiter iff
+ * <tt>word</tt> is not the first word in the package name.
+ *
+ * @param sb the buffer to append to
+ * @param word the word to append
+ * @param firstWord a flag indicating whether this is the first word
+ */
+ private static void addWordToPackageBuffer(StringBuffer sb, String word,
boolean firstWord) {
+ if (JavaUtils.isJavaKeyword(word)) {
+ word = JavaUtils.makeNonJavaKeyword(word);
+ }
+ // separate with dot after the first word
+ if( ! firstWord )
+ sb.append('.');
+
+ // convert digits to underscores
+ if( Character.isDigit(word.charAt(0)) )
+ sb.append('_');
+ sb.append( word );
}
/**