diff options
author | Michi Henning <michi@zeroc.com> | 2007-10-29 16:57:02 +1000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2007-10-29 16:57:02 +1000 |
commit | 3d0c83b386b37331de7069430049aec4944451c9 (patch) | |
tree | 4fb024d1b638e88c63ba655c6d4348211e588b59 /cpp | |
parent | Merge branch 'master' of cvs:/home/git/ice (diff) | |
download | ice-3d0c83b386b37331de7069430049aec4944451c9.tar.bz2 ice-3d0c83b386b37331de7069430049aec4944451c9.tar.xz ice-3d0c83b386b37331de7069430049aec4944451c9.zip |
Bug 2522.
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/CHANGES | 3 | ||||
-rw-r--r-- | cpp/src/Ice/Incoming.cpp | 83 | ||||
-rw-r--r-- | cpp/src/Ice/IncomingAsync.cpp | 26 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/AllTests.cpp | 34 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/Client.cpp | 2 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/Collocated.cpp | 2 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/Makefile | 2 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/ServantLocatorI.cpp | 11 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/ServantLocatorI.h | 2 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/Server.cpp | 2 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/ServerAMD.cpp | 2 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/Test.ice | 10 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/TestAMD.ice | 12 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/TestAMDI.cpp | 22 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/TestAMDI.h | 8 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/TestI.cpp | 22 | ||||
-rw-r--r-- | cpp/test/Ice/servantLocator/TestI.h | 6 | ||||
-rwxr-xr-x | cpp/test/Ice/servantLocator/run.py | 2 |
18 files changed, 215 insertions, 36 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index 322d46756f9..61922a58a8f 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -1,6 +1,9 @@ Changes since version 3.2.X (binary incompatible) ------------------------------------------------- +- Changed servant locators so both locate() and finished() can + throw user exceptions. (See the manual for details.) + - slice2vb has been removed from the distribution and is no longer supported. To use Visual Basic .NET with Ice, use slice2cs to generate C# code from Slice definitions, and then use a C# compiler to create a DLL from the diff --git a/cpp/src/Ice/Incoming.cpp b/cpp/src/Ice/Incoming.cpp index 391515df1ad..07af1086aa8 100644 --- a/cpp/src/Ice/Incoming.cpp +++ b/cpp/src/Ice/Incoming.cpp @@ -406,6 +406,7 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) try { + bool finishedException = false; try { if(servantManager) @@ -420,27 +421,38 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) } if(_locator) { - _servant = _locator->locate(_current, _cookie); + try + { + _servant = _locator->locate(_current, _cookie); + } + catch(const UserException& ex) + { + _os.write(ex); + replyStatus = replyUserException; + } } } } - if(!_servant) + if(replyStatus == replyOK) { - if(servantManager && servantManager->hasServant(_current.id)) + if(!_servant) { - replyStatus = replyFacetNotExist; + if(servantManager && servantManager->hasServant(_current.id)) + { + replyStatus = replyFacetNotExist; + } + else + { + replyStatus = replyObjectNotExist; + } } else { - replyStatus = replyObjectNotExist; - } - } - else - { - dispatchStatus = _servant->__dispatch(*this, _current); - if(dispatchStatus == DispatchUserException) - { - replyStatus = replyUserException; + dispatchStatus = _servant->__dispatch(*this, _current); + if(dispatchStatus == DispatchUserException) + { + replyStatus = replyUserException; + } } } } @@ -448,15 +460,50 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager) { if(_locator && _servant && dispatchStatus != DispatchAsync) { - _locator->finished(_current, _servant, _cookie); + try + { + _locator->finished(_current, _servant, _cookie); + } + catch(const UserException& ex) + { + // + // The operation may have already marshaled a reply; we must overwrite that reply. + // + _os.endWriteEncaps(); + _os.b.resize(headerSize + 5); // Byte following reply status. + _os.startWriteEncaps(); + _os.write(ex); + replyStatus = replyUserException; // Code below inserts the reply status. + finishedException = true; + } + catch(...) + { + throw; + } + } + if(!finishedException) + { + throw; } - - throw; } - if(_locator && _servant && dispatchStatus != DispatchAsync) + if(!finishedException && _locator && _servant && dispatchStatus != DispatchAsync) { - _locator->finished(_current, _servant, _cookie); + try + { + _locator->finished(_current, _servant, _cookie); + } + catch(const UserException& ex) + { + // + // The operation may have already marshaled a reply; we must overwrite that reply. + // + _os.endWriteEncaps(); + _os.b.resize(headerSize + 5); // Byte following reply status. + _os.startWriteEncaps(); + _os.write(ex); + replyStatus = replyUserException; // Code below inserts the reply status. + } } } catch(const std::exception& ex) diff --git a/cpp/src/Ice/IncomingAsync.cpp b/cpp/src/Ice/IncomingAsync.cpp index 0db1a4acaf6..c479c034399 100644 --- a/cpp/src/Ice/IncomingAsync.cpp +++ b/cpp/src/Ice/IncomingAsync.cpp @@ -138,7 +138,31 @@ IceInternal::IncomingAsync::__servantLocatorFinished() { if(_locator && _servant) { - _locator->finished(_current, _servant, _cookie); + try + { + _locator->finished(_current, _servant, _cookie); + } + catch(const UserException& ex) + { + // + // The operation may have already marshaled a reply; we must overwrite that reply. + // + if(_response) + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Reply status position. + _os.write(replyUserException); + _os.startWriteEncaps(); + _os.write(ex); + _os.endWriteEncaps(); + _connection->sendResponse(&_os, _compress); + } + else + { + _connection->sendNoResponse(); + } + return false; + } } return true; } diff --git a/cpp/test/Ice/servantLocator/AllTests.cpp b/cpp/test/Ice/servantLocator/AllTests.cpp index cbfda04dcd1..c9de4b3aa52 100644 --- a/cpp/test/Ice/servantLocator/AllTests.cpp +++ b/cpp/test/Ice/servantLocator/AllTests.cpp @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. @@ -137,6 +137,38 @@ testExceptions(const TestIntfPrx& obj, bool collocated) { test(ex.unknown == "reason"); } + + try + { + obj->intfUserException(); + test(false); + } + catch(const TestIntfUserException&) + { + } + catch(...) + { + test(false); + } + + try + { + obj->impossibleException(); + test(false); + } + catch(const TestImpossibleException&) + { + test(collocated); + } + catch(const UnknownUserException&) + { + test(!collocated); + } + catch(...) + { + test(false); + } + } TestIntfPrx diff --git a/cpp/test/Ice/servantLocator/Client.cpp b/cpp/test/Ice/servantLocator/Client.cpp index 1303af0ac9a..cb80df831e5 100644 --- a/cpp/test/Ice/servantLocator/Client.cpp +++ b/cpp/test/Ice/servantLocator/Client.cpp @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. diff --git a/cpp/test/Ice/servantLocator/Collocated.cpp b/cpp/test/Ice/servantLocator/Collocated.cpp index d9b0fa5d300..471537c3950 100644 --- a/cpp/test/Ice/servantLocator/Collocated.cpp +++ b/cpp/test/Ice/servantLocator/Collocated.cpp @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. diff --git a/cpp/test/Ice/servantLocator/Makefile b/cpp/test/Ice/servantLocator/Makefile index 90ba62d6e98..d581a4d4e28 100644 --- a/cpp/test/Ice/servantLocator/Makefile +++ b/cpp/test/Ice/servantLocator/Makefile @@ -1,6 +1,6 @@ # ********************************************************************** # -# Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +# Copyright (c) 2003-2007 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. diff --git a/cpp/test/Ice/servantLocator/ServantLocatorI.cpp b/cpp/test/Ice/servantLocator/ServantLocatorI.cpp index 93727d24be1..c7203f2502d 100644 --- a/cpp/test/Ice/servantLocator/ServantLocatorI.cpp +++ b/cpp/test/Ice/servantLocator/ServantLocatorI.cpp @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. @@ -8,6 +8,7 @@ // ********************************************************************** #include <ServantLocatorI.h> +#include <Test.h> #include <TestCommon.h> #include <stdexcept> @@ -110,4 +111,12 @@ ServantLocatorI::exception(const Ice::Current& current) { throw UnknownException(__FILE__, __LINE__, "reason"); } + else if(current.operation == "intfUserException") + { + throw TestIntfUserException(); + } + else if(current.operation == "impossibleException") + { + throw TestImpossibleException(); + } } diff --git a/cpp/test/Ice/servantLocator/ServantLocatorI.h b/cpp/test/Ice/servantLocator/ServantLocatorI.h index 2e1fd4e67aa..d923712f41a 100644 --- a/cpp/test/Ice/servantLocator/ServantLocatorI.h +++ b/cpp/test/Ice/servantLocator/ServantLocatorI.h @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. diff --git a/cpp/test/Ice/servantLocator/Server.cpp b/cpp/test/Ice/servantLocator/Server.cpp index 68348699177..68a6b3d0c78 100644 --- a/cpp/test/Ice/servantLocator/Server.cpp +++ b/cpp/test/Ice/servantLocator/Server.cpp @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. diff --git a/cpp/test/Ice/servantLocator/ServerAMD.cpp b/cpp/test/Ice/servantLocator/ServerAMD.cpp index c52bedbec23..dab8ac089f0 100644 --- a/cpp/test/Ice/servantLocator/ServerAMD.cpp +++ b/cpp/test/Ice/servantLocator/ServerAMD.cpp @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. diff --git a/cpp/test/Ice/servantLocator/Test.ice b/cpp/test/Ice/servantLocator/Test.ice index f677738477b..3790b54b479 100644 --- a/cpp/test/Ice/servantLocator/Test.ice +++ b/cpp/test/Ice/servantLocator/Test.ice @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. @@ -17,6 +17,10 @@ exception TestIntfUserException { }; +exception TestImpossibleException +{ +}; + interface TestIntf { void requestFailedException(); @@ -29,6 +33,10 @@ interface TestIntf void cppException(); void unknownExceptionWithServantException(); + + string intfUserException() throws TestIntfUserException; + + string impossibleException() throws TestIntfUserException; void shutdown(); }; diff --git a/cpp/test/Ice/servantLocator/TestAMD.ice b/cpp/test/Ice/servantLocator/TestAMD.ice index 5c677918c06..a8ec1209e50 100644 --- a/cpp/test/Ice/servantLocator/TestAMD.ice +++ b/cpp/test/Ice/servantLocator/TestAMD.ice @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. @@ -17,6 +17,10 @@ exception TestIntfUserException { }; +exception TestImpossibleException +{ +}; + ["amd"] interface TestIntf { void requestFailedException(); @@ -27,9 +31,13 @@ exception TestIntfUserException void userException(); void stdException(); void cppException(); - + void unknownExceptionWithServantException(); + string intfUserException() throws TestIntfUserException; + + string impossibleException() throws TestIntfUserException; + void shutdown(); }; diff --git a/cpp/test/Ice/servantLocator/TestAMDI.cpp b/cpp/test/Ice/servantLocator/TestAMDI.cpp index 073f77c0ae6..970ef71134e 100644 --- a/cpp/test/Ice/servantLocator/TestAMDI.cpp +++ b/cpp/test/Ice/servantLocator/TestAMDI.cpp @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. @@ -69,6 +69,26 @@ TestAMDI::unknownExceptionWithServantException_async(const Test::AMD_TestIntf_un } void +TestAMDI::intfUserException_async(const Test::AMD_TestIntf_intfUserExceptionPtr& cb, const Current&) +{ + // + // Return a value so we can be sure that the stream position + // is reset correctly if finished() throws. + // + cb->ice_response("Hello"); +} + +void +TestAMDI::impossibleException_async(const Test::AMD_TestIntf_impossibleExceptionPtr& cb, const Current&) +{ + // + // Return a value so we can be sure that the stream position + // is reset correctly if finished() throws. + // + cb->ice_response("Hello"); +} + +void TestAMDI::shutdown_async(const Test::AMD_TestIntf_shutdownPtr& cb, const Current& current) { current.adapter->deactivate(); diff --git a/cpp/test/Ice/servantLocator/TestAMDI.h b/cpp/test/Ice/servantLocator/TestAMDI.h index 1fef32739e1..aed39a6bca0 100644 --- a/cpp/test/Ice/servantLocator/TestAMDI.h +++ b/cpp/test/Ice/servantLocator/TestAMDI.h @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. @@ -25,7 +25,11 @@ public: virtual void stdException_async(const Test::AMD_TestIntf_stdExceptionPtr&, const Ice::Current&); virtual void cppException_async(const Test::AMD_TestIntf_cppExceptionPtr&, const Ice::Current&); - virtual void unknownExceptionWithServantException_async(const Test::AMD_TestIntf_unknownExceptionWithServantExceptionPtr&, const Ice::Current&); + virtual void unknownExceptionWithServantException_async( + const Test::AMD_TestIntf_unknownExceptionWithServantExceptionPtr&, const Ice::Current&); + + virtual void intfUserException_async(const Test::AMD_TestIntf_intfUserExceptionPtr&, const Ice::Current&); + virtual void impossibleException_async(const Test::AMD_TestIntf_impossibleExceptionPtr&, const Ice::Current&); virtual void shutdown_async(const Test::AMD_TestIntf_shutdownPtr&, const Ice::Current&); }; diff --git a/cpp/test/Ice/servantLocator/TestI.cpp b/cpp/test/Ice/servantLocator/TestI.cpp index 5c32a3ff950..cbb310c7ffc 100644 --- a/cpp/test/Ice/servantLocator/TestI.cpp +++ b/cpp/test/Ice/servantLocator/TestI.cpp @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. @@ -60,6 +60,26 @@ TestI::unknownExceptionWithServantException(const Current&) throw Ice::ObjectNotExistException(__FILE__, __LINE__); } +string +TestI::intfUserException(const Current&) +{ + // + // Return a value so we can be sure that the stream position + // is reset correctly if finished() throws. + // + return "Hello"; +} + +string +TestI::impossibleException(const Current&) +{ + // + // Return a value so we can be sure that the stream position + // is reset correctly if finished() throws. + // + return "Hello"; +} + void TestI::shutdown(const Current& current) { diff --git a/cpp/test/Ice/servantLocator/TestI.h b/cpp/test/Ice/servantLocator/TestI.h index 97a616dc1c2..c3df4f43389 100644 --- a/cpp/test/Ice/servantLocator/TestI.h +++ b/cpp/test/Ice/servantLocator/TestI.h @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2007 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. @@ -27,6 +27,10 @@ public: virtual void unknownExceptionWithServantException(const Ice::Current&); + virtual ::std::string intfUserException(const Ice::Current&); + + virtual ::std::string impossibleException(const Ice::Current&); + virtual void shutdown(const Ice::Current&); }; diff --git a/cpp/test/Ice/servantLocator/run.py b/cpp/test/Ice/servantLocator/run.py index 71412047e00..09196a05df0 100755 --- a/cpp/test/Ice/servantLocator/run.py +++ b/cpp/test/Ice/servantLocator/run.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # ********************************************************************** # -# Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +# Copyright (c) 2003-2007 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. |