[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


 Description   

imho there is no need to catch the exception in

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

{ 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?



 Comments   
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>");
 
        mockClient.sendRequest(withPayload(requestPayload));
    }

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

Generated at Mon Dec 18 12:53:23 UTC 2017 using JIRA 6.4.14#64029-sha1:ae256fe0fbb912241490ff1cecfb323ea0905ca5.