Announcement Announcement Module
No announcement yet.
Difficulty marshalling custom @RequestPayload Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Difficulty marshalling custom @RequestPayload

    I'm trying to do some integration tests on my web services, using the methodology defined in the spring-ws reference doc, (section 5.7). The problem is that when I define the @RequestPayload as an Element, the code works as expected and I can set breakpoints and see the data.

    However, when I define the payload as anything else (which I have duly annotated with @XmlRootElement) the test 'silently fails'. I get a green bar on the junit test, but the code within the method is not executed. No breakpoints hit, and any println messages defined do not display. Code examples follow. Please note that my development network is not connected to the internet, so I am fat-fingering in the relevant code. Please ignore any misspellings.

    The endpoint:
    public class MyEndpoint{
      private static final String NAMESPACE_URI = "";
      @PayloadRoot(namespace=NAMESPACE_URI, localPart="myTest")
      Public StringResponse handleMyRequest(@RequestPayload Element userElement) {
        StringResponse response = new StringResponse();
        return response;
    The test:
    public class MyEndpointTest {
      private Applicationcontext applicationContext;
      private MockWebServiceClient mockClient;
      public void createClient() {
        mockClient = MockWebServiceClient.createClient(applicationContext);
      public void firstTest() throws Exception {
        Source requestPayload = new StringSource( "<myTest xmlns='" + NAMESPACE_URI + "'>"
        + "<stringRequest><value>MyName</value></stringRequest>" + "</myTest>");
        Source responsePayload = new StringSource( "<stringResponse xmlns='" + NAMESPACE_URI + "'>"
        + "<value>MyValue</value></stringResponse>" );
     //     .andExpect(payload(responsePayload))
    The request parameter:
    public class StringRequest {
      String value;
      <setter and getter>
    The response is the same except for the name.

    key elements from the context file:
    <context:component-scan base-package = "myEndpoint"/>
    The jaxbMarshaller has both StringRequest and StringResponse bound.
    the rest of the context file is taken pretty much verbatim from the example.

    One other item I noted. The .andExpect method is relying on org.custommonkey.xmlunit but that is not noted in the documentation, nor is it included in the distribution of either spring-ws or spring-framework-test.

    I am using spring-ws 2.0.1 and spring-framework 3.0.5.

    As written above, the test runs and I get the println on the console. If I change the Element to StringRequest, the junit test still runs but the method does not execute.

    Can anyone provide insight?

  • #2
    While debugging, I found that the unmarshaller was throwing this error:
    javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"myTest"). Expected elements are <{}stringRequest>

    The <myTest> tag is required to get the @PayloadRoot to match, but it is being evaluated as part of the element being passed.