Skip to content

Commit

Permalink
SOAP call not rejected when interceptor fails
Browse files Browse the repository at this point in the history
When a ClientInterceptor returns false for handleRequest, the actual
SOAP call should not proceed.

Issue: SWS-892
  • Loading branch information
poutsma committed Mar 16, 2015
1 parent 3f15500 commit b6500fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,16 +590,19 @@ protected <T> T doSendAndReceive(MessageContext messageContext,
requestCallback.doWithMessage(messageContext.getRequest());
}
// Apply handleRequest of registered interceptors
boolean intercepted = false;

This comment has been minimized.

Copy link
@gregturn

gregturn Mar 17, 2015

Contributor

Looks like an inconsistent tabs/spaces formatting here.

if (interceptors != null) {
for (int i = 0; i < interceptors.length; i++) {
interceptorIndex = i;
if (!interceptors[i].handleRequest(messageContext)) {
intercepted = true;

This comment has been minimized.

Copy link
@gregturn

gregturn Mar 17, 2015

Contributor

Looks like an inconsistent tabs/spaces formatting here.

break;
}
}
}
// if an interceptor has set a response, we don't send/receive
if (!messageContext.hasResponse()) {
// no send/receive if an interceptor has set a response or if the chain
// has been interrupted
if (!messageContext.hasResponse() && !intercepted) {
sendRequest(connection, messageContext.getRequest());
if (hasError(connection, messageContext.getRequest())) {
triggerAfterCompletion(interceptorIndex, messageContext, null);
Expand All @@ -622,6 +625,7 @@ protected <T> T doSendAndReceive(MessageContext messageContext,
}
}
else {
triggerAfterCompletion(interceptorIndex, messageContext, null);

This comment has been minimized.

Copy link
@gregturn

gregturn Mar 17, 2015

Contributor

Looks like an inconsistent tabs/spaces formatting here.

return null;
}
}
Expand Down Expand Up @@ -793,8 +797,8 @@ private void triggerHandleFault(int interceptorIndex, MessageContext messageCont
* invoke afterCompletion for all interceptors whose handleRequest invocation has
* successfully completed and returned true, in addition to the last interceptor who
* returned {@code false}.
* @param mappedEndpoint the mapped EndpointInvocationChain
* @param interceptorIndex index of last interceptor that successfully completed
* @param messageContext the message context
* @param ex Exception thrown on handler execution, or {@code null} if none
* @see ClientInterceptor#afterCompletion
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,32 +407,24 @@ public void testInterceptors() throws Exception {
}

@Test
public void testInterceptorsIntercepted() throws Exception {
public void testInterceptorsInterceptedNoResponse() throws Exception {
MessageContext messageContext = new DefaultMessageContext(messageFactory);

ClientInterceptor interceptorMock1 = createStrictMock("interceptor1", ClientInterceptor.class);
ClientInterceptor interceptorMock2 = createStrictMock("interceptor2", ClientInterceptor.class);
template.setInterceptors(new ClientInterceptor[]{interceptorMock1, interceptorMock2});
expect(interceptorMock1.handleRequest(isA(MessageContext.class))).andReturn(false);
expect(interceptorMock1.handleResponse(isA(MessageContext.class))).andReturn(true);
interceptorMock1.afterCompletion(isA(MessageContext.class), (Exception)isNull());

WebServiceMessageCallback requestCallback = createMock(WebServiceMessageCallback.class);
requestCallback.doWithMessage(messageContext.getRequest());

WebServiceMessageExtractor extractorMock = createMock(WebServiceMessageExtractor.class);
Object extracted = new Object();
expect(extractorMock.extractData(isA(WebServiceMessage.class))).andReturn(extracted);

connectionMock.send(isA(WebServiceMessage.class));
expect(connectionMock.hasError()).andReturn(false);
expect(connectionMock.receive(messageFactory)).andReturn(new MockWebServiceMessage("<response/>"));
expect(connectionMock.hasFault()).andReturn(false);

replay(connectionMock, interceptorMock1, interceptorMock2, requestCallback, extractorMock);

Object result = template.doSendAndReceive(messageContext, connectionMock, requestCallback, extractorMock);
assertEquals("Invalid response", extracted, result);
assertNull(result);

This comment has been minimized.

Copy link
@gregturn

gregturn Mar 17, 2015

Contributor

Looks like an inconsistent tabs/spaces formatting here.


verify(connectionMock, interceptorMock1, interceptorMock2, requestCallback, extractorMock);
}
Expand Down

0 comments on commit b6500fe

Please sign in to comment.