复杂的自定义对象作为服务器中的SOAP Web服务的参数不起作用

时间:2016-01-13 19:54:23

标签: web-services soap jaxb axis2

我必须编写一个SOAP Web服务,我正在使用JAXB和Axis2。 webservice方法将稍微复杂的Object作为输入参数,然后它应该处理并返回另一个复杂的自定义Object。

现在参数中预期的对象结构是:

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(name = "softwarepart", propOrder = {
    "approved",
    "desc",
    "users",
    "associatedchipparts"
})
@XmlRootElement(name = "softwarepart")
public class Softwarepart {

    public boolean approved;
    public String desc;    
    public Softwarepart.Users users;
    public Softwarepart.Associatedchipparts associatedchipparts;

    public boolean isApproved() {
        return approved;
    }

    public void setApproved(boolean value) {
        this.approved = value;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String value) {
        this.desc = value;
    }

    public Softwarepart.Users getUsers() {      
        return this.users;
    }


    public void setUsers(Softwarepart.Users usrs) {
        this.users = usrs;
    }


    public Softwarepart.Associatedchipparts getAssociatedchipparts() {

        return this.associatedchipparts;
    }


    public void setAssociatedchipparts(
            Softwarepart.Associatedchipparts chipparts) {
        this.associatedchipparts = chipparts;
    }

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "associatedchipparts", propOrder = {
        "associatedchippart"
    })
    @XmlRootElement(name = "associatedchipparts")
    public static class Associatedchipparts {

        public List<Softwarepart.Associatedchipparts.Associatedchippart> associatedchippart;

        public List<Softwarepart.Associatedchipparts.Associatedchippart> getAssociatedchippart() {
            if (associatedchippart == null) {
                associatedchippart = new ArrayList<Softwarepart.Associatedchipparts.Associatedchippart>();
            }
            return this.associatedchippart;
        }

        @XmlAccessorType(XmlAccessType.FIELD)
        @XmlType(name = "associatedchippart", propOrder = {
            "partNumber",
            "mpn"
        })
        @XmlRootElement(name = "associatedchippart")
        public static class Associatedchippart {

            public String partNumber;
            public String mpn;

            public String getPartNumber() {
                return partNumber;
            }

            public void setPartNumber(String value) {
                this.partNumber = value;
            }

            public String getMpn() {
                return mpn;
            }

            public void setMpn(String value) {
                this.mpn = value;
            }

        }

    }

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "users", propOrder = {
        "user"
    })
    @XmlRootElement(name = "users")
    public static class Users {

        public List<Softwarepart.Users.User> user;

        public List<Softwarepart.Users.User> getUser() {
            if (user == null) {
                user = new ArrayList<Softwarepart.Users.User>();
            }
            return this.user;
        }

        @XmlAccessorType(XmlAccessType.FIELD)
        @XmlType(name = "user", propOrder = {
            "email"
        })
        @XmlRootElement(name = "user")
        public static class User {
            public String email;

            public String getEmail() {
                return email;
            }

            public void setEmail(String value) {
                this.email = value;
            }

        }

    }

}

网络服务中的代码如下所示:

public class SoftwarePartCreator {
    public String createSoftwarePart(SoftwarePartsList softwareList,String postURL) {
        return "created";
    }

wsdl生成的结构如下:

<wsdl:types>
    <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://packagename/xsd">
        <xs:complexType name="SoftwarePartsList">
        <xs:sequence>
            <xs:element minOccurs="0" name="softwarePart" nillable="true" type="xs:anyType"/>
            <xs:element minOccurs="0" name="status" nillable="true" type="xs:string"/>
        </xs:sequence>
        </xs:complexType>
    </xs:schema>
    <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" xmlns:ax24="http://packagename/xsd">
        <xs:element name="createSoftwarePart">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="softwareList" nillable="true" type="ax23:SoftwarePartsList"/>
                <xs:element minOccurs="0" name="postURL" nillable="true" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
        </xs:element>
        <xs:element name="createSoftwarePartResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
        </xs:element>
    </xs:schema>
</wsdl:types>

现在,在WSDL中,不处理嵌套模式,而xs:anyType将来临,而不是SoftwarePart。类似地,即使我使用了JAXB注释,许多内部类的定义也没有出现在模式中。

任何人都可以帮我这个吗?

1 个答案:

答案 0 :(得分:1)

通过将所有ArrayList更改为JAXB pojos中的simple array []来解决此问题。 希望这有助于某人。