aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs131
1 files changed, 0 insertions, 131 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
deleted file mode 100644
index 41ece86..0000000
--- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
+++ /dev/null
@@ -1,131 +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.Reflection;
32using System.Text;
33using System.Xml;
34using System.Xml.Serialization;
35
36using log4net;
37
38namespace OpenSim.Framework.Servers.HttpServer
39{
40 public class SynchronousRestFormsRequester
41 {
42 private static readonly ILog m_log =
43 LogManager.GetLogger(
44 MethodBase.GetCurrentMethod().DeclaringType);
45
46 /// <summary>
47 /// Perform a synchronous REST request.
48 /// </summary>
49 /// <param name="verb"></param>
50 /// <param name="requestUrl"></param>
51 /// <param name="obj"> </param>
52 /// <returns></returns>
53 ///
54 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting
55 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception>
56 public static string MakeRequest(string verb, string requestUrl, string obj)
57 {
58 WebRequest request = WebRequest.Create(requestUrl);
59 request.Method = verb;
60 string respstring = String.Empty;
61
62 using (MemoryStream buffer = new MemoryStream())
63 {
64 if ((verb == "POST") || (verb == "PUT"))
65 {
66 request.ContentType = "text/www-form-urlencoded";
67
68 int length = 0;
69 using (StreamWriter writer = new StreamWriter(buffer))
70 {
71 writer.Write(obj);
72 writer.Flush();
73 }
74
75 length = (int)obj.Length;
76 request.ContentLength = length;
77
78 Stream requestStream = null;
79 try
80 {
81 requestStream = request.GetRequestStream();
82 requestStream.Write(buffer.ToArray(), 0, length);
83 }
84 catch (Exception e)
85 {
86 m_log.DebugFormat("[FORMS]: exception occured on sending request to {0}: " + e.ToString(), requestUrl);
87 }
88 finally
89 {
90 if (requestStream != null)
91 requestStream.Close();
92 }
93 }
94
95 try
96 {
97 using (WebResponse resp = request.GetResponse())
98 {
99 if (resp.ContentLength != 0)
100 {
101 Stream respStream = null;
102 try
103 {
104 respStream = resp.GetResponseStream();
105 using (StreamReader reader = new StreamReader(respStream))
106 {
107 respstring = reader.ReadToEnd();
108 }
109 }
110 catch (Exception e)
111 {
112 m_log.DebugFormat("[FORMS]: exception occured on receiving reply " + e.ToString());
113 }
114 finally
115 {
116 if (respStream != null)
117 respStream.Close();
118 }
119 }
120 }
121 }
122 catch (System.InvalidOperationException)
123 {
124 // This is what happens when there is invalid XML
125 m_log.DebugFormat("[FORMS]: InvalidOperationException on receiving request");
126 }
127 }
128 return respstring;
129 }
130 }
131}