From 7592a033df4f81ba985e1d6f57ad0ef488dc5745 Mon Sep 17 00:00:00 2001
From: Diva Canto
Date: Tue, 12 Apr 2011 20:24:28 -0700
Subject: 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.
---
.../HttpServer/AsynchronousRestObjectRequester.cs | 192 ------------
.../HttpServer/SynchronousRestFormsRequester.cs | 131 --------
.../HttpServer/SynchronousRestObjectRequester.cs | 122 --------
OpenSim/Framework/WebUtil.cs | 335 +++++++++++++++++++++
4 files changed, 335 insertions(+), 445 deletions(-)
delete mode 100644 OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs
delete mode 100644 OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs
delete mode 100644 OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs
(limited to 'OpenSim/Framework')
diff --git a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs
deleted file mode 100644
index 03c12dd..0000000
--- a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * 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.Reflection;
-using System.Text;
-using System.Xml;
-using System.Xml.Serialization;
-using log4net;
-
-namespace OpenSim.Framework.Servers.HttpServer
-{
- public class AsynchronousRestObjectRequester
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
-
- ///
- /// Perform an asynchronous REST request.
- ///
- /// GET or POST
- ///
- ///
- ///
- ///
- ///
- /// 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 void MakeRequest(string verb,
- string requestUrl, TRequest obj, Action action)
- {
-// m_log.DebugFormat("[ASYNC REQUEST]: Starting {0} {1}", verb, requestUrl);
-
- Type type = typeof (TRequest);
-
- WebRequest request = WebRequest.Create(requestUrl);
- WebResponse response = null;
- TResponse deserial = default(TResponse);
- XmlSerializer deserializer = new XmlSerializer(typeof (TResponse));
-
- request.Method = verb;
-
- if (verb == "POST")
- {
- request.ContentType = "text/xml";
-
- MemoryStream buffer = new MemoryStream();
-
- XmlWriterSettings settings = new XmlWriterSettings();
- settings.Encoding = Encoding.UTF8;
-
- using (XmlWriter writer = XmlWriter.Create(buffer, settings))
- {
- XmlSerializer serializer = new XmlSerializer(type);
- serializer.Serialize(writer, obj);
- writer.Flush();
- }
-
- int length = (int) buffer.Length;
- request.ContentLength = length;
-
- request.BeginGetRequestStream(delegate(IAsyncResult res)
- {
- Stream requestStream = request.EndGetRequestStream(res);
-
- requestStream.Write(buffer.ToArray(), 0, length);
- requestStream.Close();
-
- request.BeginGetResponse(delegate(IAsyncResult ar)
- {
- response = request.EndGetResponse(ar);
- Stream respStream = null;
- try
- {
- respStream = response.GetResponseStream();
- deserial = (TResponse)deserializer.Deserialize(
- respStream);
- }
- catch (System.InvalidOperationException)
- {
- }
- finally
- {
- // Let's not close this
- //buffer.Close();
- respStream.Close();
- response.Close();
- }
-
- action(deserial);
-
- }, null);
- }, null);
-
-
- return;
- }
-
- request.BeginGetResponse(delegate(IAsyncResult res2)
- {
- try
- {
- // If the server returns a 404, this appears to trigger a System.Net.WebException even though that isn't
- // documented in MSDN
- response = request.EndGetResponse(res2);
-
- Stream respStream = null;
- try
- {
- respStream = response.GetResponseStream();
- deserial = (TResponse)deserializer.Deserialize(respStream);
- }
- catch (System.InvalidOperationException)
- {
- }
- finally
- {
- respStream.Close();
- response.Close();
- }
- }
- catch (WebException e)
- {
- if (e.Status == WebExceptionStatus.ProtocolError)
- {
- if (e.Response is HttpWebResponse)
- {
- HttpWebResponse httpResponse = (HttpWebResponse)e.Response;
-
- if (httpResponse.StatusCode != HttpStatusCode.NotFound)
- {
- // We don't appear to be handling any other status codes, so log these feailures to that
- // people don't spend unnecessary hours hunting phantom bugs.
- m_log.DebugFormat(
- "[ASYNC REQUEST]: Request {0} {1} failed with unexpected status code {2}",
- verb, requestUrl, httpResponse.StatusCode);
- }
- }
- }
- else
- {
- m_log.ErrorFormat("[ASYNC REQUEST]: Request {0} {1} failed with status {2} and message {3}", verb, requestUrl, e.Status, e.Message);
- }
- }
- catch (Exception e)
- {
- m_log.ErrorFormat("[ASYNC REQUEST]: Request {0} {1} failed with exception {2}", verb, requestUrl, e);
- }
-
- // m_log.DebugFormat("[ASYNC REQUEST]: Received {0}", deserial.ToString());
-
- try
- {
- action(deserial);
- }
- catch (Exception e)
- {
- m_log.ErrorFormat(
- "[ASYNC REQUEST]: Request {0} {1} callback failed with exception {2}", verb, requestUrl, e);
- }
-
- }, null);
- }
- }
-}
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 @@
-/*
- * 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.Reflection;
-using System.Text;
-using System.Xml;
-using System.Xml.Serialization;
-
-using log4net;
-
-namespace OpenSim.Framework.Servers.HttpServer
-{
- public class SynchronousRestFormsRequester
- {
- private static readonly ILog m_log =
- LogManager.GetLogger(
- MethodBase.GetCurrentMethod().DeclaringType);
-
- ///
- /// 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;
- string respstring = String.Empty;
-
- using (MemoryStream buffer = new MemoryStream())
- {
- if ((verb == "POST") || (verb == "PUT"))
- {
- request.ContentType = "text/www-form-urlencoded";
-
- int length = 0;
- using (StreamWriter writer = new StreamWriter(buffer))
- {
- writer.Write(obj);
- writer.Flush();
- }
-
- length = (int)obj.Length;
- request.ContentLength = length;
-
- Stream requestStream = null;
- try
- {
- requestStream = request.GetRequestStream();
- requestStream.Write(buffer.ToArray(), 0, length);
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[FORMS]: exception occured on sending request to {0}: " + e.ToString(), requestUrl);
- }
- finally
- {
- if (requestStream != null)
- requestStream.Close();
- }
- }
-
- try
- {
- using (WebResponse resp = request.GetResponse())
- {
- if (resp.ContentLength != 0)
- {
- Stream respStream = null;
- try
- {
- respStream = resp.GetResponseStream();
- using (StreamReader reader = new StreamReader(respStream))
- {
- respstring = reader.ReadToEnd();
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[FORMS]: exception occured on receiving reply " + e.ToString());
- }
- finally
- {
- if (respStream != null)
- respStream.Close();
- }
- }
- }
- }
- catch (System.InvalidOperationException)
- {
- // This is what happens when there is invalid XML
- m_log.DebugFormat("[FORMS]: InvalidOperationException on receiving request");
- }
- }
- return respstring;
- }
- }
-}
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 @@
-/*
- * 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 SynchronousRestObjectPoster
- {
- [Obsolete]
- public static TResponse BeginPostObject(string verb, string requestUrl, TRequest obj)
- {
- return SynchronousRestObjectRequester.MakeRequest(verb, requestUrl, obj);
- }
- }
-
- public class SynchronousRestObjectRequester
- {
- ///
- /// 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 TResponse MakeRequest(string verb, string requestUrl, TRequest obj)
- {
- Type type = typeof (TRequest);
- TResponse deserial = default(TResponse);
-
- WebRequest request = WebRequest.Create(requestUrl);
- request.Method = verb;
-
- if ((verb == "POST") || (verb == "PUT"))
- {
- request.ContentType = "text/xml";
-
- MemoryStream buffer = new MemoryStream();
-
- XmlWriterSettings settings = new XmlWriterSettings();
- settings.Encoding = Encoding.UTF8;
-
- using (XmlWriter writer = XmlWriter.Create(buffer, settings))
- {
- XmlSerializer serializer = new XmlSerializer(type);
- serializer.Serialize(writer, obj);
- writer.Flush();
- }
-
- int length = (int) buffer.Length;
- request.ContentLength = length;
-
- Stream requestStream = null;
- try
- {
- requestStream = request.GetRequestStream();
- requestStream.Write(buffer.ToArray(), 0, length);
- }
- catch (Exception)
- {
- return deserial;
- }
- finally
- {
- if (requestStream != null)
- requestStream.Close();
- }
- }
-
- try
- {
- using (WebResponse resp = request.GetResponse())
- {
- if (resp.ContentLength > 0)
- {
- Stream respStream = resp.GetResponseStream();
- XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
- deserial = (TResponse)deserializer.Deserialize(respStream);
- respStream.Close();
- }
- }
- }
- catch (System.InvalidOperationException)
- {
- // This is what happens when there is invalid XML
- }
- return deserial;
- }
- }
-}
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index 1feeeb3..64cd014 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -36,6 +36,9 @@ using System.Net.Security;
using System.Reflection;
using System.Text;
using System.Web;
+using System.Xml;
+using System.Xml.Serialization;
+
using log4net;
using OpenSim.Framework.Servers.HttpServer;
using OpenMetaverse.StructuredData;
@@ -625,4 +628,336 @@ namespace OpenSim.Framework
}
+
+ public static class AsynchronousRestObjectRequester
+ {
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ ///
+ /// Perform an asynchronous REST request.
+ ///
+ /// GET or POST
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// 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 void MakeRequest(string verb,
+ string requestUrl, TRequest obj, Action action)
+ {
+ // m_log.DebugFormat("[ASYNC REQUEST]: Starting {0} {1}", verb, requestUrl);
+
+ Type type = typeof(TRequest);
+
+ WebRequest request = WebRequest.Create(requestUrl);
+ WebResponse response = null;
+ TResponse deserial = default(TResponse);
+ XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
+
+ request.Method = verb;
+
+ if (verb == "POST")
+ {
+ request.ContentType = "text/xml";
+
+ MemoryStream buffer = new MemoryStream();
+
+ XmlWriterSettings settings = new XmlWriterSettings();
+ settings.Encoding = Encoding.UTF8;
+
+ using (XmlWriter writer = XmlWriter.Create(buffer, settings))
+ {
+ XmlSerializer serializer = new XmlSerializer(type);
+ serializer.Serialize(writer, obj);
+ writer.Flush();
+ }
+
+ int length = (int)buffer.Length;
+ request.ContentLength = length;
+
+ request.BeginGetRequestStream(delegate(IAsyncResult res)
+ {
+ Stream requestStream = request.EndGetRequestStream(res);
+
+ requestStream.Write(buffer.ToArray(), 0, length);
+ requestStream.Close();
+
+ request.BeginGetResponse(delegate(IAsyncResult ar)
+ {
+ response = request.EndGetResponse(ar);
+ Stream respStream = null;
+ try
+ {
+ respStream = response.GetResponseStream();
+ deserial = (TResponse)deserializer.Deserialize(
+ respStream);
+ }
+ catch (System.InvalidOperationException)
+ {
+ }
+ finally
+ {
+ // Let's not close this
+ //buffer.Close();
+ respStream.Close();
+ response.Close();
+ }
+
+ action(deserial);
+
+ }, null);
+ }, null);
+
+
+ return;
+ }
+
+ request.BeginGetResponse(delegate(IAsyncResult res2)
+ {
+ try
+ {
+ // If the server returns a 404, this appears to trigger a System.Net.WebException even though that isn't
+ // documented in MSDN
+ response = request.EndGetResponse(res2);
+
+ Stream respStream = null;
+ try
+ {
+ respStream = response.GetResponseStream();
+ deserial = (TResponse)deserializer.Deserialize(respStream);
+ }
+ catch (System.InvalidOperationException)
+ {
+ }
+ finally
+ {
+ respStream.Close();
+ response.Close();
+ }
+ }
+ catch (WebException e)
+ {
+ if (e.Status == WebExceptionStatus.ProtocolError)
+ {
+ if (e.Response is HttpWebResponse)
+ {
+ HttpWebResponse httpResponse = (HttpWebResponse)e.Response;
+
+ if (httpResponse.StatusCode != HttpStatusCode.NotFound)
+ {
+ // We don't appear to be handling any other status codes, so log these feailures to that
+ // people don't spend unnecessary hours hunting phantom bugs.
+ m_log.DebugFormat(
+ "[ASYNC REQUEST]: Request {0} {1} failed with unexpected status code {2}",
+ verb, requestUrl, httpResponse.StatusCode);
+ }
+ }
+ }
+ else
+ {
+ m_log.ErrorFormat("[ASYNC REQUEST]: Request {0} {1} failed with status {2} and message {3}", verb, requestUrl, e.Status, e.Message);
+ }
+ }
+ catch (Exception e)
+ {
+ m_log.ErrorFormat("[ASYNC REQUEST]: Request {0} {1} failed with exception {2}", verb, requestUrl, e);
+ }
+
+ // m_log.DebugFormat("[ASYNC REQUEST]: Received {0}", deserial.ToString());
+
+ try
+ {
+ action(deserial);
+ }
+ catch (Exception e)
+ {
+ m_log.ErrorFormat(
+ "[ASYNC REQUEST]: Request {0} {1} callback failed with exception {2}", verb, requestUrl, e);
+ }
+
+ }, null);
+ }
+ }
+
+ public static class SynchronousRestFormsRequester
+ {
+ private static readonly ILog m_log =
+ LogManager.GetLogger(
+ MethodBase.GetCurrentMethod().DeclaringType);
+
+ ///
+ /// 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;
+ string respstring = String.Empty;
+
+ using (MemoryStream buffer = new MemoryStream())
+ {
+ if ((verb == "POST") || (verb == "PUT"))
+ {
+ request.ContentType = "text/www-form-urlencoded";
+
+ int length = 0;
+ using (StreamWriter writer = new StreamWriter(buffer))
+ {
+ writer.Write(obj);
+ writer.Flush();
+ }
+
+ length = (int)obj.Length;
+ request.ContentLength = length;
+
+ Stream requestStream = null;
+ try
+ {
+ requestStream = request.GetRequestStream();
+ requestStream.Write(buffer.ToArray(), 0, length);
+ }
+ catch (Exception e)
+ {
+ m_log.DebugFormat("[FORMS]: exception occured on sending request to {0}: " + e.ToString(), requestUrl);
+ }
+ finally
+ {
+ if (requestStream != null)
+ requestStream.Close();
+ }
+ }
+
+ try
+ {
+ using (WebResponse resp = request.GetResponse())
+ {
+ if (resp.ContentLength != 0)
+ {
+ Stream respStream = null;
+ try
+ {
+ respStream = resp.GetResponseStream();
+ using (StreamReader reader = new StreamReader(respStream))
+ {
+ respstring = reader.ReadToEnd();
+ }
+ }
+ catch (Exception e)
+ {
+ m_log.DebugFormat("[FORMS]: exception occured on receiving reply " + e.ToString());
+ }
+ finally
+ {
+ if (respStream != null)
+ respStream.Close();
+ }
+ }
+ }
+ }
+ catch (System.InvalidOperationException)
+ {
+ // This is what happens when there is invalid XML
+ m_log.DebugFormat("[FORMS]: InvalidOperationException on receiving request");
+ }
+ }
+ return respstring;
+ }
+ }
+
+ public class SynchronousRestObjectPoster
+ {
+ [Obsolete]
+ public static TResponse BeginPostObject(string verb, string requestUrl, TRequest obj)
+ {
+ return SynchronousRestObjectRequester.MakeRequest(verb, requestUrl, obj);
+ }
+ }
+
+ public class SynchronousRestObjectRequester
+ {
+ ///
+ /// 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 TResponse MakeRequest(string verb, string requestUrl, TRequest obj)
+ {
+ Type type = typeof(TRequest);
+ TResponse deserial = default(TResponse);
+
+ WebRequest request = WebRequest.Create(requestUrl);
+ request.Method = verb;
+
+ if ((verb == "POST") || (verb == "PUT"))
+ {
+ request.ContentType = "text/xml";
+
+ MemoryStream buffer = new MemoryStream();
+
+ XmlWriterSettings settings = new XmlWriterSettings();
+ settings.Encoding = Encoding.UTF8;
+
+ using (XmlWriter writer = XmlWriter.Create(buffer, settings))
+ {
+ XmlSerializer serializer = new XmlSerializer(type);
+ serializer.Serialize(writer, obj);
+ writer.Flush();
+ }
+
+ int length = (int)buffer.Length;
+ request.ContentLength = length;
+
+ Stream requestStream = null;
+ try
+ {
+ requestStream = request.GetRequestStream();
+ requestStream.Write(buffer.ToArray(), 0, length);
+ }
+ catch (Exception)
+ {
+ return deserial;
+ }
+ finally
+ {
+ if (requestStream != null)
+ requestStream.Close();
+ }
+ }
+
+ try
+ {
+ using (WebResponse resp = request.GetResponse())
+ {
+ if (resp.ContentLength > 0)
+ {
+ Stream respStream = resp.GetResponseStream();
+ XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
+ deserial = (TResponse)deserializer.Deserialize(respStream);
+ respStream.Close();
+ }
+ }
+ }
+ catch (System.InvalidOperationException)
+ {
+ // This is what happens when there is invalid XML
+ }
+ return deserial;
+ }
+ }
}
--
cgit v1.1
From 3fe22126ca3974b2a10365121ee0141fb54806e6 Mon Sep 17 00:00:00 2001
From: Mic Bowman
Date: Tue, 12 Apr 2011 12:36:36 -0700
Subject: First pass at moving object property requests into a queue similar to
the entity update queue. The number of property packets can become
significant when selecting/deselecting large numbers of objects.
This is experimental code.
---
OpenSim/Framework/IClientAPI.cs | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
(limited to 'OpenSim/Framework')
diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs
index 5bf0b7b..c56a756 100644
--- a/OpenSim/Framework/IClientAPI.cs
+++ b/OpenSim/Framework/IClientAPI.cs
@@ -570,16 +570,30 @@ namespace OpenSim.Framework
public float dwell;
}
- public class EntityUpdate
+ public class IEntityUpdate
{
public ISceneEntity Entity;
- public PrimUpdateFlags Flags;
- public float TimeDilation;
+ public uint Flags;
- public EntityUpdate(ISceneEntity entity, PrimUpdateFlags flags, float timedilation)
+ public IEntityUpdate(ISceneEntity entity, uint flags)
{
Entity = entity;
Flags = flags;
+ }
+ }
+
+
+ public class EntityUpdate : IEntityUpdate
+ {
+ // public ISceneEntity Entity;
+ // public PrimUpdateFlags Flags;
+ public float TimeDilation;
+
+ public EntityUpdate(ISceneEntity entity, PrimUpdateFlags flags, float timedilation)
+ : base(entity,(uint)flags)
+ {
+ //Entity = entity;
+ // Flags = flags;
TimeDilation = timedilation;
}
}
@@ -1211,20 +1225,9 @@ namespace OpenSim.Framework
///
void SendSimStats(SimStats stats);
- void SendObjectPropertiesFamilyData(uint RequestFlags, UUID ObjectUUID, UUID OwnerID, UUID GroupID,
- uint BaseMask, uint OwnerMask, uint GroupMask, uint EveryoneMask,
- uint NextOwnerMask, int OwnershipCost, byte SaleType, int SalePrice,
- uint Category,
- UUID LastOwnerID, string ObjectName, string Description);
-
- void SendObjectPropertiesReply(UUID ItemID, ulong CreationDate, UUID CreatorUUID, UUID FolderUUID,
- UUID FromTaskUUID,
- UUID GroupUUID, short InventorySerial, UUID LastOwnerUUID, UUID ObjectUUID,
- UUID OwnerUUID, string TouchTitle, byte[] TextureID, string SitTitle,
- string ItemName,
- string ItemDescription, uint OwnerMask, uint NextOwnerMask, uint GroupMask,
- uint EveryoneMask,
- uint BaseMask, byte saleType, int salePrice);
+ void SendObjectPropertiesFamilyData(ISceneEntity Entity, uint RequestFlags);
+
+ void SendObjectPropertiesReply(ISceneEntity Entity);
void SendAgentOffline(UUID[] agentIDs);
--
cgit v1.1
From b33aac737a3e7ae28216cb98de99d9c6eba1d563 Mon Sep 17 00:00:00 2001
From: Mic Bowman
Date: Tue, 12 Apr 2011 15:40:57 -0700
Subject: Fixed the update of items in the priority queue to enable both types
of property updates to be specified. Not sure if one form of property update
should supercede another. But for now the old OpenSim behavior is preserved
by sending both.
---
OpenSim/Framework/IClientAPI.cs | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'OpenSim/Framework')
diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs
index c56a756..f573c32 100644
--- a/OpenSim/Framework/IClientAPI.cs
+++ b/OpenSim/Framework/IClientAPI.cs
@@ -575,6 +575,11 @@ namespace OpenSim.Framework
public ISceneEntity Entity;
public uint Flags;
+ public virtual void Update(IEntityUpdate update)
+ {
+ this.Flags |= update.Flags;
+ }
+
public IEntityUpdate(ISceneEntity entity, uint flags)
{
Entity = entity;
--
cgit v1.1