I am struggling with an Spring-WS with JMS example. I set the Spring-WS and JMS wiring as per the Spring recommendations. But I kept getting following error. I dont know how to
This method works when called from SOAPUI:
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getOrderDetail")
public @ResponsePayload JAXBElement<OrderDetailResponse> getOrderDetail(@RequestPayload JAXBElement<String> customerId, @RequestPayload JAXBElement<String> promoCode)
In the method below, the values inside the customerStatusRequest are coming in null even though from SOAPUI I am populating them.
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCustomerStatus")
public @ResponsePayload
JAXBElement<CustomerStatusResponse> getCustomerStatus(@RequestPayload JAXBElement<CustomerStatusRequest> customerStatusRequest)
(CustomerStatusRequest implements Serializable)
It appears String parameter values are making it through the call. But not a custom class. I annotated the CustomerStatusRequest class in this manner:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CustomerStatusRequest", propOrder = {
"customerId",
"gender",
"dob",
"lastName",
"sourceSystemId"
},namespace="http://www.mycompany.com/webservices")
and also each field in the CustomerStatusRequest this way:
@XmlElement(name = "customerId", required = true, nillable = true)
The method is called but the values for customerId, etc... are still coming in as null. Are additional annotations needed for a custom class?
--Thanks
I was using WSDL file and did as below, then it worked.
@PayloadRoot(namespace = "http://www.myservice/v1.0/query", localPart = "queryRequest")
@ResponsePayload
public JAXBElement<QueryResponse> queryAddrLocation(@RequestPayload JAXBElement<QueryRequest> queryRequest) {
System.out.println("Welcome to " + queryRequest);
return createJaxbElement(new QueryResponse(), QueryResponse.class);
}
private <T> JAXBElement<T> createJaxbElement(T object, Class<T> clazz) {
return new JAXBElement<>(new QName(clazz.getSimpleName()), clazz, object);
}
I had a similar error. the problem is that the request and response generated from XSD/WSDL missed the @XMLRootElement annotation. By adding JAXBElement to the endpoint solved the problem.
private static final String NAMESPACE_URI = "<targetNamespace>";
@Autowired
Service service;
@PayloadRoot ( namespace = Endpoint.NAMESPACE_URI, localPart = "name" )
@ResponsePayload
public JAXBElement < Response > Create ( @RequestPayload JAXBElement < Request> request ) throws Exception
{
ObjectFactory factory = new ObjectFactory ( );
Response response = new Response ( );
Request req = request.getValue ( );
response = this.service.call( req);
return factory.createResponse ( response );
}
I had a similar error message. My problem was in request and response class that I generated from XSD. It missed @XMLRootElement annotation. This caused that description of operation (in WSDL) and description of implemented method (in Endpoint) did not match. Adding JAXBElement to my endpoint method solved my problem.
import javax.xml.bind.JAXBElement;
@PayloadRoot(namespace = "http://foo.bar/books", localPart = "GetBook")
@ResponsePayload
public JAXBElement<MyReponse> getBook(@RequestPayload JAXBElement<MyRequest> myRequest) {
...
See this blog for more details: spring-ws: No adapter for endpoint
Same problem but in my case was because I forgot to place the annotations @ResponsePayload
and @RequestPayload
in the handler function. Just check it! It's probably all it's needed.
First, as per the guidelines, there should be an Endpoint class
@Endpoint
public class EmpEndpoint {
@Autowired
private EmpService empService;
//This is like @RequestMapping of Spring MVC
@PayloadRoot(localPart = "EmpServiceRequest", namespace = "http://www.example.org/")
@ResponsePayload
public EmpServiceResponse getemployeeDetails(@RequestPayload EmpServiceRequest request) {
EmpServiceResponse response = new ObjectFactory().createEmpServiceResponse();
List<Employee> l = empService.getemployeeDetails(request.getName());
response.setName(l.get(0).getName());
response.setEmail(l.get(0).getEmail());
return response;
}
}
And one Service and its implementation class which will have PayloadRoot and other Annotations (Request and Response)
And place this in your spring-servlet.xml
<!-- To detect @Endpoint -->
<sws:annotation-driven/>
<!-- To detect @Service, @Component etc -->
<context:component-scan base-package="your package for eg com.employee" />