gpt4 book ai didi

java - 获取 UnmarshallingFailureException 预期的元素是(无)

转载 作者:行者123 更新时间:2023-12-04 01:42:36 25 4
gpt4 key购买 nike

下面是我用来调用服务的代码:

TaskRequest myrequest = objectFactory.createTaskRequest();
myrequest.setId("12");
JAXBElement jElem = new JAXBElement(
new QName("http://service.domain.com/", "taskResponse"),
TaskRequest.class, myrequest);

TaskResponse o = (TaskResponse) webServiceTemplate.marshalSendAndReceive(jElem);

我遇到了这个异常:

org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://service.domain.com/", local:"taskResponse"). Expected elements are (none) at org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:794)

TaskResponse 有以下注解:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TaskResponse", namespace = "http://message.domain.com/", propOrder = {
"id",
"name"
})
public class TaskResponse {...}

这是我的 WebServiceTemplate 配置:

WebServiceTemplate serviceTemplate = new WebServiceTemplate();    
serviceTemplate.setDefaultUri("http://mydomain.com/TaskWebService/taskServ");
serviceTemplate.setMessageFactory(saajSoapMessageFactory());
serviceTemplate.setMessageSender(httpMessageSender());
serviceTemplate.setMarshaller(marshaller());
serviceTemplate.setUnmarshaller(marshaller());

这是我的编码器:

   @Bean
public Jaxb2Marshaller marshaller() {
final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();

jaxb2Marshaller.setContextPath("com.domain.message");
return jaxb2Marshaller;
}

这可能是什么原因?

我正在进行契约优先开发..

最佳答案

您的 TaskResponse 类似乎没有 @XmlRootElement 注释,因此出现编码错误。但是根据错误跟踪,来自 Web 服务的响应似乎是空响应(不是 TaskResponse)。你能用 SoapUI 检查一下实际的响应是什么吗?

关于java - 获取 UnmarshallingFailureException 预期的元素是(无),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21615881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com