diff options
author | Melanie | 2009-10-05 10:17:23 +0100 |
---|---|---|
committer | Melanie | 2009-10-05 10:17:23 +0100 |
commit | 0744292b479446eb1ebec828afafacc0189709ca (patch) | |
tree | 3c43b5f425aff61d3625b75b7aef35ce5062ae56 /OpenSim/Framework/Servers/HttpServer | |
parent | Merge branch 'master' into vehicles (diff) | |
parent | Make the asset connector async Get overload return false if the asset (diff) | |
download | opensim-SC_OLD-0744292b479446eb1ebec828afafacc0189709ca.zip opensim-SC_OLD-0744292b479446eb1ebec828afafacc0189709ca.tar.gz opensim-SC_OLD-0744292b479446eb1ebec828afafacc0189709ca.tar.bz2 opensim-SC_OLD-0744292b479446eb1ebec828afafacc0189709ca.tar.xz |
Merge branch 'master' into vehicles
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer')
5 files changed, 92 insertions, 17 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs index 5afa110..03c12dd 100644 --- a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs | |||
@@ -91,24 +91,35 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
91 | Stream requestStream = request.EndGetRequestStream(res); | 91 | Stream requestStream = request.EndGetRequestStream(res); |
92 | 92 | ||
93 | requestStream.Write(buffer.ToArray(), 0, length); | 93 | requestStream.Write(buffer.ToArray(), 0, length); |
94 | requestStream.Close(); | ||
94 | 95 | ||
95 | request.BeginGetResponse(delegate(IAsyncResult ar) | 96 | request.BeginGetResponse(delegate(IAsyncResult ar) |
96 | { | 97 | { |
97 | response = request.EndGetResponse(ar); | 98 | response = request.EndGetResponse(ar); |
98 | 99 | Stream respStream = null; | |
99 | try | 100 | try |
100 | { | 101 | { |
101 | deserial = (TResponse) deserializer.Deserialize( | 102 | respStream = response.GetResponseStream(); |
102 | response.GetResponseStream()); | 103 | deserial = (TResponse)deserializer.Deserialize( |
104 | respStream); | ||
103 | } | 105 | } |
104 | catch (System.InvalidOperationException) | 106 | catch (System.InvalidOperationException) |
105 | { | 107 | { |
106 | } | 108 | } |
109 | finally | ||
110 | { | ||
111 | // Let's not close this | ||
112 | //buffer.Close(); | ||
113 | respStream.Close(); | ||
114 | response.Close(); | ||
115 | } | ||
107 | 116 | ||
108 | action(deserial); | 117 | action(deserial); |
118 | |||
109 | }, null); | 119 | }, null); |
110 | }, null); | 120 | }, null); |
111 | 121 | ||
122 | |||
112 | return; | 123 | return; |
113 | } | 124 | } |
114 | 125 | ||
@@ -119,14 +130,21 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
119 | // If the server returns a 404, this appears to trigger a System.Net.WebException even though that isn't | 130 | // If the server returns a 404, this appears to trigger a System.Net.WebException even though that isn't |
120 | // documented in MSDN | 131 | // documented in MSDN |
121 | response = request.EndGetResponse(res2); | 132 | response = request.EndGetResponse(res2); |
122 | 133 | ||
134 | Stream respStream = null; | ||
123 | try | 135 | try |
124 | { | 136 | { |
125 | deserial = (TResponse)deserializer.Deserialize(response.GetResponseStream()); | 137 | respStream = response.GetResponseStream(); |
138 | deserial = (TResponse)deserializer.Deserialize(respStream); | ||
126 | } | 139 | } |
127 | catch (System.InvalidOperationException) | 140 | catch (System.InvalidOperationException) |
128 | { | 141 | { |
129 | } | 142 | } |
143 | finally | ||
144 | { | ||
145 | respStream.Close(); | ||
146 | response.Close(); | ||
147 | } | ||
130 | } | 148 | } |
131 | catch (WebException e) | 149 | catch (WebException e) |
132 | { | 150 | { |
@@ -148,7 +166,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
148 | } | 166 | } |
149 | else | 167 | else |
150 | { | 168 | { |
151 | m_log.ErrorFormat("[ASYNC REQUEST]: Request {0} {1} failed with exception {2}", verb, requestUrl, e); | 169 | m_log.ErrorFormat("[ASYNC REQUEST]: Request {0} {1} failed with status {2} and message {3}", verb, requestUrl, e.Status, e.Message); |
152 | } | 170 | } |
153 | } | 171 | } |
154 | catch (Exception e) | 172 | catch (Exception e) |
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 6c63c6c..942fed9 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | |||
@@ -979,7 +979,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
979 | } | 979 | } |
980 | 980 | ||
981 | // response.ContentType = "application/llsd+json"; | 981 | // response.ContentType = "application/llsd+json"; |
982 | // return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(llsdResponse)); | 982 | // return Util.UTF8.GetBytes(OSDParser.SerializeJsonString(llsdResponse)); |
983 | response.ContentType = "application/llsd+xml"; | 983 | response.ContentType = "application/llsd+xml"; |
984 | return OSDParser.SerializeLLSDXmlBytes(llsdResponse); | 984 | return OSDParser.SerializeLLSDXmlBytes(llsdResponse); |
985 | } | 985 | } |
diff --git a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs index 3f72c31..7ebb462 100644 --- a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs +++ b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs | |||
@@ -94,13 +94,26 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
94 | 94 | ||
95 | Stream requestStream = request.GetRequestStream(); | 95 | Stream requestStream = request.GetRequestStream(); |
96 | requestStream.Write(buffer.ToArray(), 0, length); | 96 | requestStream.Write(buffer.ToArray(), 0, length); |
97 | buffer.Close(); | ||
97 | requestStream.Close(); | 98 | requestStream.Close(); |
99 | |||
98 | TResponse deserial = default(TResponse); | 100 | TResponse deserial = default(TResponse); |
99 | using (WebResponse resp = request.GetResponse()) | 101 | using (WebResponse resp = request.GetResponse()) |
100 | { | 102 | { |
101 | XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); | 103 | XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); |
102 | deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); | 104 | Stream respStream = null; |
103 | resp.Close(); | 105 | try |
106 | { | ||
107 | respStream = resp.GetResponseStream(); | ||
108 | deserial = (TResponse)deserializer.Deserialize(respStream); | ||
109 | } | ||
110 | catch { } | ||
111 | finally | ||
112 | { | ||
113 | if (respStream != null) | ||
114 | respStream.Close(); | ||
115 | resp.Close(); | ||
116 | } | ||
104 | } | 117 | } |
105 | return deserial; | 118 | return deserial; |
106 | } | 119 | } |
@@ -140,6 +153,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
140 | serializer.Serialize(writer, sobj); | 153 | serializer.Serialize(writer, sobj); |
141 | writer.Flush(); | 154 | writer.Flush(); |
142 | } | 155 | } |
156 | buffer.Close(); | ||
143 | 157 | ||
144 | int length = (int)buffer.Length; | 158 | int length = (int)buffer.Length; |
145 | request.ContentLength = length; | 159 | request.ContentLength = length; |
@@ -165,6 +179,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
165 | // m_log.DebugFormat("[REST OBJECT POSTER RESPONSE]: Received {0}", reader.ReadToEnd()); | 179 | // m_log.DebugFormat("[REST OBJECT POSTER RESPONSE]: Received {0}", reader.ReadToEnd()); |
166 | 180 | ||
167 | deserial = (TResponse)deserializer.Deserialize(stream); | 181 | deserial = (TResponse)deserializer.Deserialize(stream); |
182 | if (stream != null) | ||
183 | stream.Close(); | ||
168 | 184 | ||
169 | if (deserial != null && ResponseCallback != null) | 185 | if (deserial != null && ResponseCallback != null) |
170 | { | 186 | { |
diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index a0d4008..8a490f7 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | |||
@@ -66,8 +66,23 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
66 | length = (int)obj.Length; | 66 | length = (int)obj.Length; |
67 | request.ContentLength = length; | 67 | request.ContentLength = length; |
68 | 68 | ||
69 | Stream requestStream = request.GetRequestStream(); | 69 | Stream requestStream = null; |
70 | requestStream.Write(buffer.ToArray(), 0, length); | 70 | try |
71 | { | ||
72 | requestStream = request.GetRequestStream(); | ||
73 | requestStream.Write(buffer.ToArray(), 0, length); | ||
74 | } | ||
75 | catch | ||
76 | { | ||
77 | } | ||
78 | finally | ||
79 | { | ||
80 | if (requestStream != null) | ||
81 | requestStream.Close(); | ||
82 | // Let's not close this | ||
83 | //buffer.Close(); | ||
84 | |||
85 | } | ||
71 | } | 86 | } |
72 | 87 | ||
73 | string respstring = String.Empty; | 88 | string respstring = String.Empty; |
@@ -78,9 +93,20 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
78 | { | 93 | { |
79 | if (resp.ContentLength > 0) | 94 | if (resp.ContentLength > 0) |
80 | { | 95 | { |
81 | using (StreamReader reader = new StreamReader(resp.GetResponseStream())) | 96 | Stream respStream = null; |
97 | try | ||
98 | { | ||
99 | respStream = resp.GetResponseStream(); | ||
100 | using (StreamReader reader = new StreamReader(respStream)) | ||
101 | { | ||
102 | respstring = reader.ReadToEnd(); | ||
103 | } | ||
104 | } | ||
105 | catch { } | ||
106 | finally | ||
82 | { | 107 | { |
83 | respstring = reader.ReadToEnd(); | 108 | if (respStream != null) |
109 | respStream.Close(); | ||
84 | } | 110 | } |
85 | } | 111 | } |
86 | } | 112 | } |
diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs index ec9bd4f..eab463c 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs | |||
@@ -58,6 +58,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
58 | public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj) | 58 | public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj) |
59 | { | 59 | { |
60 | Type type = typeof (TRequest); | 60 | Type type = typeof (TRequest); |
61 | TResponse deserial = default(TResponse); | ||
61 | 62 | ||
62 | WebRequest request = WebRequest.Create(requestUrl); | 63 | WebRequest request = WebRequest.Create(requestUrl); |
63 | request.Method = verb; | 64 | request.Method = verb; |
@@ -81,19 +82,33 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
81 | int length = (int) buffer.Length; | 82 | int length = (int) buffer.Length; |
82 | request.ContentLength = length; | 83 | request.ContentLength = length; |
83 | 84 | ||
84 | Stream requestStream = request.GetRequestStream(); | 85 | Stream requestStream = null; |
85 | requestStream.Write(buffer.ToArray(), 0, length); | 86 | try |
87 | { | ||
88 | requestStream = request.GetRequestStream(); | ||
89 | requestStream.Write(buffer.ToArray(), 0, length); | ||
90 | } | ||
91 | catch (Exception) | ||
92 | { | ||
93 | return deserial; | ||
94 | } | ||
95 | finally | ||
96 | { | ||
97 | if (requestStream != null) | ||
98 | requestStream.Close(); | ||
99 | } | ||
86 | } | 100 | } |
87 | 101 | ||
88 | TResponse deserial = default(TResponse); | ||
89 | try | 102 | try |
90 | { | 103 | { |
91 | using (WebResponse resp = request.GetResponse()) | 104 | using (WebResponse resp = request.GetResponse()) |
92 | { | 105 | { |
93 | if (resp.ContentLength > 0) | 106 | if (resp.ContentLength > 0) |
94 | { | 107 | { |
108 | Stream respStream = resp.GetResponseStream(); | ||
95 | XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); | 109 | XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); |
96 | deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); | 110 | deserial = (TResponse)deserializer.Deserialize(respStream); |
111 | respStream.Close(); | ||
97 | } | 112 | } |
98 | } | 113 | } |
99 | } | 114 | } |