You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/07/07 15:15:29 UTC
cvs commit: ws-axis/java/src/org/apache/axis/wsdl/toJava JavaServiceImplWriter.java
dims 2005/07/07 06:15:29
Modified: java/src/org/apache/axis/wsdl/symbolTable ServiceEntry.java
SymbolTable.java
java/src/org/apache/axis/wsdl/toJava
JavaServiceImplWriter.java
Added: java/src/org/apache/axis/wsdl/symbolTable BackslashUtil.java
Log:
Fix for AXIS-2088 - backslash in wsdl:service[@name] generates bad java
from Dennis Byrne
Revision Changes Path
1.5 +13 -0 ws-axis/java/src/org/apache/axis/wsdl/symbolTable/ServiceEntry.java
Index: ServiceEntry.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/ServiceEntry.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ServiceEntry.java 25 Feb 2004 14:02:51 -0000 1.4
+++ ServiceEntry.java 7 Jul 2005 13:15:28 -0000 1.5
@@ -25,6 +25,7 @@
/** Field service */
private Service service;
+ private String originalServiceName;
/**
* Construct a ServiceEntry from a WSDL4J Service object.
@@ -39,6 +40,18 @@
} // ctor
/**
+ *
+ * @param originalServiceName
+ *
+ */
+ public String getOriginalServiceName(){
+ return this.originalServiceName;
+ }
+ public void setOriginalServiceName(String originalName){
+ this.originalServiceName = originalName;
+ }
+
+ /**
* Get this entry's Service object.
*
* @return
1.124 +9 -4 ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SymbolTable.java
Index: SymbolTable.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/symbolTable/SymbolTable.java,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -r1.123 -r1.124
--- SymbolTable.java 30 Jun 2005 20:09:17 -0000 1.123
+++ SymbolTable.java 7 Jul 2005 13:15:28 -0000 1.124
@@ -3051,27 +3051,32 @@
* @param def
* @throws IOException
*/
- private void populateServices(Definition def) throws IOException {
+ private void populateServices(Definition def) throws IOException {
+ String originalName = null;
Iterator i = def.getServices().values().iterator();
while (i.hasNext()) {
Service service = (Service) i.next();
-
+ originalName = service.getQName().getLocalPart();
// do a bit of name validation
if ((service.getQName() == null)
|| (service.getQName().getLocalPart() == null)
|| service.getQName().getLocalPart().equals("")) {
throw new IOException(Messages.getMessage("BadServiceName00"));
}
-
+
+ // behave as though backslashes were never there
+ service.setQName(BackslashUtil.getQNameWithBackslashlessLocal(service.getQName()));
ServiceEntry sEntry = new ServiceEntry(service);
-
+ // we'll need this later when it is time print a backslash escaped service name
+ sEntry.setOriginalServiceName(originalName);
symbolTablePut(sEntry);
populatePorts(service.getPorts());
}
} // populateServices
+
/**
* populates the symbol table with port elements defined within a <service>
* element.
1.1 ws-axis/java/src/org/apache/axis/wsdl/symbolTable/BackslashUtil.java
Index: BackslashUtil.java
===================================================================
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.axis.wsdl.symbolTable;
import javax.xml.namespace.QName;
/**
* @author dbyrne
*
* this method exists because backslashes cannot be removed unless
*/
public class BackslashUtil implements java.io.Serializable {
public static QName getQNameWithBackslashlessLocal(QName suspectQName) {
String trustedString = null;
// get a wsdl:service[@name] that we can trust
trustedString = stripBackslashes(suspectQName.getLocalPart());
return getQNameWithDifferentLocal(suspectQName, trustedString);
}
public static QName getQNameWithBackslashedLocal(QName suspectQName) {
String trustedString = null;
// get a wsdl:service[@name] with safe backslashes
trustedString = applyBackslashes(suspectQName.getLocalPart());
return getQNameWithDifferentLocal(suspectQName, trustedString);
}
public static QName getQNameWithDifferentLocal(QName qName, String localName) {
QName trustedQName = null;
// recreate the QName, only w/ a local name we can trust.
trustedQName = new QName(qName.getNamespaceURI(), localName, qName.getPrefix());
return trustedQName;
}
public static String applyBackslashes(String string) {
return transformBackslashes(string, false);
}
public static String stripBackslashes(String string) {
return transformBackslashes(string, true);
}
public static String transformBackslashes(String string, boolean delete) {
byte[] suspectBytes = null;
StringBuffer stringBuffer = null;
suspectBytes = string.getBytes();
stringBuffer = new StringBuffer(string);
for (int b = suspectBytes.length - 1; b >= 0; b--) {
if (suspectBytes[b] == 92) {
if(delete){
stringBuffer.delete(b, b + 1);
}else{
stringBuffer.insert(b, "\\");
}
}
}
return stringBuffer.toString();
}
}
1.46 +13 -3 ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaServiceImplWriter.java
Index: JavaServiceImplWriter.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaServiceImplWriter.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- JavaServiceImplWriter.java 25 May 2005 07:30:58 -0000 1.45
+++ JavaServiceImplWriter.java 7 Jul 2005 13:15:29 -0000 1.46
@@ -22,6 +22,7 @@
import org.apache.axis.wsdl.symbolTable.PortTypeEntry;
import org.apache.axis.wsdl.symbolTable.ServiceEntry;
import org.apache.axis.wsdl.symbolTable.SymbolTable;
+import org.apache.axis.wsdl.symbolTable.BackslashUtil;
import javax.wsdl.Binding;
import javax.wsdl.Port;
@@ -547,13 +548,22 @@
* @param pw
* @param qname
*/
- protected void writeGetServiceName(PrintWriter pw, QName qname) {
+ protected void writeGetServiceName(PrintWriter pw, QName qname) {
+ String originalServiceName = null;
+ QName qNameWithDifferentLocal = null;
+ QName qNameWithBackslashedLocal = null;
+
+ originalServiceName = sEntry.getOriginalServiceName();
+ qNameWithDifferentLocal = BackslashUtil.getQNameWithDifferentLocal(qname, originalServiceName);
+ qNameWithBackslashedLocal = BackslashUtil.getQNameWithBackslashedLocal(qNameWithDifferentLocal);
+
pw.println(" public javax.xml.namespace.QName getServiceName() {");
- pw.println(" return " + Utils.getNewQName(qname) + ";");
+
+ pw.println(" return " + Utils.getNewQName(qNameWithBackslashedLocal) + ";");
pw.println(" }");
pw.println();
- } // writeGetServiceName
+ } // writeGetServiceName
/**
* Write the getPorts method.