summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/Ice/DispatchInterceptor.cpp13
-rw-r--r--cpp/src/Ice/Incoming.cpp2
-rw-r--r--cpp/test/Ice/interceptor/AMDInterceptorI.cpp38
-rw-r--r--cpp/test/Ice/interceptor/Client.cpp55
-rw-r--r--cpp/test/Ice/interceptor/InterceptorI.cpp39
5 files changed, 145 insertions, 2 deletions
diff --git a/cpp/src/Ice/DispatchInterceptor.cpp b/cpp/src/Ice/DispatchInterceptor.cpp
index 10457e990e9..ae12e77f900 100644
--- a/cpp/src/Ice/DispatchInterceptor.cpp
+++ b/cpp/src/Ice/DispatchInterceptor.cpp
@@ -21,4 +21,17 @@ Ice::DispatchInterceptor::_iceDispatch(IceInternal::Incoming& in, const Current&
{
return false;
}
+ catch(const std::exception&)
+ {
+ //
+ // 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(in.getCurrent().encoding.major == 0 && in.getCurrent().encoding.minor == 0)
+ {
+ in.skipReadParams();
+ }
+ throw;
+ }
}
diff --git a/cpp/src/Ice/Incoming.cpp b/cpp/src/Ice/Incoming.cpp
index 1fce4e5f107..b7cc91488d2 100644
--- a/cpp/src/Ice/Incoming.cpp
+++ b/cpp/src/Ice/Incoming.cpp
@@ -59,6 +59,8 @@ IceInternal::IncomingBase::IncomingBase(Instance* instance, ResponseHandler* res
_current.con = connection;
#endif
_current.requestId = requestId;
+ _current.encoding.major = 0;
+ _current.encoding.minor = 0;
}
IceInternal::IncomingBase::IncomingBase(IncomingBase& other) :
diff --git a/cpp/test/Ice/interceptor/AMDInterceptorI.cpp b/cpp/test/Ice/interceptor/AMDInterceptorI.cpp
index 33cfb5e0b38..e2e2d95b001 100644
--- a/cpp/test/Ice/interceptor/AMDInterceptorI.cpp
+++ b/cpp/test/Ice/interceptor/AMDInterceptorI.cpp
@@ -4,7 +4,7 @@
#include <IceUtil/DisableWarnings.h>
#include <AMDInterceptorI.h>
-#include <Test.h>
+#include <MyObjectI.h>
#include <TestHelper.h>
using namespace std;
@@ -56,6 +56,24 @@ AMDInterceptorI::dispatch(Ice::Request& request)
#endif
Ice::Current& current = const_cast<Ice::Current&>(request.getCurrent());
+
+ Ice::Context::const_iterator p = current.ctx.find("raiseBeforeDispatch");
+ if(p != current.ctx.end())
+ {
+ if(p->second == "user")
+ {
+ throw Test::InvalidInputException();
+ }
+ else if(p->second == "notExist")
+ {
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ }
+ else if(p->second == "system")
+ {
+ throw MySystemException(__FILE__, __LINE__);
+ }
+ }
+
_lastOperation = current.operation;
if(_lastOperation == "amdAddWithRetry")
@@ -105,6 +123,24 @@ AMDInterceptorI::dispatch(Ice::Request& request)
#else
_lastStatus = _servant->ice_dispatch(request, _defaultCb);
#endif
+
+ p = current.ctx.find("raiseAfterDispatch");
+ if(p != current.ctx.end())
+ {
+ if(p->second == "user")
+ {
+ throw Test::InvalidInputException();
+ }
+ else if(p->second == "notExist")
+ {
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ }
+ else if(p->second == "system")
+ {
+ throw MySystemException(__FILE__, __LINE__);
+ }
+ }
+
return _lastStatus;
}
diff --git a/cpp/test/Ice/interceptor/Client.cpp b/cpp/test/Ice/interceptor/Client.cpp
index fd7c8314d26..dc93891e819 100644
--- a/cpp/test/Ice/interceptor/Client.cpp
+++ b/cpp/test/Ice/interceptor/Client.cpp
@@ -35,6 +35,7 @@ private:
void runTest(const Test::MyObjectPrxPtr&, const InterceptorIPtr&);
void runAmdTest(const Test::MyObjectPrxPtr&, const AMDInterceptorIPtr&);
+ void testInterceptorExceptions(const Test::MyObjectPrx&);
};
void
@@ -169,6 +170,10 @@ Client::runTest(const Test::MyObjectPrxPtr& prx, const InterceptorIPtr& intercep
test(interceptor->getLastOperation() == "amdAdd");
test(!interceptor->getLastStatus());
cout << "ok" << endl;
+
+ cout << "testing exceptions raised by the interceptor... " << flush;
+ testInterceptorExceptions(prx);
+ cout << "ok" << endl;
}
void
@@ -234,6 +239,56 @@ Client::runAmdTest(const Test::MyObjectPrxPtr& prx, const AMDInterceptorIPtr& in
test(!interceptor->getLastStatus());
test(dynamic_cast<MySystemException*>(interceptor->getException()) != 0);
cout << "ok" << endl;
+
+ cout << "testing exceptions raised by the interceptor... " << flush;
+ testInterceptorExceptions(prx);
+ cout << "ok" << endl;
+}
+
+void
+Client::testInterceptorExceptions(const Test::MyObjectPrx& prx)
+{
+ vector<pair<string, string> > exceptions;
+ exceptions.push_back(make_pair("raiseBeforeDispatch", "user"));
+ exceptions.push_back(make_pair("raiseBeforeDispatch", "notExist"));
+ exceptions.push_back(make_pair("raiseBeforeDispatch", "system"));
+ exceptions.push_back(make_pair("raiseAfterDispatch", "user"));
+ exceptions.push_back(make_pair("raiseAfterDispatch", "notExist"));
+ exceptions.push_back(make_pair("raiseAfterDispatch", "system"));
+ for(vector<pair<string, string> >::const_iterator p = exceptions.begin(); p != exceptions.end(); ++p)
+ {
+ Ice::Context ctx;
+ ctx[p->first] = p->second;
+ try
+ {
+ prx->ice_ping(ctx);
+ test(false);
+ }
+ catch(const Ice::UnknownUserException&)
+ {
+ test(p->second == "user");
+ }
+ catch(const Ice::ObjectNotExistException&)
+ {
+ test(p->second == "notExist");
+ }
+ catch(const Ice::UnknownException&)
+ {
+ test(p->second == "system"); // non-collocated
+ }
+ catch(const MySystemException&)
+ {
+ test(p->second == "system"); // collocated
+ }
+ {
+ 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();
}
DEFINE_TEST(Client)
diff --git a/cpp/test/Ice/interceptor/InterceptorI.cpp b/cpp/test/Ice/interceptor/InterceptorI.cpp
index 04b60f7a8f6..171aaf0c25a 100644
--- a/cpp/test/Ice/interceptor/InterceptorI.cpp
+++ b/cpp/test/Ice/interceptor/InterceptorI.cpp
@@ -3,7 +3,7 @@
//
#include <InterceptorI.h>
-#include <Test.h>
+#include <MyObjectI.h>
#include <TestHelper.h>
using namespace std;
@@ -18,6 +18,24 @@ bool
InterceptorI::dispatch(Ice::Request& request)
{
Ice::Current& current = const_cast<Ice::Current&>(request.getCurrent());
+
+ Ice::Context::const_iterator p = current.ctx.find("raiseBeforeDispatch");
+ if(p != current.ctx.end())
+ {
+ if(p->second == "user")
+ {
+ throw Test::InvalidInputException();
+ }
+ else if(p->second == "notExist")
+ {
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ }
+ else if(p->second == "system")
+ {
+ throw MySystemException(__FILE__, __LINE__);
+ }
+ }
+
_lastOperation = current.operation;
if(_lastOperation == "addWithRetry")
@@ -39,7 +57,26 @@ InterceptorI::dispatch(Ice::Request& request)
current.ctx["retry"] = "no";
}
+
_lastStatus = _servant->ice_dispatch(request);
+
+ p = current.ctx.find("raiseAfterDispatch");
+ if(p != current.ctx.end())
+ {
+ if(p->second == "user")
+ {
+ throw Test::InvalidInputException();
+ }
+ else if(p->second == "notExist")
+ {
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ }
+ else if(p->second == "system")
+ {
+ throw MySystemException(__FILE__, __LINE__);
+ }
+ }
+
return _lastStatus;
}