void RcfSession::processJsonRpcRequest() { ByteBuffer readByteBuffer = getSessionState().getReadByteBuffer(); RCF_LOG_3()(this)(readByteBuffer.getLength()) << "RcfServer - received JSON-RPC packet from transport."; CurrentRcfSessionSentry guard(*this); boost::scoped_ptr<JsonRpcResponse> jsonResponsePtr; bool isOneway = false; boost::uint64_t jsonRequestId = 0; try { JsonRpcRequest jsonRequest(readByteBuffer); jsonRequestId = jsonRequest.getRequestId(); jsonResponsePtr.reset( new JsonRpcResponse(jsonRequestId) ); std::string jsonRpcName = jsonRequest.getMethodName(); isOneway = jsonRequest.isNotification(); RcfServer::JsonRpcMethod jsonRpcMethod; { ReadLock lock(mRcfServer.mStubMapMutex); RcfServer::JsonRpcMethods::iterator iter = mRcfServer.mJsonRpcMethods.find(jsonRpcName); if (iter != mRcfServer.mJsonRpcMethods.end()) { jsonRpcMethod = iter->second; } } if (jsonRpcMethod) { jsonRpcMethod(jsonRequest, *jsonResponsePtr); } else { std::string errMsg = "Unknown JSON-RPC method name: " + jsonRpcName; jsonResponsePtr->getJsonResponse()["error"] = errMsg; } } catch(...) { std::string errMsg; try { throw; } catch(const RCF::Exception & e) { errMsg = e.getErrorString(); } catch(const std::exception & e) { errMsg = e.what(); } catch(const std::string & jsonSpiritErrMsg) { errMsg = jsonSpiritErrMsg; } catch(...) { errMsg = "Caught C++ exception of unknown type."; } jsonResponsePtr.reset( new JsonRpcResponse(jsonRequestId) ); jsonResponsePtr->getJsonResponse()["result"] = json_spirit::mValue(); jsonResponsePtr->getJsonResponse()["error"] = errMsg; } setTlsRcfSessionPtr(); if (isOneway) { onWriteCompleted(); } else { json_spirit::mObject & obj = jsonResponsePtr->getJsonResponse(); MemOstreamPtr osPtr = getObjectPool().getMemOstreamPtr(); json_spirit::write_stream(json_spirit::mValue(obj), *osPtr, json_spirit::pretty_print); ByteBuffer buffer(osPtr->str(), static_cast<std::size_t>(osPtr->tellp()), osPtr); ThreadLocalCached< std::vector<ByteBuffer> > tlcByteBuffers; std::vector<ByteBuffer> & buffers = tlcByteBuffers.get(); buffers.push_back(buffer); getSessionState().postWrite(buffers); } }