我有wsdl(我无法更改)-这是必需的部分:
<xs:complexType name="out">
<xs:sequence>
<xs:element name="isValid"
type="xs:boolean"
minOccurs="0"/>
<xs:element name="errorMessage"
type="xs:string"
minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:element name="GetDataResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return"
type="tns:out"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<message name="GetDataResponseMessage">
<part name="parameters"
element="tns:GetDataResponse"/>
</message>
<operation name="GetData">
<output message="tns:GetDataResponseMessage"/>
</operation>
使用wsdl2java生成的服务(通过此wsdl):
@WebService(...)
@XmlSeeAlso({ObjectFactory.class})
public interface MyService {
@WebMethod(operationName = "GetData", action = "...")
@RequestWrapper(localName = "GetData", targetNamespace = "...", className = "GetData")
@ResponseWrapper(localName = "GetDataResponse", targetNamespace = "..", className = "GetDataResponse")
@WebResult(name = "return", targetNamespace = "...")
public Out getData(
@WebParam(name = "XMLData", targetNamespace = "...")
Request xmlData,
@WebParam(name = "MessageID", targetNamespace = "...")
java.lang.String messageID
);
}
我创建CXF端点:
CxfEndpoint endpoint = new CxfEndpoint();
endpoint.setAddress("address");
endpoint.setServiceClass(MyService.class);
endpoint.setWsdlURL(WSDL_LOCATION);
我用骆驼来称呼这个手术:
.setHeader(CxfConstants.OPERATION_NAMESPACE, namespace())
.setHeader(CxfConstants.OPERATION_NAME, operationName())
.to(endpoint)
响应正文后的服务返回:
<m:GetDataResponse xmlns:m="...">
<m:return xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<isValid>true</isValid>
<errorMessage>sample error</errorMessage>
</m:return>
</m:GetDataResponse>
但是骆驼试图将这具尸体解封到Out.class:
WARN o.a.c.p.PhaseInterceptorChain javax.xml.bind.UnmarshalException:意外元素(uri:“”, 本地:“ isValid”)。预期元素是 <{...} isValid>,<{...} errorMessage>
如果生成的服务没有@ResponseWrapper,则一切正常。
我不在乎结果将是哪种类型-Out.class或GetDataResponse.class-我的主要愿望是不要在我的自定义间隔子中编写对结果的自定义处理。
P.S。我删除了所有名称空间(它们的描述正确,但是没关系)
更新
Out.class定义
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "out", propOrder = {
"isValid",
"errorMessage"
})
public class Out {
protected Boolean isValid;
protected String errorMessage;
/**
* Gets the value of the isValid property.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isIsValid() {
return isValid;
}
/**
* Sets the value of the isValid property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setIsValid(Boolean value) {
this.isValid = value;
}
/**
* Gets the value of the errorMessage property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getErrorMessage() {
return errorMessage;
}
/**
* Sets the value of the errorMessage property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setErrorMessage(String value) {
this.errorMessage = value;
}
/**
* Generates a String representation of the contents of this type.
* This is an extension method, produced by the 'ts' xjc plugin
*
*/
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, JAXBToStringStyle.DEFAULT_STYLE);
}
}