When sending JSON-RPC calls (for UserProfile), use WebUtil instead of constructing the HTTP requests manually. This allows the calls to be logged when using "debug http all 6".

0.8.0.3
Oren Hurvitz 2014-04-24 14:19:03 +03:00
parent 6efc203ce8
commit d15a3b10a3
5 changed files with 92 additions and 124 deletions

View File

@ -634,8 +634,6 @@ namespace OpenSim.Data.MySQL
{ {
if(reader.HasRows) if(reader.HasRows)
{ {
m_log.DebugFormat("[PROFILES_DATA]" +
": Getting data for {0}.", props.UserId);
reader.Read(); reader.Read();
props.WebUrl = (string)reader["profileURL"]; props.WebUrl = (string)reader["profileURL"];
UUID.TryParse((string)reader["profileImage"], out props.ImageId); UUID.TryParse((string)reader["profileImage"], out props.ImageId);
@ -651,9 +649,6 @@ namespace OpenSim.Data.MySQL
} }
else else
{ {
m_log.DebugFormat("[PROFILES_DATA]" +
": No data for {0}", props.UserId);
props.WebUrl = string.Empty; props.WebUrl = string.Empty;
props.ImageId = UUID.Zero; props.ImageId = UUID.Zero;
props.AboutText = string.Empty; props.AboutText = string.Empty;

View File

@ -584,9 +584,6 @@ namespace OpenSim.Data.SQLite
} }
if(reader != null && reader.Read()) if(reader != null && reader.Read())
{ {
m_log.DebugFormat("[PROFILES_DATA]" +
": Getting data for {0}.", props.UserId);
props.WebUrl = (string)reader["profileURL"]; props.WebUrl = (string)reader["profileURL"];
UUID.TryParse((string)reader["profileImage"], out props.ImageId); UUID.TryParse((string)reader["profileImage"], out props.ImageId);
props.AboutText = (string)reader["profileAboutText"]; props.AboutText = (string)reader["profileAboutText"];
@ -601,9 +598,6 @@ namespace OpenSim.Data.SQLite
} }
else else
{ {
m_log.DebugFormat("[PROFILES_DATA]" +
": No data for {0}", props.UserId);
props.WebUrl = string.Empty; props.WebUrl = string.Empty;
props.ImageId = UUID.Zero; props.ImageId = UUID.Zero;
props.AboutText = string.Empty; props.AboutText = string.Empty;

View File

@ -48,7 +48,6 @@ namespace OpenSim.Framework.Servers.HttpServer
{ {
} }
#region Web Util
/// <summary> /// <summary>
/// Sends json-rpc request with a serializable type. /// Sends json-rpc request with a serializable type.
/// </summary> /// </summary>
@ -70,63 +69,61 @@ namespace OpenSim.Framework.Servers.HttpServer
public bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId) public bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
{ {
if (jsonId == null) if (jsonId == null)
throw new ArgumentNullException ("jsonId"); throw new ArgumentNullException("jsonId");
if (uri == null) if (uri == null)
throw new ArgumentNullException ("uri"); throw new ArgumentNullException("uri");
if (method == null) if (method == null)
throw new ArgumentNullException ("method"); throw new ArgumentNullException("method");
if (parameters == null) if (parameters == null)
throw new ArgumentNullException ("parameters"); throw new ArgumentNullException("parameters");
// Prep our payload OSDMap request = new OSDMap();
OSDMap json = new OSDMap(); request.Add("jsonrpc", OSD.FromString("2.0"));
request.Add("id", OSD.FromString(jsonId));
request.Add("method", OSD.FromString(method));
request.Add("params", OSD.SerializeMembers(parameters));
json.Add("jsonrpc", OSD.FromString("2.0")); OSDMap response;
json.Add("id", OSD.FromString(jsonId));
json.Add("method", OSD.FromString(method));
json.Add("params", OSD.SerializeMembers(parameters));
string jsonRequestData = OSDParser.SerializeJsonString(json);
byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
webRequest.ContentType = "application/json-rpc";
webRequest.Method = "POST";
//Stream dataStream = webRequest.GetRequestStream();
//dataStream.Write(content, 0, content.Length);
//dataStream.Close();
using (Stream dataStream = webRequest.GetRequestStream())
dataStream.Write(content, 0, content.Length);
WebResponse webResponse = null;
try try
{ {
webResponse = webRequest.GetResponse(); response = WebUtil.PostToService(uri, request, 10000, true);
} }
catch (WebException e) catch (Exception e)
{ {
Console.WriteLine("Web Error" + e.Message); m_log.Debug(string.Format("JsonRpc request '{0}' failed", method), e);
Console.WriteLine ("Please check input");
return false; return false;
} }
using (webResponse) if (!response.ContainsKey("_Result"))
using (Stream rstream = webResponse.GetResponseStream())
{ {
OSDMap mret = (OSDMap)OSDParser.DeserializeJson(rstream); m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}",
method, OSDParser.SerializeJsonString(response));
if (mret.ContainsKey("error"))
return false; return false;
}
response = (OSDMap)response["_Result"];
OSD data;
if (response.ContainsKey("error"))
{
data = response["error"];
m_log.DebugFormat("JsonRpc request '{0}' returned an error: {1}",
method, OSDParser.SerializeJsonString(data));
return false;
}
if (!response.ContainsKey("result"))
{
m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}",
method, OSDParser.SerializeJsonString(response));
return false;
}
data = response["result"];
OSD.DeserializeMembers(ref parameters, (OSDMap)data);
// get params...
OSD.DeserializeMembers(ref parameters, (OSDMap)mret["result"]);
return true; return true;
} }
}
/// <summary> /// <summary>
/// Sends json-rpc request with OSD parameter. /// Sends json-rpc request with OSD parameter.
@ -135,7 +132,7 @@ namespace OpenSim.Framework.Servers.HttpServer
/// The rpc request. /// The rpc request.
/// </returns> /// </returns>
/// <param name='data'> /// <param name='data'>
/// data - incoming as parameters, outgong as result/error /// data - incoming as parameters, outgoing as result/error
/// </param> /// </param>
/// <param name='method'> /// <param name='method'>
/// Json-rpc method to call. /// Json-rpc method to call.
@ -148,56 +145,39 @@ namespace OpenSim.Framework.Servers.HttpServer
/// </param> /// </param>
public bool JsonRpcRequest(ref OSD data, string method, string uri, string jsonId) public bool JsonRpcRequest(ref OSD data, string method, string uri, string jsonId)
{ {
OSDMap map = new OSDMap(); if (string.IsNullOrEmpty(jsonId))
jsonId = UUID.Random().ToString();
map["jsonrpc"] = "2.0"; OSDMap request = new OSDMap();
if(string.IsNullOrEmpty(jsonId)) request.Add("jsonrpc", OSD.FromString("2.0"));
map["id"] = UUID.Random().ToString(); request.Add("id", OSD.FromString(jsonId));
else request.Add("method", OSD.FromString(method));
map["id"] = jsonId; request.Add("params", data);
map["method"] = method; OSDMap response;
map["params"] = data;
string jsonRequestData = OSDParser.SerializeJsonString(map);
byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
webRequest.ContentType = "application/json-rpc";
webRequest.Method = "POST";
using (Stream dataStream = webRequest.GetRequestStream())
dataStream.Write(content, 0, content.Length);
WebResponse webResponse = null;
try try
{ {
webResponse = webRequest.GetResponse(); response = WebUtil.PostToService(uri, request, 10000, true);
}
catch (WebException e)
{
Console.WriteLine("Web Error" + e.Message);
Console.WriteLine ("Please check input");
return false;
}
using (webResponse)
using (Stream rstream = webResponse.GetResponseStream())
{
OSDMap response = new OSDMap();
try
{
response = (OSDMap)OSDParser.DeserializeJson(rstream);
} }
catch (Exception e) catch (Exception e)
{ {
m_log.DebugFormat("[JSONRPC]: JsonRpcRequest Error {0}", e.Message); m_log.Debug(string.Format("JsonRpc request '{0}' failed", method), e);
return false; return false;
} }
if (!response.ContainsKey("_Result"))
{
m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}",
method, OSDParser.SerializeJsonString(response));
return false;
}
response = (OSDMap)response["_Result"];
if (response.ContainsKey("error")) if (response.ContainsKey("error"))
{ {
data = response["error"]; data = response["error"];
m_log.DebugFormat("JsonRpc request '{0}' returned an error: {1}",
method, OSDParser.SerializeJsonString(data));
return false; return false;
} }
@ -205,7 +185,6 @@ namespace OpenSim.Framework.Servers.HttpServer
return true; return true;
} }
}
#endregion Web Util
} }
} }

