Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting UnmarshallingFailureException Expected elements are (none) at

Below is the code I'm using to call the service:

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

I'm getting this exception:

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 has following annotations:

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

This is my WebServiceTemplate configurations:

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

This is my marshaller:

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

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

What might be reason here?

I'm doing contract-first development..


1 Answers

It seems your TaskResponse class don't have @XmlRootElement annotation and hence Marshalling error. However according to the error trace the response from the web service seems to be empty response(not TaskResponse). Could you check with SoapUI what's the actual response is?

like image 198
Robert Avatar answered May 03 '26 22:05

Robert