diff options
author | Benoit Foucher <benoit@zeroc.com> | 2019-07-11 17:42:59 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2019-07-11 17:42:59 +0200 |
commit | bcd2c2d1b01e721be924b96247be86384ddc9738 (patch) | |
tree | 7b84ec6832dc13c548fe7d3c7098675c61bb06ec /java | |
parent | Fix .gitignore syntax (diff) | |
download | ice-bcd2c2d1b01e721be924b96247be86384ddc9738.tar.bz2 ice-bcd2c2d1b01e721be924b96247be86384ddc9738.tar.xz ice-bcd2c2d1b01e721be924b96247be86384ddc9738.zip |
Fixed dispatcher interceptor bug #435
Diffstat (limited to 'java')
3 files changed, 119 insertions, 1 deletions
diff --git a/java/src/Ice/src/main/java/com/zeroc/Ice/DispatchInterceptor.java b/java/src/Ice/src/main/java/com/zeroc/Ice/DispatchInterceptor.java index d825707630e..b5f23bb9c27 100644 --- a/java/src/Ice/src/main/java/com/zeroc/Ice/DispatchInterceptor.java +++ b/java/src/Ice/src/main/java/com/zeroc/Ice/DispatchInterceptor.java @@ -36,6 +36,22 @@ public abstract class DispatchInterceptor implements com.zeroc.Ice.Object public CompletionStage<OutputStream> _iceDispatch(com.zeroc.IceInternal.Incoming in, Current current) throws UserException { - return dispatch(in); + try + { + return dispatch(in); + } + catch(java.lang.Throwable ex) + { + // + // If the input parameters weren't read, make sure we skip them here. It's needed to read the + // encoding version used by the client to eventually marshal the user exception. It's also needed + // if we are dispatch a batch oneway request to read the next batch request. + // + if(current.encoding == null || (current.encoding.major == 0 && current.encoding.minor == 0)) + { + in.skipReadParams(); + } + throw ex; + } } } diff --git a/java/test/src/main/java/test/Ice/interceptor/Client.java b/java/test/src/main/java/test/Ice/interceptor/Client.java index 9bd89a14661..b45f9eec748 100644 --- a/java/test/src/main/java/test/Ice/interceptor/Client.java +++ b/java/test/src/main/java/test/Ice/interceptor/Client.java @@ -89,6 +89,11 @@ public class Client extends test.TestHelper test(interceptor.getLastOperation().equals("badSystemAdd")); test(!interceptor.getLastStatus()); out.println("ok"); + + out.print("testing exceptions raised by the interceptor... "); + out.flush(); + testInterceptorExceptions(prx); + out.println("ok"); } private void runAmdTest(MyObjectPrx prx, InterceptorI interceptor, PrintWriter out) @@ -159,6 +164,11 @@ public class Client extends test.TestHelper test(interceptor.getLastOperation().equals("amdBadSystemAdd")); test(interceptor.getLastStatus()); out.println("ok"); + + out.print("testing exceptions raised by the interceptor... "); + out.flush(); + testInterceptorExceptions(prx); + out.println("ok"); } public void run(String[] args) @@ -197,4 +207,60 @@ public class Client extends test.TestHelper runAmdTest(prx, interceptor, out); } } + + private class ExceptionPoint + { + public ExceptionPoint(String point, String exception) + { + this.point = point; + this.exception = exception; + } + public String point; + public String exception; + }; + + private void testInterceptorExceptions(MyObjectPrx prx) + { + java.util.List<ExceptionPoint> exceptions = new java.util.ArrayList<>(); + exceptions.add(new ExceptionPoint("raiseBeforeDispatch", "user")); + exceptions.add(new ExceptionPoint("raiseBeforeDispatch", "notExist")); + exceptions.add(new ExceptionPoint("raiseBeforeDispatch", "system")); + exceptions.add(new ExceptionPoint("raiseAfterDispatch", "user")); + exceptions.add(new ExceptionPoint("raiseAfterDispatch", "notExist")); + exceptions.add(new ExceptionPoint("raiseAfterDispatch", "system")); + for(ExceptionPoint e : exceptions) + { + java.util.Map<String, String> ctx = new java.util.HashMap<>(); + ctx.put(e.point, e.exception); + try + { + prx.ice_ping(ctx); + test(false); + } + catch(com.zeroc.Ice.UnknownUserException ex) + { + test(e.exception.equals("user")); + } + catch(com.zeroc.Ice.ObjectNotExistException ex) + { + test(e.exception.equals("notExist")); + } + catch(com.zeroc.Ice.UnknownException ex) + { + test(e.exception.equals("system")); // non-collocated + } + catch(MySystemException ex) + { + test(e.exception.equals("system")); // collocated + } + { + com.zeroc.Ice.ObjectPrx batch = prx.ice_batchOneway(); + batch.ice_ping(ctx); + batch.ice_ping(); + batch.ice_flushBatchRequests(); + } + } + // Force the last batch request to be dispatched by the server thread using invocation timeouts + prx.ice_invocationTimeout(10000).ice_ping(); + } } diff --git a/java/test/src/main/java/test/Ice/interceptor/InterceptorI.java b/java/test/src/main/java/test/Ice/interceptor/InterceptorI.java index 2437717ecb1..5ea248e1c43 100644 --- a/java/test/src/main/java/test/Ice/interceptor/InterceptorI.java +++ b/java/test/src/main/java/test/Ice/interceptor/InterceptorI.java @@ -9,6 +9,7 @@ import java.util.concurrent.CompletionStage; import com.zeroc.Ice.OutputStream; import test.Ice.interceptor.Test.RetryException; +import test.Ice.interceptor.Test.InvalidInputException; class InterceptorI extends com.zeroc.Ice.DispatchInterceptor { @@ -30,6 +31,24 @@ class InterceptorI extends com.zeroc.Ice.DispatchInterceptor throws com.zeroc.Ice.UserException { com.zeroc.Ice.Current current = request.getCurrent(); + + String context = current.ctx.get("raiseBeforeDispatch"); + if(context != null) + { + if(context.equals("user")) + { + throw new InvalidInputException(); + } + else if(context.equals("notExist")) + { + throw new com.zeroc.Ice.ObjectNotExistException(); + } + else if(context.equals("system")) + { + throw new MySystemException(); + } + } + _lastOperation = current.operation; if(_lastOperation.equals("addWithRetry") || _lastOperation.equals("amdAddWithRetry")) @@ -54,6 +73,23 @@ class InterceptorI extends com.zeroc.Ice.DispatchInterceptor CompletionStage<OutputStream> f = _servant.ice_dispatch(request); _lastStatus = f != null; + + context = current.ctx.get("raiseAfterDispatch"); + if(context != null) + { + if(context.equals("user")) + { + throw new InvalidInputException(); + } + else if(context.equals("notExist")) + { + throw new com.zeroc.Ice.ObjectNotExistException(); + } + else if(context.equals("system")) + { + throw new MySystemException(); + } + } return f; } |