From 2d9d25b367cd6a33747d2b647abfe57ede97e805 Mon Sep 17 00:00:00 2001
From: Melanie
Date: Sat, 19 Sep 2009 17:33:57 +0100
Subject: Add the skeleton of the authentication connector and the forms data
requester
---
.../HttpServer/SynchronousRestFormsRequester.cs | 95 ++++++++++++++++++++++
1 file changed, 95 insertions(+)
create mode 100644 OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
(limited to 'OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs')
diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
new file mode 100644
index 0000000..0f0c790
--- /dev/null
+++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.IO;
+using System.Net;
+using System.Text;
+using System.Xml;
+using System.Xml.Serialization;
+
+namespace OpenSim.Framework.Servers.HttpServer
+{
+ public class SynchronousRestFormsRequester
+ {
+ ///
+ /// Perform a synchronous REST request.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// Thrown if we encounter a network issue while posting
+ /// the request. You'll want to make sure you deal with this as they're not uncommon
+ public static string MakeRequest(string verb, string requestUrl, string obj)
+ {
+ WebRequest request = WebRequest.Create(requestUrl);
+ request.Method = verb;
+
+ if ((verb == "POST") || (verb == "PUT"))
+ {
+ request.ContentType = "text/www-form-urlencoded";
+
+ MemoryStream buffer = new MemoryStream();
+
+ using (StreamWriter writer = new StreamWriter(buffer))
+ {
+ writer.WriteLine(obj);
+ writer.Flush();
+ }
+
+ int length = (int) buffer.Length;
+ request.ContentLength = length;
+
+ Stream requestStream = request.GetRequestStream();
+ requestStream.Write(buffer.ToArray(), 0, length);
+ }
+
+ string respstring = String.Empty;
+
+ try
+ {
+ using (WebResponse resp = request.GetResponse())
+ {
+ if (resp.ContentLength > 0)
+ {
+ using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
+ {
+ respstring = reader.ReadToEnd();
+ }
+ }
+ }
+ }
+ catch (System.InvalidOperationException)
+ {
+ // This is what happens when there is invalid XML
+ }
+ return respstring;
+ }
+ }
+}
--
cgit v1.1
From dd3d52ae1faefbca85e2fe8d8cea67f7db4005ac Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Thu, 24 Sep 2009 13:33:58 -0700
Subject: Added test GridClient, which allowed me to remove a few bugs out of
the new code.
---
OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs')
diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
index 0f0c790..ebb2691 100644
--- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
+++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
@@ -56,14 +56,14 @@ namespace OpenSim.Framework.Servers.HttpServer
request.ContentType = "text/www-form-urlencoded";
MemoryStream buffer = new MemoryStream();
-
+ int length = 0;
using (StreamWriter writer = new StreamWriter(buffer))
{
writer.WriteLine(obj);
writer.Flush();
+ length = (int)buffer.Length;
}
- int length = (int) buffer.Length;
request.ContentLength = length;
Stream requestStream = request.GetRequestStream();
--
cgit v1.1
From 69da82b39fbb9952e29f57ff08f731b14f969f04 Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Mon, 28 Sep 2009 06:44:57 -0700
Subject: Bug fix in SynchronousRestFormsRequester -- Write instead of
WriteLine, which was causing an extra \n to be written into the buffer.
---
OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs')
diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
index ebb2691..a0d4008 100644
--- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
+++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
@@ -59,11 +59,11 @@ namespace OpenSim.Framework.Servers.HttpServer
int length = 0;
using (StreamWriter writer = new StreamWriter(buffer))
{
- writer.WriteLine(obj);
+ writer.Write(obj);
writer.Flush();
- length = (int)buffer.Length;
}
+ length = (int)obj.Length;
request.ContentLength = length;
Stream requestStream = request.GetRequestStream();
--
cgit v1.1