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>
  • 相关阅读:
    Dora.Interception,为.NET Core度身打造的AOP框架 [3]:多样化拦截器应用方式
    Dora.Interception,为.NET Core度身打造的AOP框架 [2]:以约定的方式定义拦截器
    Dora.Interception,为.NET Core度身打造的AOP框架 [1]:更加简练的编程体验
    TechEmpower最新一轮的性能测试出炉,ASP.NET Core依旧表现不俗
    [文章汇总]ASP.NET Core框架揭秘[最近更新:2018/10/31]
    依赖注入[8]: .NET Core DI框架[服务消费]
    依赖注入[7]: .NET Core DI框架[服务注册]
    依赖注入[6]: .NET Core DI框架[编程体验]
    依赖注入[5]: 创建一个简易版的DI框架[下篇]
    依赖注入[4]: 创建一个简易版的DI框架[上篇]
  • 原文地址:https://www.cnblogs.com/liwp_Stephen/p/3543868.html
Copyright © 2011-2022 走看看