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

        oakinger Erich Eichinger created issue -
        arjen.poutsma Arjen Poutsma made changes -
        Field Original Value New Value
        Fix Version/s 2.0.3 [ 12197 ]
        Assignee Arjen Poutsma [ arjen.poutsma ]
        arjen.poutsma Arjen Poutsma made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        arjen.poutsma Arjen Poutsma logged work - 17/Oct/11 3:36 AM
        • Time Spent:
          4m
           
          <No comment>
        arjen.poutsma Arjen Poutsma made changes -
        Worklog Id 28436 [ 28436 ]
        Time Spent 4m [ 240 ]
        arjen.poutsma Arjen Poutsma made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Complete [ 8 ]
        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
        arjen.poutsma Arjen Poutsma made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        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.
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        102d 14h 27m 1 Arjen Poutsma 17/Oct/11 3:31 AM
        In Progress In Progress Resolved Resolved
        4m 37s 1 Arjen Poutsma 17/Oct/11 3:36 AM
        Resolved Resolved Closed Closed
        200d 3h 27m 1 Arjen Poutsma 04/May/12 7:03 AM

          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