WebServiceMessageReceiverObjectSupport implements InitializingBean { protected final void handleConnection(WebServiceConnection connection, WebServiceMessageReceiver receiver) throws Exception { logUri(connection); TransportContext previousTransportContext = TransportContextHolder.getTransportContext(); TransportContextHolder.setTransportContext(new DefaultTransportContext(connection)); try { WebServiceMessage request = connection.receive(getMessageFactory()); MessageContext messageContext = new DefaultMessageContext(request, getMessageFactory()); receiver.receive(messageContext); if (messageContext.hasResponse()) { WebServiceMessage response = messageContext.getResponse(); if (response instanceof FaultAwareWebServiceMessage && connection instanceof FaultAwareWebServiceConnection) { FaultAwareWebServiceMessage faultResponse = (FaultAwareWebServiceMessage) response; FaultAwareWebServiceConnection faultConnection = (FaultAwareWebServiceConnection) connection; faultConnection.setFaultCode(faultResponse.getFaultCode()); } connection.send(messageContext.getResponse()); } } catch (NoEndpointFoundException ex) { handleNoEndpointFoundException(ex, connection, receiver); } finally { TransportUtils.closeConnection(connection); TransportContextHolder.setTransportContext(previousTransportContext); } }  WebServiceMessageFactory getMessageFactory(); void setMessageFactory(WebServiceMessageFactory messageFactory); @Override void afterPropertiesSet();  }
@Test public void handleConnectionResponse() throws Exception { expect(connectionMock.receive(messageFactory)).andReturn(request); connectionMock.setFaultCode(null); connectionMock.send(isA(WebServiceMessage.class)); connectionMock.close(); replay(connectionMock); WebServiceMessageReceiver receiver = new WebServiceMessageReceiver() { @Override public void receive(MessageContext messageContext) throws Exception { Assert.assertNotNull("No message context", messageContext); messageContext.getResponse(); } }; receiverSupport.handleConnection(connectionMock, receiver); verify(connectionMock); }
@Test public void handleConnectionFaultResponse() throws Exception { final QName faultCode = SoapVersion.SOAP_11.getClientOrSenderFaultName(); expect(connectionMock.receive(messageFactory)).andReturn(request); connectionMock.setFaultCode(faultCode); connectionMock.send(isA(WebServiceMessage.class)); connectionMock.close(); replay(connectionMock); WebServiceMessageReceiver receiver = new WebServiceMessageReceiver() { @Override public void receive(MessageContext messageContext) throws Exception { Assert.assertNotNull("No message context", messageContext); MockWebServiceMessage response = (MockWebServiceMessage) messageContext.getResponse(); response.setFaultCode(faultCode); } }; receiverSupport.handleConnection(connectionMock, receiver); verify(connectionMock); }
@Test public void handleConnectionNoResponse() throws Exception { expect(connectionMock.receive(messageFactory)).andReturn(request); connectionMock.close(); replay(connectionMock); WebServiceMessageReceiver receiver = new WebServiceMessageReceiver() { public void receive(MessageContext messageContext) throws Exception { Assert.assertNotNull("No message context", messageContext); } }; receiverSupport.handleConnection(connectionMock, receiver); verify(connectionMock); }