Uploaded image for project: 'Spring Web Services'
  1. Spring Web Services
  2. SWS-714

MockWebServiceClient.sendRequest swallows StackTrace of exceptions thrown during request processing

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 2.0.3
    • Component/s: None
    • Labels:
      None

      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?

        Activity

        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        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.

        Show
        arjen.poutsma Arjen Poutsma added a comment - 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.
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        Closing old issues

        Show
        arjen.poutsma Arjen Poutsma added a comment - Closing old issues
        Hide
        rubensa Ruben Suarez Alvarez added a comment -

        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.

        Show
        rubensa Ruben Suarez Alvarez added a comment - 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.

          People

          • Assignee:
            arjen.poutsma Arjen Poutsma
            Reporter:
            oakinger Erich Eichinger
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - Not Specified
              Not Specified
              Logged:
              Time Spent - 4m
              4m