From aba9ffdbd008920f94cfbd7d4ff4a0fa92e92321 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 2 May 2011 11:56:40 -0700 Subject: Refactored the GetMesh module into a handler and a module, to be the same as GetTexture. --- .../Handlers/GetMesh/GetMeshHandler.cs | 143 +++++++++++++++++++++ .../Handlers/GetMesh/GetMeshServerConnector.cs | 79 ++++++++++++ 2 files changed, 222 insertions(+) create mode 100644 OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs create mode 100644 OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs (limited to 'OpenSim/Capabilities/Handlers/GetMesh') diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs new file mode 100644 index 0000000..c60abb1 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs @@ -0,0 +1,143 @@ +/* + * 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.Collections; +using System.Collections.Specialized; +using System.Reflection; +using System.IO; +using System.Web; +using log4net; +using Nini.Config; +using OpenMetaverse; +using OpenMetaverse.StructuredData; +using OpenSim.Framework; +using OpenSim.Framework.Servers; +using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Services.Interfaces; +using Caps = OpenSim.Framework.Capabilities.Caps; + +namespace OpenSim.Capabilities.Handlers +{ + public class GetMeshHandler + { +// private static readonly ILog m_log = +// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private IAssetService m_assetService; + + public GetMeshHandler(IAssetService assService) + { + m_assetService = assService; + } + + public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) + { + + Hashtable responsedata = new Hashtable(); + responsedata["int_response_code"] = 400; //501; //410; //404; + responsedata["content_type"] = "text/plain"; + responsedata["keepalive"] = false; + responsedata["str_response_string"] = "Request wasn't what was expected"; + + string meshStr = string.Empty; + + if (request.ContainsKey("mesh_id")) + meshStr = request["mesh_id"].ToString(); + + + UUID meshID = UUID.Zero; + if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) + { + if (m_assetService == null) + { + responsedata["int_response_code"] = 404; //501; //410; //404; + responsedata["content_type"] = "text/plain"; + responsedata["keepalive"] = false; + responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; + return responsedata; + } + + AssetBase mesh; + // Only try to fetch locally cached textures. Misses are redirected + mesh = m_assetService.GetCached(meshID.ToString()); + if (mesh != null) + { + if (mesh.Type == (SByte)AssetType.Mesh) + { + responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); + responsedata["content_type"] = "application/vnd.ll.mesh"; + responsedata["int_response_code"] = 200; + } + // Optionally add additional mesh types here + else + { + responsedata["int_response_code"] = 404; //501; //410; //404; + responsedata["content_type"] = "text/plain"; + responsedata["keepalive"] = false; + responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; + return responsedata; + } + } + else + { + mesh = m_assetService.Get(meshID.ToString()); + if (mesh != null) + { + if (mesh.Type == (SByte)AssetType.Mesh) + { + responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); + responsedata["content_type"] = "application/vnd.ll.mesh"; + responsedata["int_response_code"] = 200; + } + // Optionally add additional mesh types here + else + { + responsedata["int_response_code"] = 404; //501; //410; //404; + responsedata["content_type"] = "text/plain"; + responsedata["keepalive"] = false; + responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; + return responsedata; + } + } + + else + { + responsedata["int_response_code"] = 404; //501; //410; //404; + responsedata["content_type"] = "text/plain"; + responsedata["keepalive"] = false; + responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; + return responsedata; + } + } + + } + + return responsedata; + } + } +} diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs new file mode 100644 index 0000000..fa5f755 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs @@ -0,0 +1,79 @@ +/* + * 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.Collections; +using Nini.Config; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Server.Handlers.Base; +using OpenSim.Framework.Servers; +using OpenSim.Framework.Servers.HttpServer; + +using OpenMetaverse; + +namespace OpenSim.Capabilities.Handlers +{ + public class GetMeshServerConnector : ServiceConnector + { + private IAssetService m_AssetService; + private string m_ConfigName = "CapsService"; + + public GetMeshServerConnector(IConfigSource config, IHttpServer server, string configName) : + base(config, server, configName) + { + if (configName != String.Empty) + m_ConfigName = configName; + + IConfig serverConfig = config.Configs[m_ConfigName]; + if (serverConfig == null) + throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); + + string assetService = serverConfig.GetString("AssetService", String.Empty); + + if (assetService == String.Empty) + throw new Exception("No AssetService in config file"); + + Object[] args = new Object[] { config }; + m_AssetService = + ServerUtils.LoadPlugin(assetService, args); + + if (m_AssetService == null) + throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); + + GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService); + IRequestHandler reqHandler = new RestHTTPHandler("GET", "/CAPS/" + UUID.Random(), + delegate(Hashtable m_dhttpMethod) + { + return gmeshHandler.ProcessGetMesh(m_dhttpMethod, UUID.Zero, null); + }); + server.AddStreamHandler(reqHandler); + } + + } +} -- cgit v1.1 From f5bb6edd85776594551dcb35b31384f80e73d36e Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 5 May 2011 13:01:46 +0100 Subject: Squish a warning --- OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'OpenSim/Capabilities/Handlers/GetMesh') diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs index fa5f755..2ecfa3c 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs @@ -33,7 +33,6 @@ using OpenSim.Services.Interfaces; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Server.Handlers.Base; using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.HttpServer; using OpenMetaverse; -- cgit v1.1 From 3146f4bae0d6c0b190fb6b8477c690046a1c79af Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 18 Aug 2011 23:36:43 +0100 Subject: Don't need to try both AssetService.Get and GetCached in GetMesh since Get always calls GetCached and code paths were identical --- .../Handlers/GetMesh/GetMeshHandler.cs | 45 +++++----------------- 1 file changed, 9 insertions(+), 36 deletions(-) (limited to 'OpenSim/Capabilities/Handlers/GetMesh') diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs index c60abb1..720640e 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs @@ -57,7 +57,6 @@ namespace OpenSim.Capabilities.Handlers public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) { - Hashtable responsedata = new Hashtable(); responsedata["int_response_code"] = 400; //501; //410; //404; responsedata["content_type"] = "text/plain"; @@ -69,7 +68,6 @@ namespace OpenSim.Capabilities.Handlers if (request.ContainsKey("mesh_id")) meshStr = request["mesh_id"].ToString(); - UUID meshID = UUID.Zero; if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) { @@ -82,12 +80,11 @@ namespace OpenSim.Capabilities.Handlers return responsedata; } - AssetBase mesh; - // Only try to fetch locally cached textures. Misses are redirected - mesh = m_assetService.GetCached(meshID.ToString()); + AssetBase mesh = m_assetService.Get(meshID.ToString()); + if (mesh != null) { - if (mesh.Type == (SByte)AssetType.Mesh) + if (mesh.Type == (SByte)AssetType.Mesh) { responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); responsedata["content_type"] = "application/vnd.ll.mesh"; @@ -105,39 +102,15 @@ namespace OpenSim.Capabilities.Handlers } else { - mesh = m_assetService.Get(meshID.ToString()); - if (mesh != null) - { - if (mesh.Type == (SByte)AssetType.Mesh) - { - responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); - responsedata["content_type"] = "application/vnd.ll.mesh"; - responsedata["int_response_code"] = 200; - } - // Optionally add additional mesh types here - else - { - responsedata["int_response_code"] = 404; //501; //410; //404; - responsedata["content_type"] = "text/plain"; - responsedata["keepalive"] = false; - responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; - return responsedata; - } - } - - else - { - responsedata["int_response_code"] = 404; //501; //410; //404; - responsedata["content_type"] = "text/plain"; - responsedata["keepalive"] = false; - responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; - return responsedata; - } + responsedata["int_response_code"] = 404; //501; //410; //404; + responsedata["content_type"] = "text/plain"; + responsedata["keepalive"] = false; + responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; + return responsedata; } - } return responsedata; } } -} +} \ No newline at end of file -- cgit v1.1 From 231a3bf147315a9284140476d2b09e13c3fee1c0 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 3 May 2012 01:45:49 +0100 Subject: Implement optional name and description on http stream handlers so that we can relate a slow request to what the handler actually does and the agent it serves, if applicable. This is most useful for capabilities where the url is not self-describing. --- .../Handlers/GetMesh/GetMeshServerConnector.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'OpenSim/Capabilities/Handlers/GetMesh') diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs index 2ecfa3c..8a275f3 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs @@ -66,13 +66,14 @@ namespace OpenSim.Capabilities.Handlers throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService); - IRequestHandler reqHandler = new RestHTTPHandler("GET", "/CAPS/" + UUID.Random(), - delegate(Hashtable m_dhttpMethod) - { - return gmeshHandler.ProcessGetMesh(m_dhttpMethod, UUID.Zero, null); - }); + IRequestHandler reqHandler + = new RestHTTPHandler( + "GET", + "/CAPS/" + UUID.Random(), + httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null), + "GetMesh", + null); server.AddStreamHandler(reqHandler); } - } -} +} \ No newline at end of file -- cgit v1.1 From f6ea5088f4cc76eddb05b20b5d768f761b0fbd15 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Fri, 20 Jun 2014 10:46:24 +0300 Subject: Removed unused files: Texture/Mesh server connectors --- .../Handlers/GetMesh/GetMeshServerConnector.cs | 79 ---------------------- 1 file changed, 79 deletions(-) delete mode 100644 OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs (limited to 'OpenSim/Capabilities/Handlers/GetMesh') diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs deleted file mode 100644 index 8a275f3..0000000 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs +++ /dev/null @@ -1,79 +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.Collections; -using Nini.Config; -using OpenSim.Server.Base; -using OpenSim.Services.Interfaces; -using OpenSim.Framework.Servers.HttpServer; -using OpenSim.Server.Handlers.Base; -using OpenSim.Framework.Servers; - -using OpenMetaverse; - -namespace OpenSim.Capabilities.Handlers -{ - public class GetMeshServerConnector : ServiceConnector - { - private IAssetService m_AssetService; - private string m_ConfigName = "CapsService"; - - public GetMeshServerConnector(IConfigSource config, IHttpServer server, string configName) : - base(config, server, configName) - { - if (configName != String.Empty) - m_ConfigName = configName; - - IConfig serverConfig = config.Configs[m_ConfigName]; - if (serverConfig == null) - throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); - - string assetService = serverConfig.GetString("AssetService", String.Empty); - - if (assetService == String.Empty) - throw new Exception("No AssetService in config file"); - - Object[] args = new Object[] { config }; - m_AssetService = - ServerUtils.LoadPlugin(assetService, args); - - if (m_AssetService == null) - throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); - - GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService); - IRequestHandler reqHandler - = new RestHTTPHandler( - "GET", - "/CAPS/" + UUID.Random(), - httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null), - "GetMesh", - null); - server.AddStreamHandler(reqHandler); - } - } -} \ No newline at end of file -- cgit v1.1 From 1a9c14b04105af03f843f0760541e53b89fdedf1 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 21 Jul 2014 21:25:48 +0000 Subject: Revert "Removed unused files: Texture/Mesh server connectors" This reverts commit f6ea5088f4cc76eddb05b20b5d768f761b0fbd15. --- .../Handlers/GetMesh/GetMeshServerConnector.cs | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs (limited to 'OpenSim/Capabilities/Handlers/GetMesh') diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs new file mode 100644 index 0000000..8a275f3 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs @@ -0,0 +1,79 @@ +/* + * 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.Collections; +using Nini.Config; +using OpenSim.Server.Base; +using OpenSim.Services.Interfaces; +using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Server.Handlers.Base; +using OpenSim.Framework.Servers; + +using OpenMetaverse; + +namespace OpenSim.Capabilities.Handlers +{ + public class GetMeshServerConnector : ServiceConnector + { + private IAssetService m_AssetService; + private string m_ConfigName = "CapsService"; + + public GetMeshServerConnector(IConfigSource config, IHttpServer server, string configName) : + base(config, server, configName) + { + if (configName != String.Empty) + m_ConfigName = configName; + + IConfig serverConfig = config.Configs[m_ConfigName]; + if (serverConfig == null) + throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); + + string assetService = serverConfig.GetString("AssetService", String.Empty); + + if (assetService == String.Empty) + throw new Exception("No AssetService in config file"); + + Object[] args = new Object[] { config }; + m_AssetService = + ServerUtils.LoadPlugin(assetService, args); + + if (m_AssetService == null) + throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); + + GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService); + IRequestHandler reqHandler + = new RestHTTPHandler( + "GET", + "/CAPS/" + UUID.Random(), + httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null), + "GetMesh", + null); + server.AddStreamHandler(reqHandler); + } + } +} \ No newline at end of file -- cgit v1.1 From 16a5e154436fc56235ac03846d4bb1ba4d21ac87 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 14 Oct 2014 18:37:22 +0100 Subject: Allow GetMesh capability to be served directly by a server like GetTexture To do this required GetMesh to be converted to a BaseStreamHandler Unlike GetTexture connector, no redirect URL functionality yet (this wasn't present in the first place). --- .../Handlers/GetMesh/GetMeshHandler.cs | 60 +++++++++++----------- .../Handlers/GetMesh/GetMeshServerConnector.cs | 11 +--- 2 files changed, 31 insertions(+), 40 deletions(-) (limited to 'OpenSim/Capabilities/Handlers/GetMesh') diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs index 720640e..9fe00e0 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs @@ -30,6 +30,7 @@ using System.Collections; using System.Collections.Specialized; using System.Reflection; using System.IO; +using System.Text; using System.Web; using log4net; using Nini.Config; @@ -43,41 +44,37 @@ using Caps = OpenSim.Framework.Capabilities.Caps; namespace OpenSim.Capabilities.Handlers { - public class GetMeshHandler + public class GetMeshHandler : BaseStreamHandler { // private static readonly ILog m_log = // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_assetService; - public GetMeshHandler(IAssetService assService) + public GetMeshHandler(string path, IAssetService assService, string name, string description) + : base("GET", path, name, description) { m_assetService = assService; } - public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) + protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { - Hashtable responsedata = new Hashtable(); - responsedata["int_response_code"] = 400; //501; //410; //404; - responsedata["content_type"] = "text/plain"; - responsedata["keepalive"] = false; - responsedata["str_response_string"] = "Request wasn't what was expected"; + // Try to parse the texture ID from the request URL + NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); + string meshStr = query.GetOne("mesh_id"); - string meshStr = string.Empty; - - if (request.ContainsKey("mesh_id")) - meshStr = request["mesh_id"].ToString(); +// m_log.DebugFormat("Fetching mesh {0}", meshStr); UUID meshID = UUID.Zero; if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) { if (m_assetService == null) { - responsedata["int_response_code"] = 404; //501; //410; //404; - responsedata["content_type"] = "text/plain"; - responsedata["keepalive"] = false; - responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; - return responsedata; + httpResponse.StatusCode = 404; + httpResponse.ContentType = "text/plain"; + byte[] data = Encoding.UTF8.GetBytes("The asset service is unavailable. So is your mesh."); + httpResponse.Body.Write(data, 0, data.Length); + return null; } AssetBase mesh = m_assetService.Get(meshID.ToString()); @@ -86,31 +83,32 @@ namespace OpenSim.Capabilities.Handlers { if (mesh.Type == (SByte)AssetType.Mesh) { - responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); - responsedata["content_type"] = "application/vnd.ll.mesh"; - responsedata["int_response_code"] = 200; + byte[] data = mesh.Data; + httpResponse.Body.Write(data, 0, data.Length); + httpResponse.ContentType = "application/vnd.ll.mesh"; + httpResponse.StatusCode = 200; } // Optionally add additional mesh types here else { - responsedata["int_response_code"] = 404; //501; //410; //404; - responsedata["content_type"] = "text/plain"; - responsedata["keepalive"] = false; - responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; - return responsedata; + httpResponse.StatusCode = 404; + httpResponse.ContentType = "text/plain"; + byte[] data = Encoding.UTF8.GetBytes("Unfortunately, this asset isn't a mesh."); + httpResponse.Body.Write(data, 0, data.Length); + httpResponse.KeepAlive = false; } } else { - responsedata["int_response_code"] = 404; //501; //410; //404; - responsedata["content_type"] = "text/plain"; - responsedata["keepalive"] = false; - responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; - return responsedata; + httpResponse.StatusCode = 404; + httpResponse.ContentType = "text/plain"; + byte[] data = Encoding.UTF8.GetBytes("Your Mesh wasn't found. Sorry!"); + httpResponse.Body.Write(data, 0, data.Length); + httpResponse.KeepAlive = false; } } - return responsedata; + return null; } } } \ No newline at end of file diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs index 8a275f3..9c53862 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs @@ -65,15 +65,8 @@ namespace OpenSim.Capabilities.Handlers if (m_AssetService == null) throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); - GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService); - IRequestHandler reqHandler - = new RestHTTPHandler( - "GET", - "/CAPS/" + UUID.Random(), - httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null), - "GetMesh", - null); - server.AddStreamHandler(reqHandler); + server.AddStreamHandler( + new GetMeshHandler("/CAPS/GetMesh/" /*+ UUID.Random() */, m_AssetService, "GetMesh", null)); } } } \ No newline at end of file -- cgit v1.1 From 4de10a45e9136c75e33f31b448720db35c2c23b1 Mon Sep 17 00:00:00 2001 From: Freaky Tech Date: Thu, 5 Mar 2015 23:52:13 +0100 Subject: revised GetMesh to not use intermediate base64 coding scheme it delivers binary and has binary as input. base64 intermediate coding makes no sense. Signed-off-by: BlueWall --- .../Handlers/GetMesh/GetMeshHandler.cs | 227 +++++++++++++++++---- .../Handlers/GetMesh/GetMeshServerConnector.cs | 20 +- 2 files changed, 195 insertions(+), 52 deletions(-) (limited to 'OpenSim/Capabilities/Handlers/GetMesh') diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs index 9fe00e0..6b67da1 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs @@ -25,90 +25,229 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -using System; -using System.Collections; -using System.Collections.Specialized; -using System.Reflection; -using System.IO; -using System.Text; -using System.Web; using log4net; -using Nini.Config; using OpenMetaverse; -using OpenMetaverse.StructuredData; +using OpenMetaverse.Imaging; using OpenSim.Framework; -using OpenSim.Framework.Servers; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Services.Interfaces; -using Caps = OpenSim.Framework.Capabilities.Caps; +using System; +using System.Collections.Specialized; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Reflection; +using System.Web; namespace OpenSim.Capabilities.Handlers { public class GetMeshHandler : BaseStreamHandler { -// private static readonly ILog m_log = -// LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - + private static readonly ILog m_log = + LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_assetService; - public GetMeshHandler(string path, IAssetService assService, string name, string description) + // TODO: Change this to a config option + private string m_RedirectURL = null; + + public GetMeshHandler(string path, IAssetService assService, string name, string description, string redirectURL) : base("GET", path, name, description) { m_assetService = assService; + m_RedirectURL = redirectURL; + if (m_RedirectURL != null && !m_RedirectURL.EndsWith("/")) + m_RedirectURL += "/"; } protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // Try to parse the texture ID from the request URL NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); - string meshStr = query.GetOne("mesh_id"); + string textureStr = query.GetOne("mesh_id"); -// m_log.DebugFormat("Fetching mesh {0}", meshStr); + if (m_assetService == null) + { + m_log.Error("[GETMESH]: Cannot fetch mesh " + textureStr + " without an asset service"); + httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; + } - UUID meshID = UUID.Zero; - if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) + UUID meshID; + if (!String.IsNullOrEmpty(textureStr) && UUID.TryParse(textureStr, out meshID)) { - if (m_assetService == null) + // OK, we have an array with preferred formats, possibly with only one entry + + httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; + AssetBase mesh; + + if (!String.IsNullOrEmpty(m_RedirectURL)) { - httpResponse.StatusCode = 404; - httpResponse.ContentType = "text/plain"; - byte[] data = Encoding.UTF8.GetBytes("The asset service is unavailable. So is your mesh."); - httpResponse.Body.Write(data, 0, data.Length); - return null; + // Only try to fetch locally cached meshes. Misses are redirected + mesh = m_assetService.GetCached(meshID.ToString()); + + if (mesh != null) + { + if (mesh.Type != (sbyte)AssetType.Mesh) + { + httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; + } + WriteMeshData(httpRequest, httpResponse, mesh); + } + else + { + string textureUrl = m_RedirectURL + "?mesh_id="+ meshID.ToString(); + m_log.Debug("[GETMESH]: Redirecting mesh request to " + textureUrl); + httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently; + httpResponse.RedirectLocation = textureUrl; + return null; + } } + else // no redirect + { + // try the cache + mesh = m_assetService.GetCached(meshID.ToString()); + + if (mesh == null) + { + // Fetch locally or remotely. Misses return a 404 + mesh = m_assetService.Get(meshID.ToString()); - AssetBase mesh = m_assetService.Get(meshID.ToString()); + if (mesh != null) + { + if (mesh.Type != (sbyte)AssetType.Mesh) + { + httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; + return null; + } + WriteMeshData(httpRequest, httpResponse, mesh); + return null; + } + } + else // it was on the cache + { + if (mesh.Type != (sbyte)AssetType.Mesh) + { + httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; + return null; + } + WriteMeshData(httpRequest, httpResponse, mesh); + return null; + } + } - if (mesh != null) + // not found + httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; + return null; + } + else + { + m_log.Warn("[GETTEXTURE]: Failed to parse a mesh_id from GetMesh request: " + httpRequest.Url); + } + + return null; + } + + private void WriteMeshData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture) + { + string range = request.Headers.GetOne("Range"); + + if (!String.IsNullOrEmpty(range)) + { + // Range request + int start, end; + if (TryParseRange(range, out start, out end)) { - if (mesh.Type == (SByte)AssetType.Mesh) + // Before clamping start make sure we can satisfy it in order to avoid + // sending back the last byte instead of an error status + if (start >= texture.Data.Length) { - byte[] data = mesh.Data; - httpResponse.Body.Write(data, 0, data.Length); - httpResponse.ContentType = "application/vnd.ll.mesh"; - httpResponse.StatusCode = 200; + response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; + response.ContentType = texture.Metadata.ContentType; } - // Optionally add additional mesh types here else { - httpResponse.StatusCode = 404; - httpResponse.ContentType = "text/plain"; - byte[] data = Encoding.UTF8.GetBytes("Unfortunately, this asset isn't a mesh."); - httpResponse.Body.Write(data, 0, data.Length); - httpResponse.KeepAlive = false; + // Handle the case where no second range value was given. This is equivalent to requesting + // the rest of the entity. + if (end == -1) + end = int.MaxValue; + + end = Utils.Clamp(end, 0, texture.Data.Length - 1); + start = Utils.Clamp(start, 0, end); + int len = end - start + 1; + + if (0 == start && len == texture.Data.Length) + { + response.StatusCode = (int)System.Net.HttpStatusCode.OK; + } + else + { + response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; + response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); + } + + response.ContentLength = len; + response.ContentType = "application/vnd.ll.mesh"; + + response.Body.Write(texture.Data, start, len); } } else { - httpResponse.StatusCode = 404; - httpResponse.ContentType = "text/plain"; - byte[] data = Encoding.UTF8.GetBytes("Your Mesh wasn't found. Sorry!"); - httpResponse.Body.Write(data, 0, data.Length); - httpResponse.KeepAlive = false; + m_log.Warn("[GETMESH]: Malformed Range header: " + range); + response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; } } + else + { + // Full content request + response.StatusCode = (int)System.Net.HttpStatusCode.OK; + response.ContentLength = texture.Data.Length; + response.ContentType = "application/vnd.ll.mesh"; + response.Body.Write(texture.Data, 0, texture.Data.Length); + } + } - return null; + /// + /// Parse a range header. + /// + /// + /// As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, + /// this obeys range headers with two values (e.g. 533-4165) and no second value (e.g. 533-). + /// Where there is no value, -1 is returned. + /// FIXME: Need to cover the case where only a second value is specified (e.g. -4165), probably by returning -1 + /// for start. + /// + /// + /// Start of the range. Undefined if this was not a number. + /// End of the range. Will be -1 if no end specified. Undefined if there was a raw string but this was not a number. + private bool TryParseRange(string header, out int start, out int end) + { + start = end = 0; + + if (header.StartsWith("bytes=")) + { + string[] rangeValues = header.Substring(6).Split('-'); + + if (rangeValues.Length == 2) + { + if (!Int32.TryParse(rangeValues[0], out start)) + return false; + + string rawEnd = rangeValues[1]; + + if (rawEnd == "") + { + end = -1; + return true; + } + else if (Int32.TryParse(rawEnd, out end)) + { + return true; + } + } + } + + start = end = 0; + return false; } } } \ No newline at end of file diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs index 9c53862..19de3cf 100644 --- a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs @@ -25,16 +25,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -using System; -using System.Collections; using Nini.Config; -using OpenSim.Server.Base; -using OpenSim.Services.Interfaces; +using OpenMetaverse; using OpenSim.Framework.Servers.HttpServer; +using OpenSim.Server.Base; using OpenSim.Server.Handlers.Base; -using OpenSim.Framework.Servers; - -using OpenMetaverse; +using OpenSim.Services.Interfaces; +using System; namespace OpenSim.Capabilities.Handlers { @@ -65,8 +62,15 @@ namespace OpenSim.Capabilities.Handlers if (m_AssetService == null) throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); + string rurl = serverConfig.GetString("GetMeshRedirectURL"); + + server.AddStreamHandler( + new GetTextureHandler("/CAPS/GetMesh/" /*+ UUID.Random() */, m_AssetService, "GetMesh", null, rurl)); + + rurl = serverConfig.GetString("GetMesh2RedirectURL"); + server.AddStreamHandler( - new GetMeshHandler("/CAPS/GetMesh/" /*+ UUID.Random() */, m_AssetService, "GetMesh", null)); + new GetTextureHandler("/CAPS/GetMesh2/" /*+ UUID.Random() */, m_AssetService, "GetMesh2", null, rurl)); } } } \ No newline at end of file -- cgit v1.1