Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockWebServiceClient.sendRequest swallows StackTrace of exceptions thrown during request processing [SWS-714] #807

Closed
gregturn opened this issue Jul 6, 2011 · 3 comments
Assignees
Milestone

Comments

@gregturn
Copy link
Contributor

gregturn commented Jul 6, 2011

Erich Eichinger opened SWS-714 and commented

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?


Referenced from: commits d9ed89f

@gregturn
Copy link
Contributor Author

Arjen Poutsma commented

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.

@gregturn
Copy link
Contributor Author

gregturn commented May 4, 2012

Arjen Poutsma commented

Closing old issues

@gregturn
Copy link
Contributor Author

gregturn commented Dec 9, 2014

Ruben Suarez Alvarez commented

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants