mirror of
https://github.com/opensim/opensim.git
synced 2026-08-07 01:35:46 +08:00
cosmetics
This commit is contained in:
@@ -196,28 +196,36 @@ namespace OpenSim.Framework
|
||||
|
||||
string errorMessage = "unknown error";
|
||||
int tickstart = Util.EnvironmentTickCount();
|
||||
int compsize = 0;
|
||||
string strBuffer = null;
|
||||
|
||||
int sendlen = 0;
|
||||
int rcvlen = 0;
|
||||
HttpWebRequest request = null;
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.Method = method;
|
||||
request.Timeout = timeout;
|
||||
request.KeepAlive = keepalive;
|
||||
request.MaximumAutomaticRedirections = 10;
|
||||
request.ReadWriteTimeout = timeout / 2;
|
||||
request.Headers[OSHeaderRequestID] = reqnum.ToString();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errorMessage = ex.Message;
|
||||
m_log.Debug("[WEB UTIL]: ServiceOSD error creating request " + ex.Message);
|
||||
return ErrorResponseMap(errorMessage);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// If there is some input, write it into the request
|
||||
if (data != null)
|
||||
{
|
||||
strBuffer = OSDParser.SerializeJsonString(data);
|
||||
|
||||
string strBuffer = OSDParser.SerializeJsonString(data);
|
||||
if (DebugLevel >= 5)
|
||||
LogOutgoingDetail("SEND", reqnum, strBuffer);
|
||||
LogOutgoingDetail(method, reqnum, strBuffer);
|
||||
|
||||
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);
|
||||
byte[] buffer = Util.UTF8Getbytes(strBuffer);
|
||||
|
||||
request.ContentType = rpc ? "application/json-rpc" : "application/json";
|
||||
|
||||
@@ -231,35 +239,25 @@ namespace OpenSim.Framework
|
||||
{
|
||||
comp.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
byte[] buf = ms.ToArray();
|
||||
|
||||
request.ContentLength = buf.Length; //Count bytes to send
|
||||
compsize = buf.Length;
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
requestStream.Write(buf, 0, (int)buf.Length);
|
||||
buffer = ms.ToArray();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
compsize = buffer.Length;
|
||||
|
||||
request.ContentLength = buffer.Length; //Count bytes to send
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
requestStream.Write(buffer, 0, buffer.Length); //Send it
|
||||
}
|
||||
sendlen = buffer.Length;
|
||||
request.ContentLength = buffer.Length; //Count bytes to send
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
requestStream.Write(buffer, 0, buffer.Length); //Send it
|
||||
}
|
||||
|
||||
using (WebResponse response = request.GetResponse())
|
||||
{
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(responseStream))
|
||||
{
|
||||
string responseStr = reader.ReadToEnd();
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogResponseDetail(reqnum, responseStr);
|
||||
return CanonicalizeResults(responseStr);
|
||||
}
|
||||
string responseStr = reader.ReadToEnd();
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogResponseDetail(reqnum, responseStr);
|
||||
rcvlen = responseStr.Length;
|
||||
return CanonicalizeResults(responseStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,16 +281,8 @@ namespace OpenSim.Framework
|
||||
if (tickdiff > LongCallTime)
|
||||
{
|
||||
m_log.InfoFormat(
|
||||
"[WEB UTIL]: Slow ServiceOSD request {0} {1} {2} took {3}ms, {4} bytes ({5} uncomp): {6}",
|
||||
reqnum,
|
||||
method,
|
||||
url,
|
||||
tickdiff,
|
||||
compsize,
|
||||
strBuffer != null ? strBuffer.Length : 0,
|
||||
strBuffer != null
|
||||
? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer)
|
||||
: "");
|
||||
"[WEB UTIL]: ServiceOSD request {0} {1} {2} took {3}ms, {4}/{5}bytes",
|
||||
reqnum, method, url, tickdiff, sendlen, rcvlen );
|
||||
}
|
||||
else if (DebugLevel >= 4)
|
||||
{
|
||||
@@ -301,8 +291,7 @@ namespace OpenSim.Framework
|
||||
}
|
||||
}
|
||||
|
||||
m_log.DebugFormat(
|
||||
"[LOGHTTP]: JSON-RPC request {0} {1} to {2} FAILED: {3}", reqnum, method, url, errorMessage);
|
||||
m_log.DebugFormat("[LOGHTTP]: JSON request {0} {1} to {2} FAILED: {3}", reqnum, method, url, errorMessage);
|
||||
|
||||
return ErrorResponseMap(errorMessage);
|
||||
}
|
||||
@@ -377,22 +366,30 @@ namespace OpenSim.Framework
|
||||
|
||||
string errorMessage = "unknown error";
|
||||
int tickstart = Util.EnvironmentTickCount();
|
||||
int tickdata = 0;
|
||||
string queryString = null;
|
||||
int sendlen = 0;
|
||||
int rcvlen = 0;
|
||||
|
||||
HttpWebRequest request = null;
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
|
||||
request = (HttpWebRequest)HttpWebRequest.Create(url);
|
||||
request.Method = "POST";
|
||||
request.Timeout = timeout;
|
||||
request.KeepAlive = false;
|
||||
request.MaximumAutomaticRedirections = 10;
|
||||
request.ReadWriteTimeout = timeout / 2;
|
||||
request.Headers[OSHeaderRequestID] = reqnum.ToString();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ErrorResponseMap(ex.Message);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
queryString = BuildQueryString(data);
|
||||
string queryString = BuildQueryString(data);
|
||||
|
||||
if (DebugLevel >= 5)
|
||||
LogOutgoingDetail("SEND", reqnum, queryString);
|
||||
@@ -400,29 +397,25 @@ namespace OpenSim.Framework
|
||||
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString);
|
||||
|
||||
request.ContentLength = buffer.Length;
|
||||
sendlen = buffer.Length;
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
requestStream.Write(buffer, 0, buffer.Length);
|
||||
buffer = null;
|
||||
}
|
||||
|
||||
// capture how much time was spent writing, this may seem silly
|
||||
// but with the number concurrent requests, this often blocks
|
||||
tickdata = Util.EnvironmentTickCountSubtract(tickstart);
|
||||
|
||||
using (WebResponse response = request.GetResponse())
|
||||
{
|
||||
using (Stream responseStream = response.GetResponseStream())
|
||||
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(responseStream))
|
||||
{
|
||||
string responseStr = reader.ReadToEnd();
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogResponseDetail(reqnum, responseStr);
|
||||
OSD responseOSD = OSDParser.Deserialize(responseStr);
|
||||
string responseStr = reader.ReadToEnd();
|
||||
rcvlen = responseStr.Length;
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogResponseDetail(reqnum, responseStr);
|
||||
OSD responseOSD = OSDParser.Deserialize(responseStr);
|
||||
|
||||
if (responseOSD.Type == OSDType.Map)
|
||||
return (OSDMap)responseOSD;
|
||||
}
|
||||
if (responseOSD.Type == OSDType.Map)
|
||||
return (OSDMap)responseOSD;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,16 +438,13 @@ namespace OpenSim.Framework
|
||||
if (tickdiff > LongCallTime)
|
||||
{
|
||||
m_log.InfoFormat(
|
||||
"[LOGHTTP]: Slow ServiceForm request {0} '{1}' to {2} took {3}ms, {4}ms writing, {5}",
|
||||
reqnum, method, url, tickdiff, tickdata,
|
||||
queryString != null
|
||||
? (queryString.Length > MaxRequestDiagLength) ? queryString.Remove(MaxRequestDiagLength) : queryString
|
||||
: "");
|
||||
"[LOGHTTP]: Slow ServiceForm request {0} '{1}' to {2} took {3}ms, {4}/{5}bytes",
|
||||
reqnum, method, url, tickdiff, sendlen, rcvlen);
|
||||
}
|
||||
else if (DebugLevel >= 4)
|
||||
{
|
||||
m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing",
|
||||
reqnum, tickdiff, tickdata);
|
||||
m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms",
|
||||
reqnum, tickdiff);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -779,14 +769,13 @@ namespace OpenSim.Framework
|
||||
|
||||
Type type = typeof(TRequest);
|
||||
|
||||
WebRequest request = WebRequest.Create(requestUrl);
|
||||
HttpWebRequest ht = (HttpWebRequest)request;
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl);
|
||||
|
||||
if (auth != null)
|
||||
auth.AddAuthorization(ht.Headers);
|
||||
auth.AddAuthorization(request.Headers);
|
||||
|
||||
if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections)
|
||||
ht.ServicePoint.ConnectionLimit = maxConnections;
|
||||
if (maxConnections > 0 && request.ServicePoint.ConnectionLimit < maxConnections)
|
||||
request.ServicePoint.ConnectionLimit = maxConnections;
|
||||
|
||||
TResponse deserial = default(TResponse);
|
||||
|
||||
@@ -971,29 +960,33 @@ namespace OpenSim.Framework
|
||||
reqnum, verb, requestUrl);
|
||||
|
||||
int tickstart = Util.EnvironmentTickCount();
|
||||
int tickdata = 0;
|
||||
|
||||
WebRequest request = WebRequest.Create(requestUrl);
|
||||
request.Method = verb;
|
||||
if (timeoutsecs > 0)
|
||||
request.Timeout = timeoutsecs * 1000;
|
||||
if(!keepalive && request is HttpWebRequest)
|
||||
((HttpWebRequest)request).KeepAlive = false;
|
||||
|
||||
if (auth != null)
|
||||
auth.AddAuthorization(request.Headers);
|
||||
|
||||
string respstring = String.Empty;
|
||||
|
||||
int tickset = Util.EnvironmentTickCountSubtract(tickstart);
|
||||
|
||||
if ((verb == "POST") || (verb == "PUT"))
|
||||
HttpWebRequest request = null;
|
||||
try
|
||||
{
|
||||
request = (HttpWebRequest)WebRequest.Create(requestUrl);
|
||||
request.Method = verb;
|
||||
request.AllowWriteStreamBuffering = false;
|
||||
if (timeoutsecs > 0)
|
||||
request.Timeout = timeoutsecs * 1000;
|
||||
if(!keepalive)
|
||||
request.KeepAlive = false;
|
||||
if (auth != null)
|
||||
auth.AddAuthorization(request.Headers);
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.InfoFormat("[FORMS]: Error creating {0} request to : {1}. Request: {2}", verb, requestUrl, e.Message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
int sendlen = 0;
|
||||
if (obj.Length > 0 && (verb == "POST") || (verb == "PUT"))
|
||||
{
|
||||
byte[] data = Util.UTF8NBGetbytes(obj);
|
||||
int length = data.Length;
|
||||
request.ContentLength = length;
|
||||
sendlen = data.Length;
|
||||
request.ContentLength = sendlen;
|
||||
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
|
||||
@@ -1001,63 +994,49 @@ namespace OpenSim.Framework
|
||||
try
|
||||
{
|
||||
using(Stream requestStream = request.GetRequestStream())
|
||||
requestStream.Write(data, 0, length);
|
||||
requestStream.Write(data, 0, sendlen);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.InfoFormat("[FORMS]: Error sending request to {0}: {1}. Request: {2}", requestUrl, e.Message,
|
||||
obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
|
||||
m_log.InfoFormat("[FORMS]: Error sending {0} request to: {1}. {2}", verb,requestUrl, e.Message);
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// capture how much time was spent writing
|
||||
tickdata = Util.EnvironmentTickCountSubtract(tickstart);
|
||||
data = null;
|
||||
}
|
||||
}
|
||||
|
||||
int rcvlen = 0;
|
||||
string respstring = String.Empty;
|
||||
try
|
||||
{
|
||||
using (WebResponse resp = request.GetResponse())
|
||||
{
|
||||
if (resp.ContentLength != 0)
|
||||
{
|
||||
using (Stream respStream = resp.GetResponseStream())
|
||||
using (StreamReader reader = new StreamReader(respStream))
|
||||
respstring = reader.ReadToEnd();
|
||||
using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
|
||||
respstring = reader.ReadToEnd();
|
||||
rcvlen = respstring.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.InfoFormat("[FORMS]: Error receiving response from {0}: {1}. Request: {2}", requestUrl, e.Message,
|
||||
obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
|
||||
m_log.InfoFormat("[FORMS]: Error receiving response from {0}: {1}.", requestUrl, e.Message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
|
||||
if (tickdiff > WebUtil.LongCallTime)
|
||||
{
|
||||
m_log.InfoFormat(
|
||||
"[FORMS]: Slow request {0} {1} {2} took {3}ms, {4}ms writing, {5}",
|
||||
reqnum,
|
||||
verb,
|
||||
requestUrl,
|
||||
tickdiff,
|
||||
tickset,
|
||||
tickdata,
|
||||
obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
|
||||
m_log.InfoFormat("[FORMS]: request {0} {1} {2} took {3}ms, {4)/{5}bytes",
|
||||
reqnum, verb, requestUrl, tickdiff, sendlen, rcvlen);
|
||||
}
|
||||
else if (WebUtil.DebugLevel >= 4)
|
||||
{
|
||||
m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing",
|
||||
reqnum, tickdiff, tickdata);
|
||||
m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms",
|
||||
reqnum, tickdiff);
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogResponseDetail(reqnum, respstring);
|
||||
}
|
||||
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogResponseDetail(reqnum, respstring);
|
||||
|
||||
return respstring;
|
||||
}
|
||||
|
||||
@@ -1078,23 +1057,28 @@ namespace OpenSim.Framework
|
||||
|
||||
int tickstart = Util.EnvironmentTickCount();
|
||||
|
||||
WebRequest request = WebRequest.Create(requestUrl);
|
||||
request.Method = "POST";
|
||||
if (timeoutsecs > 0)
|
||||
request.Timeout = timeoutsecs * 1000;
|
||||
if (!keepalive && request is HttpWebRequest)
|
||||
((HttpWebRequest)request).KeepAlive = false;
|
||||
|
||||
if (auth != null)
|
||||
auth.AddAuthorization(request.Headers);
|
||||
|
||||
string respstring = String.Empty;
|
||||
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
HttpWebRequest request = null;
|
||||
try
|
||||
{
|
||||
request = (HttpWebRequest)WebRequest.Create(requestUrl);
|
||||
request.Method = "POST";
|
||||
if (timeoutsecs > 0)
|
||||
request.Timeout = timeoutsecs * 1000;
|
||||
if (!keepalive)
|
||||
request.KeepAlive = false;
|
||||
if (auth != null)
|
||||
auth.AddAuthorization(request.Headers);
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.InfoFormat("[FORMS]: Error creating POST request to {0}: {1}", requestUrl, e.Message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
byte[] data = Util.UTF8NBGetbytes(obj);
|
||||
int length = data.Length;
|
||||
request.ContentLength = length;
|
||||
int sendlen = data.Length;
|
||||
request.ContentLength = sendlen;
|
||||
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
|
||||
@@ -1102,16 +1086,17 @@ namespace OpenSim.Framework
|
||||
try
|
||||
{
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
requestStream.Write(data, 0, length);
|
||||
requestStream.Write(data, 0, sendlen);
|
||||
data = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.InfoFormat("[FORMS]: Error sending request to {0}: {1}. Request: {2}", requestUrl, e.Message,
|
||||
obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
|
||||
m_log.InfoFormat("[FORMS]: Error sending POST request to {0}: {1}", requestUrl, e.Message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
string respstring = String.Empty;
|
||||
int rcvlen = 0;
|
||||
try
|
||||
{
|
||||
using (WebResponse resp = request.GetResponse())
|
||||
@@ -1126,30 +1111,24 @@ namespace OpenSim.Framework
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.InfoFormat("[FORMS]: Error receiving response from {0}: {1}. Request: {2}", requestUrl, e.Message,
|
||||
obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
|
||||
m_log.InfoFormat("[FORMS]: Error receiving response from {0}: {1}", requestUrl, e.Message);
|
||||
throw e;
|
||||
}
|
||||
|
||||
int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
|
||||
if (tickdiff > WebUtil.LongCallTime)
|
||||
{
|
||||
m_log.InfoFormat(
|
||||
"[FORMS]: Slow request {0} POST {1} took {2}ms {3}",
|
||||
reqnum,
|
||||
requestUrl,
|
||||
tickdiff,
|
||||
obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
|
||||
m_log.InfoFormat("[FORMS]: request {0} POST {1} took {2}ms {3}/{4}bytes",
|
||||
reqnum, requestUrl, tickdiff, sendlen, rcvlen);
|
||||
}
|
||||
else if (WebUtil.DebugLevel >= 4)
|
||||
{
|
||||
m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms",
|
||||
reqnum, tickdiff);
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogResponseDetail(reqnum, respstring);
|
||||
}
|
||||
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogResponseDetail(reqnum, respstring);
|
||||
|
||||
return respstring;
|
||||
}
|
||||
}
|
||||
@@ -1240,25 +1219,34 @@ namespace OpenSim.Framework
|
||||
reqnum, verb, requestUrl);
|
||||
|
||||
int tickstart = Util.EnvironmentTickCount();
|
||||
int tickdata = 0;
|
||||
|
||||
Type type = typeof(TRequest);
|
||||
TResponse deserial = default(TResponse);
|
||||
|
||||
WebRequest request = WebRequest.Create(requestUrl);
|
||||
HttpWebRequest ht = (HttpWebRequest)request;
|
||||
HttpWebRequest request = null;
|
||||
try
|
||||
{
|
||||
request = (HttpWebRequest)WebRequest.Create(requestUrl);
|
||||
|
||||
if (auth != null)
|
||||
auth.AddAuthorization(ht.Headers);
|
||||
if (auth != null)
|
||||
auth.AddAuthorization(request.Headers);
|
||||
|
||||
if (pTimeout != 0)
|
||||
request.Timeout = pTimeout;
|
||||
if (pTimeout != 0)
|
||||
request.Timeout = pTimeout;
|
||||
|
||||
if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections)
|
||||
ht.ServicePoint.ConnectionLimit = maxConnections;
|
||||
if (maxConnections > 0 && request.ServicePoint.ConnectionLimit < maxConnections)
|
||||
request.ServicePoint.ConnectionLimit = maxConnections;
|
||||
|
||||
request.Method = verb;
|
||||
MemoryStream buffer = null;
|
||||
request.AllowWriteStreamBuffering = false;
|
||||
request.Method = verb;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat("[SynchronousRestObjectRequester]: Exception in creating request {0} {1}: {2}{3}",
|
||||
verb, requestUrl, e.Message, e.StackTrace);
|
||||
return deserial;
|
||||
}
|
||||
|
||||
int sendlen = 0;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -1271,130 +1259,105 @@ namespace OpenSim.Framework
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
using (XmlWriter writer = XmlWriter.Create(ms, settings))
|
||||
{
|
||||
XmlSerializer serializer = new XmlSerializer(type);
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(TRequest));
|
||||
serializer.Serialize(writer, obj);
|
||||
writer.Flush();
|
||||
data = ms.ToArray();
|
||||
}
|
||||
|
||||
int length = data.Length;
|
||||
request.ContentLength = length;
|
||||
sendlen = data.Length;
|
||||
request.ContentLength = sendlen;
|
||||
|
||||
if (WebUtil.DebugLevel >= 5)
|
||||
WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
|
||||
|
||||
try
|
||||
{
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
requestStream.Write(data, 0, length);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat(
|
||||
"[SynchronousRestObjectRequester]: Exception in making request {0} {1}: {2}{3}",
|
||||
verb, requestUrl, e.Message, e.StackTrace);
|
||||
|
||||
return deserial;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// capture how much time was spent writing
|
||||
tickdata = Util.EnvironmentTickCountSubtract(tickstart);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
|
||||
{
|
||||
if (resp.ContentLength != 0)
|
||||
{
|
||||
using (Stream respStream = resp.GetResponseStream())
|
||||
{
|
||||
deserial = XMLResponseHelper.LogAndDeserialize<TRequest, TResponse>(
|
||||
reqnum, respStream, resp.ContentLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.DebugFormat(
|
||||
"[SynchronousRestObjectRequester]: Oops! no content found in response stream from {0} {1}",
|
||||
verb, requestUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
|
||||
{
|
||||
if (hwr != null)
|
||||
{
|
||||
if (hwr.StatusCode == HttpStatusCode.NotFound)
|
||||
return deserial;
|
||||
|
||||
if (hwr.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
m_log.ErrorFormat("[SynchronousRestObjectRequester]: Web request {0} requires authentication",
|
||||
requestUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.WarnFormat("[SynchronousRestObjectRequester]: Web request {0} returned error: {1}",
|
||||
requestUrl, hwr.StatusCode);
|
||||
}
|
||||
}
|
||||
else
|
||||
m_log.ErrorFormat(
|
||||
"[SynchronousRestObjectRequester]: WebException for {0} {1} {2} {3}",
|
||||
verb, requestUrl, typeof(TResponse).ToString(), e.Message);
|
||||
|
||||
return deserial;
|
||||
}
|
||||
}
|
||||
catch (System.InvalidOperationException)
|
||||
{
|
||||
// This is what happens when there is invalid XML
|
||||
m_log.DebugFormat(
|
||||
"[SynchronousRestObjectRequester]: Invalid XML from {0} {1} {2}",
|
||||
verb, requestUrl, typeof(TResponse).ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Debug(string.Format(
|
||||
"[SynchronousRestObjectRequester]: Exception on response from {0} {1} ",
|
||||
verb, requestUrl), e);
|
||||
}
|
||||
|
||||
int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
|
||||
if (tickdiff > WebUtil.LongCallTime)
|
||||
{
|
||||
string originalRequest = null;
|
||||
|
||||
if (buffer != null)
|
||||
{
|
||||
originalRequest = Encoding.UTF8.GetString(buffer.ToArray());
|
||||
|
||||
if (originalRequest.Length > WebUtil.MaxRequestDiagLength)
|
||||
originalRequest = originalRequest.Remove(WebUtil.MaxRequestDiagLength);
|
||||
}
|
||||
|
||||
m_log.InfoFormat(
|
||||
"[LOGHTTP]: Slow SynchronousRestObject request {0} {1} to {2} took {3}ms, {4}ms writing, {5}",
|
||||
reqnum, verb, requestUrl, tickdiff, tickdata,
|
||||
originalRequest);
|
||||
}
|
||||
else if (WebUtil.DebugLevel >= 4)
|
||||
{
|
||||
m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing",
|
||||
reqnum, tickdiff, tickdata);
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
requestStream.Write(data, 0, sendlen);
|
||||
data = null;
|
||||
}
|
||||
}
|
||||
finally
|
||||
catch (Exception e)
|
||||
{
|
||||
if (buffer != null)
|
||||
buffer.Dispose();
|
||||
m_log.DebugFormat(
|
||||
"[SynchronousRestObjectRequester]: Exception in making request {0} {1}: {2}{3}",
|
||||
verb, requestUrl, e.Message, e.StackTrace);
|
||||
|
||||
return deserial;
|
||||
}
|
||||
|
||||
|
||||
int rcvlen = 0;
|
||||
try
|
||||
{
|
||||
using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
|
||||
{
|
||||
if (resp.ContentLength != 0)
|
||||
{
|
||||
rcvlen = (int)resp.ContentLength;
|
||||
using (Stream respStream = resp.GetResponseStream())
|
||||
{
|
||||
deserial = XMLResponseHelper.LogAndDeserialize<TRequest, TResponse>(
|
||||
reqnum, respStream, resp.ContentLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.DebugFormat("[SynchronousRestObjectRequester]: Oops! no content found in response stream from {0} {1}",
|
||||
verb, requestUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
|
||||
{
|
||||
if (hwr != null)
|
||||
{
|
||||
if (hwr.StatusCode == HttpStatusCode.NotFound)
|
||||
return deserial;
|
||||
|
||||
if (hwr.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
m_log.ErrorFormat("[SynchronousRestObjectRequester]: Web request {0} requires authentication",
|
||||
requestUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.WarnFormat("[SynchronousRestObjectRequester]: Web request {0} returned error: {1}",
|
||||
requestUrl, hwr.StatusCode);
|
||||
}
|
||||
}
|
||||
else
|
||||
m_log.ErrorFormat(
|
||||
"[SynchronousRestObjectRequester]: WebException for {0} {1} {2} {3}",
|
||||
verb, requestUrl, typeof(TResponse).ToString(), e.Message);
|
||||
|
||||
return deserial;
|
||||
}
|
||||
}
|
||||
catch (System.InvalidOperationException)
|
||||
{
|
||||
// This is what happens when there is invalid XML
|
||||
m_log.DebugFormat("[SynchronousRestObjectRequester]: Invalid XML from {0} {1} {2}",
|
||||
verb, requestUrl, typeof(TResponse).ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.DebugFormat("[SynchronousRestObjectRequester]: Exception on response from {0} {1}: {2}",
|
||||
verb, requestUrl, e.Message);
|
||||
}
|
||||
|
||||
int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
|
||||
if (tickdiff > WebUtil.LongCallTime)
|
||||
{
|
||||
m_log.InfoFormat("[LOGHTTP]: Slow SynchronousRestObject request {0} {1} to {2} took {3}ms, {4}/{5}bytes",
|
||||
reqnum, verb, requestUrl, tickdiff, sendlen, rcvlen);
|
||||
}
|
||||
else if (WebUtil.DebugLevel >= 4)
|
||||
{
|
||||
m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms",
|
||||
reqnum, tickdiff);
|
||||
}
|
||||
return deserial;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user