INT-3022: SimpleResponseMessageExtractor NPE fix

https://jira.springsource.org/browse/INT-3022
This commit is contained in:
Artem Bilan
2013-05-18 17:09:34 +03:00
committed by Gary Russell
parent 564956de86
commit 406dd39bfb
4 changed files with 53 additions and 33 deletions

View File

@@ -38,6 +38,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.handler.ReplyRequiredException;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.WebServiceMessageFactory;
@@ -57,12 +59,17 @@ public class SimpleWebServiceOutboundGatewayTests {
private static final String response = "<response><name>Test Name</name></response>";
private static final String responseSoapMessage = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> " +
public static final String responseSoapMessage = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> " +
"<soap:Body> " +
response +
"</soap:Body> " +
"</soap:Envelope>";
public static final String responseEmptyBodySoapMessage = "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
"<SOAP:Header/>\n" +
"<SOAP:Body/>\n" +
"</SOAP:Envelope>";
@Test // INT-1051
public void soapActionAndCustomCallback() {
String uri = "http://www.example.org";
@@ -100,7 +107,16 @@ public class SimpleWebServiceOutboundGatewayTests {
assertThat(replyMessage.getPayload().toString(), Matchers.endsWith(response));
}
public static WebServiceMessageSender createMockMessageSender() throws Exception {
@Test(expected = ReplyRequiredException.class)
public void testInt3022EmptyResponseBody() throws Exception {
SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway("http://testInt3022");
gateway.setRequiresReply(true);
WebServiceMessageSender messageSender = createMockMessageSender(responseEmptyBodySoapMessage);
gateway.setMessageSender(messageSender);
gateway.handleMessage(new GenericMessage<String>("<test>foo</test>"));
}
public static WebServiceMessageSender createMockMessageSender(final String mockResponseMessage) throws Exception {
WebServiceMessageSender messageSender = Mockito.mock(WebServiceMessageSender.class);
WebServiceConnection wsConnection = Mockito.mock(WebServiceConnection.class);
Mockito.when(messageSender.createConnection(Mockito.any(URI.class))).thenReturn(wsConnection);
@@ -110,7 +126,7 @@ public class SimpleWebServiceOutboundGatewayTests {
public Object answer(InvocationOnMock invocation) throws Exception{
Object[] args = invocation.getArguments();
WebServiceMessageFactory factory = (WebServiceMessageFactory) args[0];
return factory.createWebServiceMessage(new ByteArrayInputStream(responseSoapMessage.getBytes()));
return factory.createWebServiceMessage(new ByteArrayInputStream(mockResponseMessage.getBytes()));
}}).when(wsConnection).receive(Mockito.any(WebServiceMessageFactory.class));
return messageSender;

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:ws="http://www.springframework.org/schema/integration/ws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:ws="http://www.springframework.org/schema/integration/ws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
@@ -20,6 +20,9 @@
</si:chain>
<bean id="mockMessageSender" class="org.springframework.integration.ws.SimpleWebServiceOutboundGatewayTests"
factory-method="createMockMessageSender"/>
factory-method="createMockMessageSender">
<constructor-arg
value="#{T(org.springframework.integration.ws.SimpleWebServiceOutboundGatewayTests).responseSoapMessage}"/>
</bean>
</beans>