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') 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