View File

@ -127,41 +127,41 @@ namespace OpenSim.Framework
/// </summary> /// </summary>
public static OSDMap PutToServiceCompressed(string url, OSDMap data, int timeout) public static OSDMap PutToServiceCompressed(string url, OSDMap data, int timeout)
{ {
return ServiceOSDRequest(url,data, "PUT", timeout, true); return ServiceOSDRequest(url,data, "PUT", timeout, true, false);
} }
public static OSDMap PutToService(string url, OSDMap data, int timeout) public static OSDMap PutToService(string url, OSDMap data, int timeout)
{ {
return ServiceOSDRequest(url,data, "PUT", timeout, false); return ServiceOSDRequest(url,data, "PUT", timeout, false, false);
} }
public static OSDMap PostToService(string url, OSDMap data, int timeout) public static OSDMap PostToService(string url, OSDMap data, int timeout, bool rpc)
{ {
return ServiceOSDRequest(url, data, "POST", timeout, false); return ServiceOSDRequest(url, data, "POST", timeout, false, rpc);
} }
public static OSDMap PostToServiceCompressed(string url, OSDMap data, int timeout) public static OSDMap PostToServiceCompressed(string url, OSDMap data, int timeout)
{ {
return ServiceOSDRequest(url, data, "POST", timeout, true); return ServiceOSDRequest(url, data, "POST", timeout, true, false);
} }
public static OSDMap GetFromService(string url, int timeout) public static OSDMap GetFromService(string url, int timeout)
{ {
return ServiceOSDRequest(url, null, "GET", timeout, false); return ServiceOSDRequest(url, null, "GET", timeout, false, false);
} }
public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout, bool compressed) public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout, bool compressed, bool rpc)
{ {
if (SerializeOSDRequestsPerEndpoint) if (SerializeOSDRequestsPerEndpoint)
{ {
lock (EndPointLock(url)) lock (EndPointLock(url))
{ {
return ServiceOSDRequestWorker(url, data, method, timeout, compressed); return ServiceOSDRequestWorker(url, data, method, timeout, compressed, rpc);
} }
} }
else else
{ {
return ServiceOSDRequestWorker(url, data, method, timeout, compressed); return ServiceOSDRequestWorker(url, data, method, timeout, compressed, rpc);
} }
} }
@ -217,7 +217,7 @@ namespace OpenSim.Framework
LogOutgoingDetail("RESPONSE: ", input); LogOutgoingDetail("RESPONSE: ", input);
} }
private static OSDMap ServiceOSDRequestWorker(string url, OSDMap data, string method, int timeout, bool compressed) private static OSDMap ServiceOSDRequestWorker(string url, OSDMap data, string method, int timeout, bool compressed, bool rpc)
{ {
int reqnum = RequestNumber++; int reqnum = RequestNumber++;
@ -251,7 +251,7 @@ namespace OpenSim.Framework
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);
request.ContentType = "application/json"; request.ContentType = rpc ? "application/json-rpc" : "application/json";
if (compressed) if (compressed)
{ {

View File

@ -136,7 +136,7 @@ namespace OpenSim.Services.Connectors.Simulation
} }
// Try the old version, uncompressed // Try the old version, uncompressed
result = WebUtil.PostToService(uri, args, 30000); result = WebUtil.PostToService(uri, args, 30000, false);
if (result["Success"].AsBoolean()) if (result["Success"].AsBoolean())
{ {
@ -302,7 +302,7 @@ namespace OpenSim.Services.Connectors.Simulation
try try
{ {
OSDMap result = WebUtil.ServiceOSDRequest(uri, request, "QUERYACCESS", 30000, false); OSDMap result = WebUtil.ServiceOSDRequest(uri, request, "QUERYACCESS", 30000, false, false);
bool success = result["success"].AsBoolean(); bool success = result["success"].AsBoolean();
if (result.ContainsKey("_Result")) if (result.ContainsKey("_Result"))
{ {
@ -365,7 +365,7 @@ namespace OpenSim.Services.Connectors.Simulation
try try
{ {
WebUtil.ServiceOSDRequest(uri, null, "DELETE", 10000, false); WebUtil.ServiceOSDRequest(uri, null, "DELETE", 10000, false, false);
} }
catch (Exception e) catch (Exception e)
{ {
@ -384,7 +384,7 @@ namespace OpenSim.Services.Connectors.Simulation
try try
{ {
WebUtil.ServiceOSDRequest(uri, null, "DELETE", 10000, false); WebUtil.ServiceOSDRequest(uri, null, "DELETE", 10000, false, false);
} }
catch (Exception e) catch (Exception e)
{ {
@ -431,7 +431,7 @@ namespace OpenSim.Services.Connectors.Simulation
args["destination_name"] = OSD.FromString(destination.RegionName); args["destination_name"] = OSD.FromString(destination.RegionName);
args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
OSDMap result = WebUtil.PostToService(uri, args, 40000); OSDMap result = WebUtil.PostToService(uri, args, 40000, false);
if (result == null) if (result == null)
return false; return false;