PayloadEndpointAdapter extends TransformerObjectSupport implements EndpointAdapter { @Override public void invoke(MessageContext messageContext, Object endpoint) throws Exception { PayloadEndpoint payloadEndpoint = (PayloadEndpoint) endpoint; Source requestSource = messageContext.getRequest().getPayloadSource(); Source responseSource = payloadEndpoint.invoke(requestSource); if (responseSource != null) { WebServiceMessage response = messageContext.getResponse(); transform(responseSource, response.getPayloadResult()); } }  @Override boolean supports(Object endpoint); @Override void invoke(MessageContext messageContext, Object endpoint);  }
@Test public void testInvoke() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage("<request/>"); final Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer(); PayloadEndpoint endpoint = new PayloadEndpoint() { public Source invoke(Source request) throws Exception { StringWriter writer = new StringWriter(); transformer.transform(request, new StreamResult(writer)); assertXMLEqual("Invalid request", "<request/>", writer.toString()); return new StreamSource(new StringReader("<response/>")); } }; endpoint.invoke(request.getPayloadSource()); MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); adapter.invoke(messageContext, endpoint); MockWebServiceMessage response = (MockWebServiceMessage) messageContext.getResponse(); Assert.assertNotNull("No response created", response); assertXMLEqual("Invalid payload", "<response/>", response.getPayloadAsString()); }
@Test public void testInvokeNoResponse() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage("<request/>"); MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); expect(endpointMock.invoke(isA(Source.class))).andReturn(null); replay(endpointMock); adapter.invoke(messageContext, endpointMock); verify(endpointMock); Assert.assertFalse("Response created", messageContext.hasResponse()); }