Yesterday, one of Automation QA find that generate source code from WSDL failed, and let me to find the problem.
One of them is there are two methods with similar name, just as “taksSnapshot”, and another is “TakeSnapshot”, in java, these two method is OK, but when generate source code with wsimport, it will generate class with the method name, and change the first name to upper case, so the two methods will generate two same class as TakeSnapshot, so it will report class already in use error.
Another problem is in one of the class that web service used has two fields, one of them is (Monitor monitor), another is (boolean isMonitor), and, their get set methods are :
getMonitor(), setMonitor(Monitor monitor); isMonitor(), setMonitor(boolean monitor)
When generate source code with wsimport with this method, it will report same field already exists.
In order to fix this, we need to change one of the field name.
When we write Java code, we need to pay attention Java Bean’s conventions.
The following is JavaBean conventions from wiki:
In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behaviour. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans.
The required conventions are as follows:
package player; public class PersonBean implements java.io.Serializable { /** * Property <code>name</code> (note capitalization) readable/writable. */ private String name = null; private boolean deceased = false; /** No-arg constructor (takes no arguments). */ public PersonBean() { } /** * Getter for property <code>name</code> */ public String getName() { return name; } /** * Setter for property <code>name</code>. * @param value */ public void setName(final String value) { name = value; } /** * Getter for property "deceased" * Different syntax for a boolean field (is vs. get) */ public boolean isDeceased() { return deceased; } /** * Setter for property <code>deceased</code>. * @param value */ public void setDeceased(final boolean value) { deceased = value; } }
TestPersonBean.java
:
import player.PersonBean; /** * Class <code>TestPersonBean</code>. */ public class TestPersonBean { /** * Tester method <code>main</code> for class <code>PersonBean</code>. * @param ARGS */ public static void main(String[] args) { PersonBean person = new PersonBean(); person.setName("Bob"); person.setDeceased(false); // Output: "Bob [alive]" System.out.print(person.getName()); System.out.println(person.isDeceased() ? " [deceased]" : " [alive]"); } }
testPersonBean.jsp
;
<% // Use of PersonBean in a JSP. %> <jsp:useBean id="person" class="player.PersonBean" scope="page"/> <jsp:setProperty name="person" property="*"/> <html> <body> Name: <jsp:getProperty name="person" property="name"/><br/> Deceased? <jsp:getProperty name="person" property="deceased"/><br/> <br/> <form name="beanTest" method="POST" action="testPersonBean.jsp"> Enter a name: <input type="text" name="name" size="50"><br/> Choose an option: <select name="deceased"> <option value="false">Alive</option> <option value="true">Dead</option> </select> <input type="submit" value="Test the Bean"> </form> </body> </html>
Generate source code from wsdl
原文:http://www.cnblogs.com/liwp_Stephen/p/3543868.html