Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-3506

GatewayProxyFactory breaks when service method declaration returns a subclass of Future

    XMLWordPrintable

    Details

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

      Description

      If a gateway service interface returns a subtype of Future, a ClassCastException will occur as GatewayProxyFactory always returns a FutureTask.

      GatewayProxyFactory.invoke has the following code:

      if (Future.class.isAssignableFrom(invocation.getMethod().getReturnType())) {
        return this.asyncExecutor.submit(new AsyncInvocationTask(invocation));
      }
      

      asyncExecutuor (a SimpleAsyncTaskExecutor) in turn returns FutureTask. The use of isAssignableFrom should either be flipped or the condition should be restricted to apply only when explicitly returning Future (the interface).

      Note: in this case, we don't want Spring Integration's handling of Future to kick-in. We're manually supporting CompletableFuture (until Spring adds support) by directing the gateway to a specific channel that then acts as a mux for outgoing messages.

      The workaround for this issue is to declare the service interface as returning a CompletionStage, which doesn't receive any special handling by Spring (and contains all of the useful methods of CompletableFuture).

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              grussell Gary Russell
              Reporter:
              akashani Amir Kashani
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: