google-code-export / rocket-gwt

Automatically exported from code.google.com/p/rocket-gwt
1 stars 1 forks source link

Allow MethodInterceptors to proceed a call multiple times #41

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It's me again. :) I'm trying to write two method interceptors: 

One that transparently handles Authentication/Authorization exceptions on
service calls. On failed authentication, the user is prompted for new
credentials, and the call is performed again, with the new credentials.

The second one is better suited for an example: On access to a service that
may temporarily reject service calls, a method interceptor should retry the
service call a number of times. The source is like that:

public class RetryingInterceptor implements MethodInterceptor {
  private static final int DEFAULT_RETRY_COUNT = 5;
  private int retryCount = DEFAULT_RETRY_COUNT;

  public Object invoke(MethodInvocation invocation) throws Throwable {
    TemporaryNotAvailableException ex = null;
    for (int i = 0; i < this.retryCount; i++) {
      try {
        return invocation.proceed();
      } catch(TemporaryNotAvailableException e) {
        ex = e;
        logInfo("Temporary failure. Retrying in one second.");
        delay(1000);
      }
    }
    throw new NotAvailableException(
      "Retried " + this.retryCount + " times.", ex);
  }
  ...

This works perfectly well with spring-aop. But since the proceed call
relies on an Iterator, it yields a NoSuchElementException when calling it
again.
One method to resolve this would be to build a MethodInvocation chain for
each interceptor.

kind regards,
Bertram

Original issue reported on code.google.com by bertram....@entega-service.de on 11 Jan 2008 at 12:03

GoogleCodeExporter commented 9 years ago
btw: the issue should be an enhancement, not an defect...

Original comment by bertram....@entega-service.de on 11 Jan 2008 at 12:05

GoogleCodeExporter commented 9 years ago
I attached a patched InterceptorChain.java. It worked for me quiet well.

Original comment by bertram....@entega-service.de on 11 Jan 2008 at 1:19

Attachments:

GoogleCodeExporter commented 9 years ago
Thanx!

Original comment by miroslav...@gmail.com on 13 Jan 2008 at 8:36

GoogleCodeExporter commented 9 years ago
I take your code and make some slight changes but the idea remains the same. 
The only
difference is that the next interceptor's MethodInvocation is fetched lazily 
rather
than eagerly.

I have also added a test to InterceptorChainTestCase.

Will check in code shortly.

Do you mind if i add your email to IChain.java ?

Original comment by miroslav...@gmail.com on 13 Jan 2008 at 11:48

GoogleCodeExporter commented 9 years ago
Yes, that's fine with me, put it in. :)

Original comment by bertram....@entega-service.de on 14 Jan 2008 at 8:29