我正在接收来自某些遗留代码的SOAP请求,并使用来自遗留代码使用的同一WSDL中的JAX-WS生成的对象处理该请求,但我得到了一个Unmarshalling错误:处理请求时发生意外的元素错误。解组错误:使用遗留WSDL传统请求中的意外元素
的WSDL部分用于此请求如下:(请注意,“模式”已经取代了所有我们的WSDL的实际模式位置)
<xsd:complexType name="Administrate">
<xsd:sequence>
<xsd:element name="AdminOperation" type="typens:AdminOperation" maxOccurs="unbounded" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Administrate" type="typens:Administrate"/>
<xsd:complexType name="AdministrateResponse">
<xsd:sequence>
<xsd:element name="Status" type="typens:SoapResponseStatus"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="AdministrateResponse" type="typens:AdministrateResponse"/>
<xsd:complexType name="AdminOperation">
<xsd:sequence>
<xsd:choice>
<xsd:element name="Transaction" type="typens:Transaction" minOccurs="0"/>
<xsd:element name="CreateUser" type="typens:CreateUser" minOccurs="0"/>
<xsd:element name="DeleteUser" type="typens:DeleteUser" minOccurs="0"/>
<xsd:element name="UpdateUser" type="typens:UpdateUser" minOccurs="0"/>
<xsd:element name="CreateGroup" type="typens:CreateGroup" minOccurs="0"/>
<xsd:element name="DeleteGroup" type="typens:DeleteGroup" minOccurs="0"/>
<xsd:element name="UpdateGroup" type="typens:UpdateGroup" minOccurs="0"/>
<xsd:element name="CreateChannel" type="typens:CreateChannel" minOccurs="0"/>
<xsd:element name="DeleteChannel" type="typens:DeleteChannel" minOccurs="0"/>
<xsd:element name="UpdateChannel" type="typens:UpdateChannel" minOccurs="0"/>
<xsd:element name="CreateRole" type="typens:CreateRole" minOccurs="0"/>
<xsd:element name="DeleteRole" type="typens:DeleteRole" minOccurs="0"/>
<xsd:element name="UpdateRole" type="typens:UpdateRole" minOccurs="0"/>
<xsd:element name="CreateFileType" type="typens:CreateFileType" minOccurs="0"/>
<xsd:element name="DeleteFileType" type="typens:DeleteFileType" minOccurs="0"/>
<xsd:element name="UpdateFileType" type="typens:UpdateFileType" minOccurs="0"/>
<xsd:element name="CreateFolder" type="typens:CreateFolder" minOccurs="0"/>
<xsd:element name="DeleteFile" type="typens:DeleteFile" minOccurs="0"/>
<xsd:element name="MoveFile" type="typens:MoveFile" minOccurs="0"/>
<xsd:element name="CopyFile" type="typens:CopyFile" minOccurs="0"/>
<xsd:element name="UpdateFile" type="typens:UpdateFile" minOccurs="0"/>
<xsd:element name="DeleteJob" type="typens:DeleteJob" minOccurs="0"/>
<xsd:element name="DeleteJobNotices" type="typens:DeleteJobNotices" minOccurs="0"/>
<xsd:element name="UpdateJobSchedule" type="typens:UpdateJobSchedule" minOccurs="0"/>
<xsd:element name="UpdateVolumeProperties" type="typens:UpdateVolumeProperties" minOccurs="0"/>
<xsd:element name="UpdateOpenSecurityCache" type="typens:UpdateOpenSecurityCache" minOccurs="0"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
和发送的请求:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns="schema">
<SOAP-ENV:Header>
<AuthId>7</AuthId>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<Administrate>
<UpdateFile>
<SetPermissions>
<Permission SOAP-ENC:arrayType="Permission[1]">
<UserName>username</UserName>
<AccessRight>rights</AccessRight>
</Permission>
</SetPermissions>
<NameList>
<String>folder1</String>
<String>folder1/folder2</String>
<String>folder1/folder2/file.ext</String>
</NameList>
</UpdateFile>
</Administrate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但我从我的代码中得到以下错误:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: unexpected element
(uri:"schema", local:"UpdateFile"). Expected elements
are <{schema}AdminOperation> </faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
管理JAX-WS生成的对象只是包含具有吸气剂AdminOperations的ArrayList,
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Administrate", propOrder = {
"adminOperation"
})
public class Administrate {
@XmlElement(name = "AdminOperation")
protected List<AdminOperation> adminOperation;
/**
* Gets the value of the adminOperation property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the adminOperation property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getAdminOperation().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link AdminOperation }
*
*
*/
public List<AdminOperation> getAdminOperation() {
if (adminOperation == null) {
adminOperation = new ArrayList<AdminOperation>();
}
return this.adminOperation;
}
}
但是从发送遗留请求和来自WSDL来看,该操作标记被替换为选择的操作,例如更新文件等权利?
由于我无法更改旧版请求或旧版WSDL,因此我无法确定如何继续。任何帮助将不胜感激,所以先感谢!
谢谢你的回应! 所以只是为了我的理解:请求应该是 ...等,即使AdminOperation类型在xsd中声明为不同标签的选择,其中之一是UpdateFile?它不能只是<管理> ...? 谢谢我会尝试它,但我不能编辑模式,每次生成它们时都需要编辑对象,所以它仍然有点痛苦! –
TheBloodGuy
2012-07-20 14:49:39
您对'UpdateFile'的元素和路径有正确的想法。我不知道所有的常量,但是我会考虑一次注释生成的类,然后将它放置在一个不会被覆盖的结构中,因为您所在的类是一个实际上与提供的模式不一致的类无论如何。另一个选项(取决于你的舒适度)可能是在原始xml(来自消息上下文)上进行操作,并将其转换为与模式一致(然后将需要显式解组到对象中)。 – dcbyers 2012-07-20 18:46:08
非常感谢您的帮助,我们已经安装了一些CXF拦截器,并且由于约束可能不得不编辑xml。再次感谢。 – TheBloodGuy 2012-07-23 07:22:09