zoukankan      html  css  js  c++  java
  • Generate source code from wsdl

    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:

    • The class must have a public default constructor (with no arguments). This allows easy instantiation within editing and activation frameworks.
    • The class properties must be accessible using get, set, is (used for boolean properties instead of get), and other methods (so-called accessor methods and mutator methods) according to a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties. Setters can have one or more than one argument.
    • The class should be serializable. [This allows applications and frameworks to reliably save, store, and restore the bean's state in a manner independent of the VM and of the platform.]
    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>
  • 相关阅读:
    Py 获取 Flash Player amf 数据
    字符串出现表情符解决方案(超超超超超级猛)
    常用 JS HOOK 代码段
    atob方法替换方案
    conda httperror解决办法
    requests content-length进行校验了怎么办!
    tensoreflow安装教程(亲测可用)
    Python 程序运行时CPU和内存高解决思路
    Python免安装保姆级教程
    Xpath剔除不需要的标签节点
  • 原文地址:https://www.cnblogs.com/liwp_Stephen/p/3543868.html
Copyright © 2011-2022 走看看