diff options
author | Benoit Foucher <benoit@zeroc.com> | 2007-01-10 10:22:43 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2007-01-10 10:22:43 +0000 |
commit | 26c33e45e09f6c635f6a663f05e9edb51f5461ef (patch) | |
tree | 55caad6a4594a51899948b9451171098dbc7fb1e /java | |
parent | Win32 fix (diff) | |
download | ice-26c33e45e09f6c635f6a663f05e9edb51f5461ef.tar.bz2 ice-26c33e45e09f6c635f6a663f05e9edb51f5461ef.tar.xz ice-26c33e45e09f6c635f6a663f05e9edb51f5461ef.zip |
Fixed bug 1650
Diffstat (limited to 'java')
-rwxr-xr-x | java/allTests.py | 3 | ||||
-rw-r--r-- | java/src/Ice/ConnectionI.java | 78 | ||||
-rw-r--r-- | java/src/IceInternal/Incoming.java | 196 | ||||
-rw-r--r-- | java/src/IceInternal/IncomingAsync.java | 261 | ||||
-rw-r--r-- | java/src/IceInternal/IncomingBase.java | 210 | ||||
-rw-r--r-- | java/test/Ice/build.xml | 2 | ||||
-rw-r--r-- | java/test/Ice/servantLocator/AllTests.java | 192 | ||||
-rw-r--r-- | java/test/Ice/servantLocator/Client.java | 33 | ||||
-rw-r--r-- | java/test/Ice/servantLocator/CookieI.java | 19 | ||||
-rw-r--r-- | java/test/Ice/servantLocator/ServantLocatorI.java | 134 | ||||
-rw-r--r-- | java/test/Ice/servantLocator/Server.java | 39 | ||||
-rw-r--r-- | java/test/Ice/servantLocator/Test.ice | 40 | ||||
-rw-r--r-- | java/test/Ice/servantLocator/TestI.java | 54 | ||||
-rw-r--r-- | java/test/Ice/servantLocator/build.xml | 48 | ||||
-rwxr-xr-x | java/test/Ice/servantLocator/run.py | 46 |
15 files changed, 875 insertions, 480 deletions
diff --git a/java/allTests.py b/java/allTests.py index 6b0a3e960bf..2b73738e008 100755 --- a/java/allTests.py +++ b/java/allTests.py @@ -90,7 +90,10 @@ tests = [ \ "Ice/checksum", \ "Ice/package", \ "Ice/stream", \ + "Ice/hold", \ "Ice/retry", \ + "Ice/timeout", \ + "Ice/servantLocator", \ "Freeze/dbmap", \ "Freeze/complex", \ "Freeze/evictor", \ diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index d9ba8889fa9..7dedaa5b00a 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -1416,6 +1416,28 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne setState(StateClosed, ex); } + public synchronized void + invokeException(LocalException ex, int invokeNum) + { + // + // Fatal exception while invoking a request. Since sendResponse/sendNoResponse isn't + // called in case of a fatal exception we decrement _dispatchCount here. + // + + setState(StateClosed, ex); + + if(invokeNum > 0) + { + assert(_dispatchCount > 0); + _dispatchCount -= invokeNum; + assert(_dispatchCount >= 0); + if(_dispatchCount == 0) + { + notifyAll(); + } + } + } + public String type() { @@ -2189,37 +2211,18 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne } catch(LocalException ex) { - synchronized(this) - { - setState(StateClosed, ex); - } + invokeException(ex, invokeNum); } catch(java.lang.AssertionError ex) // Upon assertion, we print the stack trace. { - synchronized(this) - { - UnknownException uex = new UnknownException(); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - uex.unknown = sw.toString(); - _logger.error(uex.unknown); - setState(StateClosed, uex); - } - } - catch(java.lang.Exception ex) - { - synchronized(this) - { - UnknownException uex = new UnknownException(); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - uex.unknown = sw.toString(); - setState(StateClosed, uex); - } + UnknownException uex = new UnknownException(); + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + uex.unknown = sw.toString(); + _logger.error(uex.unknown); + invokeException(uex, invokeNum); } finally { @@ -2228,25 +2231,6 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne reclaimIncoming(in); } } - - // - // If invoke() above raised an exception, and therefore - // neither sendResponse() nor sendNoResponse() has been - // called, then we must decrement _dispatchCount here. - // - if(invokeNum > 0) - { - synchronized(this) - { - assert(_dispatchCount > 0); - _dispatchCount -= invokeNum; - assert(_dispatchCount >= 0); - if(_dispatchCount == 0) - { - notifyAll(); - } - } - } } private void diff --git a/java/src/IceInternal/Incoming.java b/java/src/IceInternal/Incoming.java index 70615982807..8b8b1f1619a 100644 --- a/java/src/IceInternal/Incoming.java +++ b/java/src/IceInternal/Incoming.java @@ -155,177 +155,6 @@ final public class Incoming extends IncomingBase } } } - catch(Ice.RequestFailedException ex) - { - _is.endReadEncaps(); - - if(ex.id == null) - { - ex.id = _current.id; - } - - if(ex.facet == null) - { - ex.facet = _current.facet; - } - - if(ex.operation == null || ex.operation.length() == 0) - { - ex.operation = _current.operation; - } - - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - if(ex instanceof Ice.ObjectNotExistException) - { - _os.writeByte((byte)DispatchStatus._DispatchObjectNotExist); - } - else if(ex instanceof Ice.FacetNotExistException) - { - _os.writeByte((byte)DispatchStatus._DispatchFacetNotExist); - } - else if(ex instanceof Ice.OperationNotExistException) - { - _os.writeByte((byte)DispatchStatus._DispatchOperationNotExist); - } - else - { - assert(false); - } - ex.id.__write(_os); - - // - // For compatibility with the old FacetPath. - // - if(ex.facet == null || ex.facet.length() == 0) - { - _os.writeStringSeq(null); - } - else - { - String[] facetPath2 = { ex.facet }; - _os.writeStringSeq(facetPath2); - } - - _os.writeString(ex.operation); - - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - - return; - } - catch(Ice.UnknownLocalException ex) - { - _is.endReadEncaps(); - - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); - _os.writeString(ex.unknown); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - - return; - } - catch(Ice.UnknownUserException ex) - { - _is.endReadEncaps(); - - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); - _os.writeString(ex.unknown); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - - return; - } - catch(Ice.UnknownException ex) - { - _is.endReadEncaps(); - - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownException); - _os.writeString(ex.unknown); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - - return; - } - catch(Ice.LocalException ex) - { - _is.endReadEncaps(); - - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); - //_os.writeString(ex.toString()); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - _os.writeString(sw.toString()); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - - return; - } /* Not possible in Java - UserExceptions are checked exceptions catch(Ice.UserException ex) { @@ -335,30 +164,7 @@ final public class Incoming extends IncomingBase catch(java.lang.Exception ex) { _is.endReadEncaps(); - - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownException); - //_os.writeString(ex.toString()); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - _os.writeString(sw.toString()); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - + __handleException(ex); return; } diff --git a/java/src/IceInternal/IncomingAsync.java b/java/src/IceInternal/IncomingAsync.java index e8e891b49f0..7a7bb90678f 100644 --- a/java/src/IceInternal/IncomingAsync.java +++ b/java/src/IceInternal/IncomingAsync.java @@ -22,9 +22,9 @@ public class IncomingAsync extends IncomingBase { try { - if(_locator != null && _servant != null) + if(!__servantLocatorFinished()) { - _locator.finished(_current, _servant, _cookie.value); + return; } if(_response) @@ -54,18 +54,7 @@ public class IncomingAsync extends IncomingBase } catch(Ice.LocalException ex) { - _connection.exception(ex); - } - catch(java.lang.Exception ex) - { - Ice.UnknownException uex = new Ice.UnknownException(); - //uex.unknown = ex.toString(); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - uex.unknown = sw.toString(); - _connection.exception(uex); + _connection.invokeException(ex, 1); } } @@ -74,239 +63,35 @@ public class IncomingAsync extends IncomingBase { try { - if(_locator != null && _servant != null) - { - _locator.finished(_current, _servant, _cookie.value); - } - - try - { - throw exc; - } - catch(Ice.RequestFailedException ex) - { - if(ex.id == null) - { - ex.id = _current.id; - } - - if(ex.facet == null) - { - ex.facet = _current.facet; - } - - if(ex.operation == null || ex.operation.length() == 0) - { - ex.operation = _current.operation; - } - - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 1) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - if(ex instanceof Ice.ObjectNotExistException) - { - _os.writeByte((byte)DispatchStatus._DispatchObjectNotExist); - } - else if(ex instanceof Ice.FacetNotExistException) - { - _os.writeByte((byte)DispatchStatus._DispatchFacetNotExist); - } - else if(ex instanceof Ice.OperationNotExistException) - { - _os.writeByte((byte)DispatchStatus._DispatchOperationNotExist); - } - else - { - assert(false); - } - ex.id.__write(_os); - - // - // For compatibility with the old FacetPath. - // - if(ex.facet == null || ex.facet.length() == 0) - { - _os.writeStringSeq(null); - } - else - { - String[] facetPath = { ex.facet }; - _os.writeStringSeq(facetPath); - } - - _os.writeString(ex.operation); - - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - } - catch(Ice.UnknownLocalException ex) - { - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); - _os.writeString(ex.unknown); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - } - catch(Ice.UnknownUserException ex) - { - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); - _os.writeString(ex.unknown); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - } - catch(Ice.UnknownException ex) - { - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownException); - _os.writeString(ex.unknown); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - } - catch(Ice.LocalException ex) - { - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); - //_os.writeString(ex.toString()); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - _os.writeString(sw.toString()); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - } - catch(Ice.UserException ex) + if(!__servantLocatorFinished()) { - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); - //_os.writeString(ex.toString()); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - _os.writeString(sw.toString()); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } + return; } - catch(java.lang.Exception ex) - { - if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault( - "Ice.Warn.Dispatch", 1) > 0) - { - __warning(ex); - } - if(_response) - { - _os.endWriteEncaps(); - _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. - _os.writeByte((byte)DispatchStatus._DispatchUnknownException); - //_os.writeString(ex.toString()); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - _os.writeString(sw.toString()); - _connection.sendResponse(_os, _compress); - } - else - { - _connection.sendNoResponse(); - } - } + __handleException(exc); } catch(Ice.LocalException ex) { - _connection.exception(ex); + _connection.invokeException(ex, 1); } - catch(java.lang.Exception ex) + } + + final private boolean + __servantLocatorFinished() + { + try { - Ice.UnknownException uex = new Ice.UnknownException(); - //uex.unknown = ex.toString(); - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - uex.unknown = sw.toString(); - _connection.exception(uex); + if(_locator != null && _servant != null) + { + _locator.finished(_current, _servant, _cookie.value); + } + return true; } + catch(java.lang.Exception ex) + { + __handleException(ex); + return false; + } } final protected BasicStream diff --git a/java/src/IceInternal/IncomingBase.java b/java/src/IceInternal/IncomingBase.java index 0f6908502b1..98b6777ed05 100644 --- a/java/src/IceInternal/IncomingBase.java +++ b/java/src/IceInternal/IncomingBase.java @@ -128,6 +128,216 @@ public class IncomingBase _os.instance().initializationData().logger.warning(sw.toString()); } + final protected void + __handleException(java.lang.Exception exc) + { + try + { + throw exc; + } + catch(Ice.RequestFailedException ex) + { + if(ex.id == null) + { + ex.id = _current.id; + } + + if(ex.facet == null) + { + ex.facet = _current.facet; + } + + if(ex.operation == null || ex.operation.length() == 0) + { + ex.operation = _current.operation; + } + + if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + if(ex instanceof Ice.ObjectNotExistException) + { + _os.writeByte((byte)DispatchStatus._DispatchObjectNotExist); + } + else if(ex instanceof Ice.FacetNotExistException) + { + _os.writeByte((byte)DispatchStatus._DispatchFacetNotExist); + } + else if(ex instanceof Ice.OperationNotExistException) + { + _os.writeByte((byte)DispatchStatus._DispatchOperationNotExist); + } + else + { + assert(false); + } + ex.id.__write(_os); + + // + // For compatibility with the old FacetPath. + // + if(ex.facet == null || ex.facet.length() == 0) + { + _os.writeStringSeq(null); + } + else + { + String[] facetPath2 = { ex.facet }; + _os.writeStringSeq(facetPath2); + } + + _os.writeString(ex.operation); + + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.UnknownLocalException ex) + { + if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); + _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.UnknownUserException ex) + { + if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); + _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.UnknownException ex) + { + if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownException); + _os.writeString(ex.unknown); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.LocalException ex) + { + if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownLocalException); + //_os.writeString(ex.toString()); + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + _os.writeString(sw.toString()); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(Ice.UserException ex) + { + if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownUserException); + //_os.writeString(ex.toString()); + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + _os.writeString(sw.toString()); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + catch(java.lang.Exception ex) + { + if(_os.instance().initializationData().properties.getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) + { + __warning(ex); + } + + if(_response) + { + _os.endWriteEncaps(); + _os.resize(Protocol.headerSize + 4, false); // Dispatch status position. + _os.writeByte((byte)DispatchStatus._DispatchUnknownException); + //_os.writeString(ex.toString()); + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + _os.writeString(sw.toString()); + _connection.sendResponse(_os, _compress); + } + else + { + _connection.sendNoResponse(); + } + } + } + protected Ice.Current _current; protected Ice.Object _servant; protected Ice.ServantLocator _locator; diff --git a/java/test/Ice/build.xml b/java/test/Ice/build.xml index bdcdfa92e18..755ac9195df 100644 --- a/java/test/Ice/build.xml +++ b/java/test/Ice/build.xml @@ -32,6 +32,8 @@ <ant dir="stream"/> <ant dir="retry"/> <ant dir="timeout"/> + <ant dir="servantLocator"/> + <ant dir="servantLocatorAMD"/> </target> <target name="clean"> diff --git a/java/test/Ice/servantLocator/AllTests.java b/java/test/Ice/servantLocator/AllTests.java new file mode 100644 index 00000000000..e4ee71a9e16 --- /dev/null +++ b/java/test/Ice/servantLocator/AllTests.java @@ -0,0 +1,192 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Test.*; +import Ice.*; + +public class AllTests +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public static void + testExceptions(TestIntfPrx obj, boolean collocated) + { + try + { + obj.requestFailedException(); + test(false); + } + catch(ObjectNotExistException ex) + { + if(!collocated) + { + test(ex.id.equals(obj.ice_getIdentity())); + test(ex.facet.equals(obj.ice_getFacet())); + test(ex.operation.equals("requestFailedException")); + } + } + + try + { + obj.unknownUserException(); + test(false); + } + catch(UnknownUserException ex) + { + test(ex.unknown.equals("reason")); + } + + try + { + obj.unknownLocalException(); + test(false); + } + catch(UnknownLocalException ex) + { + test(ex.unknown.equals("reason")); + } + + try + { + obj.unknownException(); + test(false); + } + catch(UnknownException ex) + { + test(ex.unknown.equals("reason")); + } + + // + // User exceptions are checked exceptions + // +// try +// { +// obj.userException(); +// test(false); +// } +// catch(UnknownUserException ex) +// { +// //System.err.println(ex.unknown); +// test(!collocated); +// test(ex.unknown.equals("Test::TestIntfUserException")); +// } +// catch(TestIntfUserException ex) +// { +// test(collocated); +// } + + try + { + obj.localException(); + test(false); + } + catch(UnknownLocalException ex) + { + //System.err.println(ex.unknown); + test(!collocated); + test(ex.unknown.indexOf("Ice.SocketException") >= 0); + } + catch(SocketException ex) + { + test(collocated); + } + + try + { + obj.javaException(); + test(false); + } + catch(UnknownException ex) + { + //System.err.println(ex.unknown); + test(!collocated); + test(ex.unknown.indexOf("java.lang.RuntimeException: message") >= 0); + } + catch(java.lang.RuntimeException ex) + { + test(collocated); + } + } + + public static TestIntfPrx + allTests(Ice.Communicator communicator, boolean collocated) + { + System.out.print("testing stringToProxy... "); + System.out.flush(); + String ref = "asm:default -p 12010 -t 10000"; + Ice.ObjectPrx base = communicator.stringToProxy(ref); + test(base != null); + System.out.println("ok"); + + System.out.print("testing checked cast... "); + System.out.flush(); + TestIntfPrx obj = TestIntfPrxHelper.checkedCast(base); + test(obj != null); + test(obj.equals(base)); + System.out.println("ok"); + + System.out.print("testing servant locator..."); + System.out.flush(); + base = communicator.stringToProxy("category/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(base); + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("category/unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException ex) + { + } + System.out.println("ok"); + + System.out.print("testing default servant locator..."); + System.out.flush(); + base = communicator.stringToProxy("anothercat/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(base); + base = communicator.stringToProxy("locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(base); + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("anothercat/unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException ex) + { + } + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException ex) + { + } + System.out.println("ok"); + + System.out.print("testing locate exceptions... "); + System.out.flush(); + base = communicator.stringToProxy("category/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(base); + testExceptions(obj, collocated); + System.out.println("ok"); + + System.out.print("testing finished exceptions... "); + System.out.flush(); + base = communicator.stringToProxy("category/finished:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(base); + testExceptions(obj, collocated); + System.out.println("ok"); + + return obj; + } +} diff --git a/java/test/Ice/servantLocator/Client.java b/java/test/Ice/servantLocator/Client.java new file mode 100644 index 00000000000..403616d3c10 --- /dev/null +++ b/java/test/Ice/servantLocator/Client.java @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Test.*; + +public class Client +{ + static class TestClient extends Ice.Application + { + public int + run(String[] args) + { + TestIntfPrx obj = AllTests.allTests(communicator(), false); + obj.shutdown(); + return 0; + } + } + + public static void + main(String[] args) + { + TestClient app = new TestClient(); + int result = app.main("Client", args); + System.gc(); + System.exit(result); + } +} diff --git a/java/test/Ice/servantLocator/CookieI.java b/java/test/Ice/servantLocator/CookieI.java new file mode 100644 index 00000000000..e754004a626 --- /dev/null +++ b/java/test/Ice/servantLocator/CookieI.java @@ -0,0 +1,19 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Test.*; + +public final class CookieI extends Cookie +{ + public String + message() + { + return "blahblah"; + } +} diff --git a/java/test/Ice/servantLocator/ServantLocatorI.java b/java/test/Ice/servantLocator/ServantLocatorI.java new file mode 100644 index 00000000000..7fab16bfb87 --- /dev/null +++ b/java/test/Ice/servantLocator/ServantLocatorI.java @@ -0,0 +1,134 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Test.*; +import Ice.*; + +public final class ServantLocatorI extends Ice.LocalObjectImpl implements Ice.ServantLocator +{ + public + ServantLocatorI(String category) + { + _category = category; + _deactivated = false; + } + + protected synchronized void + finalize() + throws Throwable + { + test(_deactivated); + } + + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public Ice.Object + locate(Ice.Current current, Ice.LocalObjectHolder cookie) + { + synchronized(this) + { + test(!_deactivated); + } + + test(current.id.category.equals(_category) || _category.length() == 0); + + if(current.id.name.equals("unknown")) + { + return null; + } + + test(current.id.name.equals("locate") || current.id.name.equals("finished")); + if(current.id.name.equals("locate")) + { + exception(current); + } + + cookie.value = new CookieI(); + + return new TestI(); + } + + public void + finished(Ice.Current current, Ice.Object servant, Ice.LocalObject cookie) + { + synchronized(this) + { + test(!_deactivated); + } + + test(current.id.category.equals(_category) || _category.length() == 0); + test(current.id.name.equals("locate") || current.id.name.equals("finished")); + + if(current.id.name.equals("finished")) + { + exception(current); + } + + Cookie co = (Cookie)cookie; + test(co.message().equals("blahblah")); + } + + public synchronized void + deactivate(String category) + { + synchronized(this) + { + test(!_deactivated); + + _deactivated = true; + } + } + + private void + exception(Ice.Current current) + { + if(current.operation.equals("requestFailedException")) + { + throw new ObjectNotExistException(); + } + else if(current.operation.equals("unknownUserException")) + { + throw new UnknownUserException("reason"); + } + else if(current.operation.equals("unknownLocalException")) + { + throw new UnknownLocalException("reason"); + } + else if(current.operation.equals("unknownException")) + { + throw new UnknownException("reason"); + } + // + // User exceptions are checked exceptions in Java, so it's not + // possible to throw it from the servant locator. + // +// else if(current.operation.equals("userException")) +// { +// throw new TestIntfUserException(); +// } + else if(current.operation.equals("localException")) + { + throw new SocketException(0); + } + else if(current.operation.equals("javaException")) + { + throw new java.lang.RuntimeException("message"); + } + } + + private boolean _deactivated; + private final String _category; +} diff --git a/java/test/Ice/servantLocator/Server.java b/java/test/Ice/servantLocator/Server.java new file mode 100644 index 00000000000..a6e9f74be45 --- /dev/null +++ b/java/test/Ice/servantLocator/Server.java @@ -0,0 +1,39 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Server +{ + static class TestServer extends Ice.Application + { + public int + run(String[] args) + { + communicator().getProperties().setProperty("Ice.OA.TestAdapter.Endpoints", "default -p 12010 -t 10000"); + communicator().getProperties().setProperty("Ice.Warn.Dispatch", "0"); + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("TestAdapter"); + adapter.addServantLocator(new ServantLocatorI("category"), "category"); + adapter.addServantLocator(new ServantLocatorI(""), ""); + adapter.add(new TestI(), communicator().stringToIdentity("asm")); + + adapter.activate(); + adapter.waitForDeactivate(); + return 0; + } + } + + public static void + main(String[] args) + { + TestServer app = new TestServer(); + int result = app.main("Server", args); + System.gc(); + System.exit(result); + } +} diff --git a/java/test/Ice/servantLocator/Test.ice b/java/test/Ice/servantLocator/Test.ice new file mode 100644 index 00000000000..c32c7e89538 --- /dev/null +++ b/java/test/Ice/servantLocator/Test.ice @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +module Test +{ + +exception TestIntfUserException +{ +}; + +interface TestIntf +{ + void requestFailedException(); + void unknownUserException(); + void unknownLocalException(); + void unknownException(); + void localException(); + //void userException(); + void javaException(); + + void shutdown(); +}; + +local class Cookie +{ + ["cpp:const"] string message(); +}; + +}; + +#endif diff --git a/java/test/Ice/servantLocator/TestI.java b/java/test/Ice/servantLocator/TestI.java new file mode 100644 index 00000000000..15520733750 --- /dev/null +++ b/java/test/Ice/servantLocator/TestI.java @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Test.*; + +public final class TestI extends _TestIntfDisp +{ + public void + requestFailedException(Ice.Current current) + { + } + + public void + unknownUserException(Ice.Current current) + { + } + + public void + unknownLocalException(Ice.Current current) + { + } + + public void + unknownException(Ice.Current current) + { + } + + public void + localException(Ice.Current current) + { + } + +// public void +// userException(Ice.Current current) +// { +// } + + public void + javaException(Ice.Current current) + { + } + + public void + shutdown(Ice.Current current) + { + current.adapter.deactivate(); + } +} diff --git a/java/test/Ice/servantLocator/build.xml b/java/test/Ice/servantLocator/build.xml new file mode 100644 index 00000000000..7989d984638 --- /dev/null +++ b/java/test/Ice/servantLocator/build.xml @@ -0,0 +1,48 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. + + This copy of Ice is licensed to you under the terms described in the + ICE_LICENSE file included in this distribution. + + ********************************************************************** +--> + +<project name="test_Ice_servantLocator" default="all" basedir="."> + + <!-- set global properties for this build --> + <property name="top.dir" value="../../.."/> + + <!-- import common definitions --> + <import file="${top.dir}/config/common.xml"/> + + <target name="generate" depends="init"> + <!-- Create the output directory for generated code --> + <mkdir dir="${generated.dir}"/> + <slice2java outputdir="${generated.dir}"> + <meta value="${java5metadata}"/> + <fileset dir="." includes="Test.ice"/> + </slice2java> + </target> + + <target name="compile" depends="generate"> + <mkdir dir="${class.dir}"/> + <javac srcdir="${generated.dir}" destdir="${class.dir}" + source="${jdk.version}" classpath="${lib.dir}" debug="${debug}"> + <compilerarg value="${javac.lint}" compiler="${javac.lint.compiler}"/> + </javac> + <javac srcdir="." destdir="${class.dir}" source="${jdk.version}" + classpath="${lib.dir}" excludes="generated/**" debug="${debug}"> + <compilerarg value="${javac.lint}" compiler="${javac.lint.compiler}"/> + </javac> + </target> + + <target name="all" depends="compile"/> + + <target name="clean"> + <delete dir="${generated.dir}"/> + <delete dir="${class.dir}"/> + </target> + +</project> diff --git a/java/test/Ice/servantLocator/run.py b/java/test/Ice/servantLocator/run.py new file mode 100755 index 00000000000..3e6d59ec3a7 --- /dev/null +++ b/java/test/Ice/servantLocator/run.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("Ice", "servantLocator") +nameAMD = os.path.join("Ice", "servantLocatorAMD") +testdir = os.path.join(toplevel, "test", name) +testdirAMD = os.path.join(toplevel, "test", nameAMD) +os.environ["CLASSPATH"] = os.path.join(testdir, "classes") + TestUtil.sep + os.getenv("CLASSPATH", "") + +# +# We need to use mixedClientServerTest so that, when using SSL, the +# server-side SSL configuration properties are defined. This is +# necessary because the client creates object adapters. +# +print "tests with regular server." +classpath = os.getenv("CLASSPATH", "") +TestUtil.mixedClientServerTest() + +print "tests with AMD server." +TestUtil.clientServerTestWithClasspath(\ + os.path.join(testdirAMD, "classes") + TestUtil.sep + classpath,\ + os.path.join(testdir, "classes") + TestUtil.sep + classpath) + +print "tests with collocated server." +TestUtil.collocatedTest() + +sys.exit(0) |