Announcement Announcement Module
Collapse
No announcement yet.
Difficulty marshalling custom @RequestPayload Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    Code:
    @Endpoint
    public class MyEndpoint{
      private static final String NAMESPACE_URI = "http://www.myendpoint.com/myendpoint";
    
      @PayloadRoot(namespace=NAMESPACE_URI, localPart="myTest")
      @ResponsePayload
      Public StringResponse handleMyRequest(@RequestPayload Element userElement) {
        StringResponse response = new StringResponse();
        response.setValue("myValue");
        System.out.println(response.getValue();
        return response;
      }
    }
    The test:
    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("MyEndpointContext.xml")
    public class MyEndpointTest {
      @Autowired
      private Applicationcontext applicationContext;
      private MockWebServiceClient mockClient;
    
      @Before
      public void createClient() {
        mockClient = MockWebServiceClient.createClient(applicationContext);
      }
    
      @Test
      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>" );
    
        mockClient.sendRequest(withPayload(requestPayload))
     //     .andExpect(payload(responsePayload))
    ;
      }
    }
    The request parameter:
    Code:
    @XmlRootElement(name="stringRequest")
    public class StringRequest {
      String value;
      <setter and getter>
    }
    The response is the same except for the name.

    key elements from the context file:
    Code:
    <sws:annotation-driven/>
    <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:"http://www.myendpoint.com/myendpoint/", local:"myTest"). Expected elements are <{http://www.myendpoint.com/myendpoint/}stringRequest>

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

    Comment

    Working...
    X