aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs
diff options
context:
space:
mode:
authorDiva Canto2011-04-12 20:24:28 -0700
committerDiva Canto2011-04-12 20:24:28 -0700
commit7592a033df4f81ba985e1d6f57ad0ef488dc5745 (patch)
tree14969e6c75d9dc08e517e4a26429b5fd84bdd034 /OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs
parentImplemented terrain save-tile command. Does the opposite of load-tile. For no... (diff)
downloadopensim-SC-7592a033df4f81ba985e1d6f57ad0ef488dc5745.zip
opensim-SC-7592a033df4f81ba985e1d6f57ad0ef488dc5745.tar.gz
opensim-SC-7592a033df4f81ba985e1d6f57ad0ef488dc5745.tar.bz2
opensim-SC-7592a033df4f81ba985e1d6f57ad0ef488dc5745.tar.xz
Moved 3 request handlers from OpenSim.Framework.Servers.HttpServer up to OpenSim.Framework -- just pasted them in WebUtil. This is so that code that uses the Service connectors don't need to include the HttpServer dll -- that was odd.
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs122
1 files changed, 0 insertions, 122 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs
deleted file mode 100644
index eab463c..0000000
--- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs
+++ /dev/null
@@ -1,122 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.IO;
30using System.Net;
31using System.Text;
32using System.Xml;
33using System.Xml.Serialization;
34
35namespace OpenSim.Framework.Servers.HttpServer
36{
37 public class SynchronousRestObjectPoster
38 {
39 [Obsolete]
40 public static TResponse BeginPostObject<TRequest, TResponse>(string verb, string requestUrl, TRequest obj)
41 {
42 return SynchronousRestObjectRequester.MakeRequest<TRequest, TResponse>(verb, requestUrl, obj);
43 }
44 }
45
46 public class SynchronousRestObjectRequester
47 {
48 /// <summary>
49 /// Perform a synchronous REST request.
50 /// </summary>
51 /// <param name="verb"></param>
52 /// <param name="requestUrl"></param>
53 /// <param name="obj"> </param>
54 /// <returns></returns>
55 ///
56 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting
57 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception>
58 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj)
59 {
60 Type type = typeof (TRequest);
61 TResponse deserial = default(TResponse);
62
63 WebRequest request = WebRequest.Create(requestUrl);
64 request.Method = verb;
65
66 if ((verb == "POST") || (verb == "PUT"))
67 {
68 request.ContentType = "text/xml";
69
70 MemoryStream buffer = new MemoryStream();
71
72 XmlWriterSettings settings = new XmlWriterSettings();
73 settings.Encoding = Encoding.UTF8;
74
75 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
76 {
77 XmlSerializer serializer = new XmlSerializer(type);
78 serializer.Serialize(writer, obj);
79 writer.Flush();
80 }
81
82 int length = (int) buffer.Length;
83 request.ContentLength = length;
84
85 Stream requestStream = null;
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 }
100 }
101
102 try
103 {
104 using (WebResponse resp = request.GetResponse())
105 {
106 if (resp.ContentLength > 0)
107 {
108 Stream respStream = resp.GetResponseStream();
109 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
110 deserial = (TResponse)deserializer.Deserialize(respStream);
111 respStream.Close();
112 }
113 }
114 }
115 catch (System.InvalidOperationException)
116 {
117 // This is what happens when there is invalid XML
118 }
119 return deserial;
120 }
121 }
122}