aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Communications/RestClient.cs29
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs94
-rw-r--r--OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs28
-rw-r--r--OpenSim/Framework/Servers/HttpServer/RestObjectPosterResponse.cs29
-rw-r--r--OpenSim/Framework/Servers/HttpServer/RestSessionService.cs61
-rw-r--r--OpenSim/Framework/Util.cs53
-rw-r--r--OpenSim/Framework/WebUtil.cs7
7 files changed, 164 insertions, 137 deletions
diff --git a/OpenSim/Framework/Communications/RestClient.cs b/OpenSim/Framework/Communications/RestClient.cs
index e556181..fb79c59 100644
--- a/OpenSim/Framework/Communications/RestClient.cs
+++ b/OpenSim/Framework/Communications/RestClient.cs
@@ -56,7 +56,7 @@ namespace OpenSim.Framework.Communications
56 /// other threads to execute, while it waits for a response from the web-service. RestClient itself can be 56 /// other threads to execute, while it waits for a response from the web-service. RestClient itself can be
57 /// invoked by the caller in either synchronous mode or asynchronous modes. 57 /// invoked by the caller in either synchronous mode or asynchronous modes.
58 /// </remarks> 58 /// </remarks>
59 public class RestClient 59 public class RestClient : IDisposable
60 { 60 {
61 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 61 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
62 62
@@ -148,6 +148,33 @@ namespace OpenSim.Framework.Communications
148 148
149 #endregion constructors 149 #endregion constructors
150 150
151
152 #region Dispose
153
154 private bool disposed = false;
155
156 public void Dispose()
157 {
158 Dispose(true);
159 GC.SuppressFinalize(this);
160 }
161
162 protected virtual void Dispose(bool disposing)
163 {
164 if (disposed)
165 return;
166
167 if (disposing)
168 {
169 _resource.Dispose();
170 }
171
172 disposed = true;
173 }
174
175 #endregion Dispose
176
177
151 /// <summary> 178 /// <summary>
152 /// Add a path element to the query, e.g. assets 179 /// Add a path element to the query, e.g. assets
153 /// </summary> 180 /// </summary>
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index b92c25b..093855c 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -832,28 +832,40 @@ namespace OpenSim.Framework.Servers.HttpServer
832 return; // never log these; they're just binary data 832 return; // never log these; they're just binary data
833 833
834 Stream inputStream = Util.Copy(request.InputStream); 834 Stream inputStream = Util.Copy(request.InputStream);
835 835 Stream innerStream = null;
836 if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip")) 836 try
837 inputStream = new GZipStream(inputStream, System.IO.Compression.CompressionMode.Decompress);
838
839 using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8))
840 { 837 {
841 string output; 838 if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip"))
842
843 if (DebugLevel == 5)
844 { 839 {
845 char[] chars = new char[WebUtil.MaxRequestDiagLength + 1]; // +1 so we know to add "..." only if needed 840 innerStream = inputStream;
846 int len = reader.Read(chars, 0, WebUtil.MaxRequestDiagLength + 1); 841 inputStream = new GZipStream(innerStream, System.IO.Compression.CompressionMode.Decompress);
847 output = new string(chars, 0, Math.Min(len, WebUtil.MaxRequestDiagLength));
848 if (len > WebUtil.MaxRequestDiagLength)
849 output += "...";
850 } 842 }
851 else 843
844 using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8))
852 { 845 {
853 output = reader.ReadToEnd(); 846 string output;
854 }
855 847
856 m_log.DebugFormat("[LOGHTTP] {0}", Util.BinaryToASCII(output)); 848 if (DebugLevel == 5)
849 {
850 char[] chars = new char[WebUtil.MaxRequestDiagLength + 1]; // +1 so we know to add "..." only if needed
851 int len = reader.Read(chars, 0, WebUtil.MaxRequestDiagLength + 1);
852 output = new string(chars, 0, Math.Min(len, WebUtil.MaxRequestDiagLength));
853 if (len > WebUtil.MaxRequestDiagLength)
854 output += "...";
855 }
856 else
857 {
858 output = reader.ReadToEnd();
859 }
860
861 m_log.DebugFormat("[LOGHTTP] {0}", Util.BinaryToASCII(output));
862 }
863 }
864 finally
865 {
866 if (innerStream != null)
867 innerStream.Dispose();
868 inputStream.Dispose();
857 } 869 }
858 } 870 }
859 871
@@ -981,19 +993,33 @@ namespace OpenSim.Framework.Servers.HttpServer
981 /// <param name="response"></param> 993 /// <param name="response"></param>
982 private byte[] HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response) 994 private byte[] HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
983 { 995 {
984 Stream requestStream = request.InputStream; 996 String requestBody;
985 997
986 if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip")) 998 Stream requestStream = request.InputStream;
987 requestStream = new GZipStream(requestStream, System.IO.Compression.CompressionMode.Decompress); 999 Stream innerStream = null;
1000 try
1001 {
1002 if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip"))
1003 {
1004 innerStream = requestStream;
1005 requestStream = new GZipStream(innerStream, System.IO.Compression.CompressionMode.Decompress);
1006 }
988 1007
989 Encoding encoding = Encoding.UTF8; 1008 using (StreamReader reader = new StreamReader(requestStream, Encoding.UTF8))
990 StreamReader reader = new StreamReader(requestStream, encoding); 1009 {
1010 requestBody = reader.ReadToEnd();
1011 }
1012 }
1013 finally
1014 {
1015 if (innerStream != null)
1016 innerStream.Dispose();
1017 requestStream.Dispose();
1018 }
991 1019
992 string requestBody = reader.ReadToEnd();
993 reader.Close();
994 requestStream.Close();
995 //m_log.Debug(requestBody); 1020 //m_log.Debug(requestBody);
996 requestBody = requestBody.Replace("<base64></base64>", ""); 1021 requestBody = requestBody.Replace("<base64></base64>", "");
1022
997 string responseString = String.Empty; 1023 string responseString = String.Empty;
998 XmlRpcRequest xmlRprcRequest = null; 1024 XmlRpcRequest xmlRprcRequest = null;
999 1025
@@ -1089,18 +1115,16 @@ namespace OpenSim.Framework.Servers.HttpServer
1089 1115
1090 response.ContentType = "text/xml"; 1116 response.ContentType = "text/xml";
1091 using (MemoryStream outs = new MemoryStream()) 1117 using (MemoryStream outs = new MemoryStream())
1118 using (XmlTextWriter writer = new XmlTextWriter(outs, Encoding.UTF8))
1092 { 1119 {
1093 using (XmlTextWriter writer = new XmlTextWriter(outs, Encoding.UTF8)) 1120 writer.Formatting = Formatting.None;
1121 XmlRpcResponseSerializer.Singleton.Serialize(writer, xmlRpcResponse);
1122 writer.Flush();
1123 outs.Flush();
1124 outs.Position = 0;
1125 using (StreamReader sr = new StreamReader(outs))
1094 { 1126 {
1095 writer.Formatting = Formatting.None; 1127 responseString = sr.ReadToEnd();
1096 XmlRpcResponseSerializer.Singleton.Serialize(writer, xmlRpcResponse);
1097 writer.Flush();
1098 outs.Flush();
1099 outs.Position = 0;
1100 using (StreamReader sr = new StreamReader(outs))
1101 {
1102 responseString = sr.ReadToEnd();
1103 }
1104 } 1128 }
1105 } 1129 }
1106 } 1130 }
diff --git a/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs b/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs
index 48ced19..afe052f 100644
--- a/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs
+++ b/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs
@@ -52,23 +52,25 @@ namespace OpenSim.Framework.Servers.HttpServer
52 request.Method = verb; 52 request.Method = verb;
53 request.ContentType = "text/xml"; 53 request.ContentType = "text/xml";
54 54
55 MemoryStream buffer = new MemoryStream(); 55 using (MemoryStream buffer = new MemoryStream())
56 {
57 XmlWriterSettings settings = new XmlWriterSettings();
58 settings.Encoding = Encoding.UTF8;
56 59
57 XmlWriterSettings settings = new XmlWriterSettings(); 60 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
58 settings.Encoding = Encoding.UTF8; 61 {
62 XmlSerializer serializer = new XmlSerializer(type);
63 serializer.Serialize(writer, obj);
64 writer.Flush();
65 }
59 66
60 using (XmlWriter writer = XmlWriter.Create(buffer, settings)) 67 int length = (int)buffer.Length;
61 { 68 request.ContentLength = length;
62 XmlSerializer serializer = new XmlSerializer(type);
63 serializer.Serialize(writer, obj);
64 writer.Flush();
65 }
66 69
67 int length = (int) buffer.Length; 70 using (Stream requestStream = request.GetRequestStream())
68 request.ContentLength = length; 71 requestStream.Write(buffer.ToArray(), 0, length);
72 }
69 73
70 Stream requestStream = request.GetRequestStream();
71 requestStream.Write(buffer.ToArray(), 0, length);
72 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); 74 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
73 request.BeginGetResponse(AsyncCallback, request); 75 request.BeginGetResponse(AsyncCallback, request);
74 } 76 }
diff --git a/OpenSim/Framework/Servers/HttpServer/RestObjectPosterResponse.cs b/OpenSim/Framework/Servers/HttpServer/RestObjectPosterResponse.cs
index 451745c..a911b9f 100644
--- a/OpenSim/Framework/Servers/HttpServer/RestObjectPosterResponse.cs
+++ b/OpenSim/Framework/Servers/HttpServer/RestObjectPosterResponse.cs
@@ -60,24 +60,25 @@ namespace OpenSim.Framework.Servers.HttpServer
60 request.ContentType = "text/xml"; 60 request.ContentType = "text/xml";
61 request.Timeout = 10000; 61 request.Timeout = 10000;
62 62
63 MemoryStream buffer = new MemoryStream(); 63 using (MemoryStream buffer = new MemoryStream())
64 {
65 XmlWriterSettings settings = new XmlWriterSettings();
66 settings.Encoding = Encoding.UTF8;
67
68 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
69 {
70 XmlSerializer serializer = new XmlSerializer(type);
71 serializer.Serialize(writer, obj);
72 writer.Flush();
73 }
64 74
65 XmlWriterSettings settings = new XmlWriterSettings(); 75 int length = (int)buffer.Length;
66 settings.Encoding = Encoding.UTF8; 76 request.ContentLength = length;
67 77
68 using (XmlWriter writer = XmlWriter.Create(buffer, settings)) 78 using (Stream requestStream = request.GetRequestStream())
69 { 79 requestStream.Write(buffer.ToArray(), 0, length);
70 XmlSerializer serializer = new XmlSerializer(type);
71 serializer.Serialize(writer, obj);
72 writer.Flush();
73 } 80 }
74 81
75 int length = (int) buffer.Length;
76 request.ContentLength = length;
77
78 Stream requestStream = request.GetRequestStream();
79 requestStream.Write(buffer.ToArray(), 0, length);
80 requestStream.Close();
81 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); 82 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
82 request.BeginGetResponse(AsyncCallback, request); 83 request.BeginGetResponse(AsyncCallback, request);
83 } 84 }
diff --git a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
index 83c9848..ad69cd2 100644
--- a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
+++ b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
@@ -77,25 +77,24 @@ namespace OpenSim.Framework.Servers.HttpServer
77 request.ContentType = "text/xml"; 77 request.ContentType = "text/xml";
78 request.Timeout = 20000; 78 request.Timeout = 20000;
79 79
80 MemoryStream buffer = new MemoryStream(); 80 using (MemoryStream buffer = new MemoryStream())
81
82 XmlWriterSettings settings = new XmlWriterSettings();
83 settings.Encoding = Encoding.UTF8;
84
85 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
86 { 81 {
87 XmlSerializer serializer = new XmlSerializer(type); 82 XmlWriterSettings settings = new XmlWriterSettings();
88 serializer.Serialize(writer, sobj); 83 settings.Encoding = Encoding.UTF8;
89 writer.Flush();
90 }
91 84
92 int length = (int)buffer.Length; 85 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
93 request.ContentLength = length; 86 {
87 XmlSerializer serializer = new XmlSerializer(type);
88 serializer.Serialize(writer, sobj);
89 writer.Flush();
90 }
91
92 int length = (int)buffer.Length;
93 request.ContentLength = length;
94 94
95 Stream requestStream = request.GetRequestStream(); 95 using (Stream requestStream = request.GetRequestStream())
96 requestStream.Write(buffer.ToArray(), 0, length); 96 requestStream.Write(buffer.ToArray(), 0, length);
97 buffer.Close(); 97 }
98 requestStream.Close();
99 98
100 TResponse deserial = default(TResponse); 99 TResponse deserial = default(TResponse);
101 using (WebResponse resp = request.GetResponse()) 100 using (WebResponse resp = request.GetResponse())
@@ -133,25 +132,25 @@ namespace OpenSim.Framework.Servers.HttpServer
133 request.ContentType = "text/xml"; 132 request.ContentType = "text/xml";
134 request.Timeout = 10000; 133 request.Timeout = 10000;
135 134
136 MemoryStream buffer = new MemoryStream(); 135 using (MemoryStream buffer = new MemoryStream())
136 {
137 XmlWriterSettings settings = new XmlWriterSettings();
138 settings.Encoding = Encoding.UTF8;
139
140 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
141 {
142 XmlSerializer serializer = new XmlSerializer(type);
143 serializer.Serialize(writer, sobj);
144 writer.Flush();
145 }
137 146
138 XmlWriterSettings settings = new XmlWriterSettings(); 147 int length = (int)buffer.Length;
139 settings.Encoding = Encoding.UTF8; 148 request.ContentLength = length;
140 149
141 using (XmlWriter writer = XmlWriter.Create(buffer, settings)) 150 using (Stream requestStream = request.GetRequestStream())
142 { 151 requestStream.Write(buffer.ToArray(), 0, length);
143 XmlSerializer serializer = new XmlSerializer(type);
144 serializer.Serialize(writer, sobj);
145 writer.Flush();
146 } 152 }
147 buffer.Close();
148
149 int length = (int)buffer.Length;
150 request.ContentLength = length;
151 153
152 Stream requestStream = request.GetRequestStream();
153 requestStream.Write(buffer.ToArray(), 0, length);
154 requestStream.Close();
155 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); 154 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
156 request.BeginGetResponse(AsyncCallback, request); 155 request.BeginGetResponse(AsyncCallback, request);
157 } 156 }
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 9d7de97..5c429ee 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -509,6 +509,19 @@ namespace OpenSim.Framework
509 return sb.ToString(); 509 return sb.ToString();
510 } 510 }
511 511
512 public static byte[] DocToBytes(XmlDocument doc)
513 {
514 using (MemoryStream ms = new MemoryStream())
515 using (XmlTextWriter xw = new XmlTextWriter(ms, null))
516 {
517 xw.Formatting = Formatting.Indented;
518 doc.WriteTo(xw);
519 xw.Flush();
520
521 return ms.ToArray();
522 }
523 }
524
512 /// <summary> 525 /// <summary>
513 /// Is the platform Windows? 526 /// Is the platform Windows?
514 /// </summary> 527 /// </summary>
@@ -1307,46 +1320,6 @@ namespace OpenSim.Framework
1307 return ret; 1320 return ret;
1308 } 1321 }
1309 1322
1310 public static string Compress(string text)
1311 {
1312 byte[] buffer = Util.UTF8.GetBytes(text);
1313 MemoryStream memory = new MemoryStream();
1314 using (GZipStream compressor = new GZipStream(memory, CompressionMode.Compress, true))
1315 {
1316 compressor.Write(buffer, 0, buffer.Length);
1317 }
1318
1319 memory.Position = 0;
1320
1321 byte[] compressed = new byte[memory.Length];
1322 memory.Read(compressed, 0, compressed.Length);
1323
1324 byte[] compressedBuffer = new byte[compressed.Length + 4];
1325 Buffer.BlockCopy(compressed, 0, compressedBuffer, 4, compressed.Length);
1326 Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, compressedBuffer, 0, 4);
1327 return Convert.ToBase64String(compressedBuffer);
1328 }
1329
1330 public static string Decompress(string compressedText)
1331 {
1332 byte[] compressedBuffer = Convert.FromBase64String(compressedText);
1333 using (MemoryStream memory = new MemoryStream())
1334 {
1335 int msgLength = BitConverter.ToInt32(compressedBuffer, 0);
1336 memory.Write(compressedBuffer, 4, compressedBuffer.Length - 4);
1337
1338 byte[] buffer = new byte[msgLength];
1339
1340 memory.Position = 0;
1341 using (GZipStream decompressor = new GZipStream(memory, CompressionMode.Decompress))
1342 {
1343 decompressor.Read(buffer, 0, buffer.Length);
1344 }
1345
1346 return Util.UTF8.GetString(buffer);
1347 }
1348 }
1349
1350 /// <summary> 1323 /// <summary>
1351 /// Copy data from one stream to another, leaving the read position of both streams at the beginning. 1324 /// Copy data from one stream to another, leaving the read position of both streams at the beginning.
1352 /// </summary> 1325 /// </summary>
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index e614fd5..d683152 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -176,7 +176,8 @@ namespace OpenSim.Framework
176 176
177 public static void LogOutgoingDetail(string context, Stream outputStream) 177 public static void LogOutgoingDetail(string context, Stream outputStream)
178 { 178 {
179 using (StreamReader reader = new StreamReader(Util.Copy(outputStream), Encoding.UTF8)) 179 using (Stream stream = Util.Copy(outputStream))
180 using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
180 { 181 {
181 string output; 182 string output;
182 183
@@ -262,12 +263,12 @@ namespace OpenSim.Framework
262 263
263 using (MemoryStream ms = new MemoryStream()) 264 using (MemoryStream ms = new MemoryStream())
264 { 265 {
265 using (GZipStream comp = new GZipStream(ms, CompressionMode.Compress)) 266 using (GZipStream comp = new GZipStream(ms, CompressionMode.Compress, true))
266 { 267 {
267 comp.Write(buffer, 0, buffer.Length); 268 comp.Write(buffer, 0, buffer.Length);
268 // We need to close the gzip stream before we write it anywhere 269 // We need to close the gzip stream before we write it anywhere
269 // because apparently something important related to gzip compression 270 // because apparently something important related to gzip compression
270 // gets written on the strteam upon Dispose() 271 // gets written on the stream upon Dispose()
271 } 272 }
272 byte[] buf = ms.ToArray(); 273 byte[] buf = ms.ToArray();
273 request.ContentLength = buf.Length; //Count bytes to send 274 request.ContentLength = buf.Length; //Count bytes to send