[SWS-714] MockWebServiceClient.sendRequest swallows StackTrace of exceptions thrown during request processing Created: 06/Jul/11  Updated: 09/Dec/14  Resolved: 17/Oct/11

Status: Closed
Project: Spring Web Services
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0.3

Type: Improvement Priority: Minor
Reporter: Erich Eichinger Assignee: Arjen Poutsma
Resolution: Complete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: 4m
Original Estimate: Not Specified


imho there is no need to catch the exception in

public ResponseActions sendRequest(RequestCreator requestCreator) {
Assert.notNull(requestCreator, "'requestCreator' must not be null");

{ WebServiceMessage request = requestCreator.createRequest(messageFactory); MessageContext messageContext = new DefaultMessageContext(request, messageFactory); messageReceiver.receive(messageContext); return new MockWebServiceClientResponseActions(messageContext); }

catch (Exception ex)

{ fail(ex.getMessage()); return null; }


as this swallows any stacktrace. Why not just let the exception propagate?

Comment by Arjen Poutsma [ 17/Oct/11 ]

The Exception cannot propagate because that would force users to deal with it in their integration tests, which is typically not what you want.

That said, I did add some additional logging so that the stacktrace is now fully logged and not lost.

Comment by Arjen Poutsma [ 04/May/12 ]

Closing old issues

Comment by Ruben Suarez Alvarez [ 09/Dec/14 ]

If you catch the exception and don't rethrow it, how am I supposed to test with an expected exception?

Supose I wan't to test a no end point call, something like this:

    @Test(expected = NoEndpointFoundException.class)
    public void whenWrongEndpointThenNoEndpointFoundExceptionIsThrown() {
        Source requestPayload = new StringSource(
                "<badGetCountryRequest xmlns='http://org/eu/rubensa/ws/country'>"
                        + "</badGetCountryRequest>");


As original exception (NoEndpointFoundException) is captured, the exception thrown is an AssertionError, not the expected one, and test fails.

Generated at Thu Oct 18 01:38:27 UTC 2018 using JIRA 7.9.2#79002-sha1:3bb15b68ecd99a30eb364c4c1a393359bcad6278.