30 using System.Net.Sockets;
31 using System.Reflection;
34 using OpenMetaverse.StructuredData;
38 namespace OpenSim.Framework.Servers.HttpServer
45 static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
69 public bool JsonRpcRequest(ref
object parameters,
string method,
string uri,
string jsonId)
72 throw new ArgumentNullException(
"jsonId");
74 throw new ArgumentNullException(
"uri");
76 throw new ArgumentNullException(
"method");
77 if (parameters == null)
78 throw new ArgumentNullException(
"parameters");
81 request.Add(
"jsonrpc", OSD.FromString(
"2.0"));
82 request.Add(
"id", OSD.FromString(jsonId));
83 request.Add(
"method", OSD.FromString(method));
84 request.Add(
"params", OSD.SerializeMembers(parameters));
89 response = WebUtil.PostToService(uri, request, 10000,
true);
93 m_log.Debug(string.Format(
"JsonRpc request '{0}' to {1} failed", method, uri), e);
97 if (!response.ContainsKey(
"_Result"))
99 m_log.DebugFormat(
"JsonRpc request '{0}' to {1} returned an invalid response: {2}",
100 method, uri, OSDParser.SerializeJsonString(response));
103 response = (
OSDMap)response[
"_Result"];
107 if (response.ContainsKey(
"error"))
109 data = response[
"error"];
110 m_log.DebugFormat(
"JsonRpc request '{0}' to {1} returned an error: {2}",
111 method, uri, OSDParser.SerializeJsonString(data));
115 if (!response.ContainsKey(
"result"))
117 m_log.DebugFormat(
"JsonRpc request '{0}' to {1} returned an invalid response: {2}",
118 method, uri, OSDParser.SerializeJsonString(response));
122 data = response[
"result"];
123 OSD.DeserializeMembers(ref parameters, (
OSDMap)data);
148 if (
string.IsNullOrEmpty(jsonId))
149 jsonId = UUID.Random().ToString();
152 request.Add(
"jsonrpc", OSD.FromString(
"2.0"));
153 request.Add(
"id", OSD.FromString(jsonId));
154 request.Add(
"method", OSD.FromString(method));
155 request.Add(
"params", data);
160 response = WebUtil.PostToService(uri, request, 10000,
true);
164 m_log.Debug(string.Format(
"JsonRpc request '{0}' to {1} failed", method, uri), e);
168 if (!response.ContainsKey(
"_Result"))
170 m_log.DebugFormat(
"JsonRpc request '{0}' to {1} returned an invalid response: {2}",
171 method, uri, OSDParser.SerializeJsonString(response));
174 response = (
OSDMap)response[
"_Result"];
176 if (response.ContainsKey(
"error"))
178 data = response[
"error"];
179 m_log.DebugFormat(
"JsonRpc request '{0}' to {1} returned an error: {2}",
180 method, uri, OSDParser.SerializeJsonString(data));
OpenMetaverse.StructuredData.OSDMap OSDMap
Json rpc request manager.
OpenMetaverse.StructuredData.OSD OSD
bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
Sends json-rpc request with a serializable type.
bool JsonRpcRequest(ref OSD data, string method, string uri, string jsonId)
Sends json-rpc request with OSD parameter.