2016-01-13 57 views
1

我必須編寫SOAP Web服務,並且我正在使用JAXB和Axis2。 webservice方法會將一些複雜的Object作爲輸入參數,然後處理並返回另一個複雜的自定義對象。複雜的自定義對象作爲參數SOAP服務器中的web服務器不起作用

現在這是在參數預期我的對象的結構是:

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; 
      } 

     } 

    } 

} 

中的代碼web服務是象下面這樣:

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即將instea d的SoftwarePart。類似的,很多內部類的定義並不在模式中,即使我已經使用了JAXB註釋。

任何人都可以幫助我呢?

回答

1

這是通過在JAXB pojos中將所有ArrayList更改爲簡單數組[]來解決的。 希望這可以幫助別人。

相關問題