/* void onHttpResponseReady (in hyIHttpResponse aResponse, in hyIDataChannel aDataChannel, in nsISupports aContext); */ NS_IMETHODIMP hyPipelineHttpHandlerInstance::OnHttpResponseReady( hyIHttpResponse *aResponse, hyIHttpHeaderFields *aHeaders, hyIDataChannel *aDataChannel, nsISupports *aContext) { nsresult rv; if(mPipeline->getNextPipeline() && !isErrorResponse(aResponse)) { nsCOMPtr<hyIHttpHeaderFields> newRequestHeaders; rv = ConvertResponseToRequestHeaders( aResponse, getter_AddRefs(requestHeaders)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<hyIHttpRequestChannel> requestChannel = new hySimpleHttpRequestChannel( mRequest, newRequestHeaders, aDataChannel, aContext); rv = mNextPipeline->AcceptHttpRequestChannel( requestChannel, mHandlerListener, mHandlerContext); } else { rv = mHandlerListener->OnHttpResponseReady( aResponse, aDataChannel, mHandlerContext); } mHandlerListener.forget(); mHandlerContext.forget(); return rv; }
Json::Value SynchronousCallback::invoke ( JsonRpc * jsonRpc , std::string const & methodName , Json::Value const & params ) { SynchronousCallback callback; // Acquire the mutex. This ensures the response thread is // blocked until this thread has had a chance to start waiting // for a response QMutexLocker locker (& callback.m_mutex); // Send the request jsonRpc->invoke (methodName, params, & callback); // Start waiting for a response Json::Value const response (callback.wait ()); // Handle the response if (isErrorResponse (response)) { Json::Value const error (response["error"]); int const code (error["code"].asInt ()); std::string const message (error["message"].asString ()); Json::Value const data (error["data"]); fprintf(stderr, "Error invoking \"%s\"\n" "This may indicate mismatched " "Conveyor and MakerWare versions,\n" "check your Conveyor and MakerWare " "logs for more information.\n\n", methodName.c_str()); throw JsonRpcException (methodName, params, code, message, data); } else if (not isSuccessResponse (response)) { throw std::runtime_error("Response is not success!"); } else { Json::Value const result (response["result"]); return result; } }
bool JsonRpcPrivate::isResponse(const Json::Value &value) { return isSuccessResponse(value) || isErrorResponse(value); }