diff options
author | Justin Clark-Casey (justincc) | 2014-10-14 18:37:22 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-11-25 23:21:38 +0000 |
commit | 16a5e154436fc56235ac03846d4bb1ba4d21ac87 (patch) | |
tree | 19ed04e82bfa813519e7d55f70e575bfd5e4f585 /OpenSim/Capabilities/Handlers/GetMesh | |
parent | Start JobEngine by default in simulator for now. (diff) | |
download | opensim-SC-16a5e154436fc56235ac03846d4bb1ba4d21ac87.zip opensim-SC-16a5e154436fc56235ac03846d4bb1ba4d21ac87.tar.gz opensim-SC-16a5e154436fc56235ac03846d4bb1ba4d21ac87.tar.bz2 opensim-SC-16a5e154436fc56235ac03846d4bb1ba4d21ac87.tar.xz |
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).
Diffstat (limited to 'OpenSim/Capabilities/Handlers/GetMesh')
-rw-r--r-- | OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs | 60 | ||||
-rw-r--r-- | OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs | 11 |
2 files changed, 31 insertions, 40 deletions
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; | |||
30 | using System.Collections.Specialized; | 30 | using System.Collections.Specialized; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.IO; | 32 | using System.IO; |
33 | using System.Text; | ||
33 | using System.Web; | 34 | using System.Web; |
34 | using log4net; | 35 | using log4net; |
35 | using Nini.Config; | 36 | using Nini.Config; |
@@ -43,41 +44,37 @@ using Caps = OpenSim.Framework.Capabilities.Caps; | |||
43 | 44 | ||
44 | namespace OpenSim.Capabilities.Handlers | 45 | namespace OpenSim.Capabilities.Handlers |
45 | { | 46 | { |
46 | public class GetMeshHandler | 47 | public class GetMeshHandler : BaseStreamHandler |
47 | { | 48 | { |
48 | // private static readonly ILog m_log = | 49 | // private static readonly ILog m_log = |
49 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 50 | // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
50 | 51 | ||
51 | private IAssetService m_assetService; | 52 | private IAssetService m_assetService; |
52 | 53 | ||
53 | public GetMeshHandler(IAssetService assService) | 54 | public GetMeshHandler(string path, IAssetService assService, string name, string description) |
55 | : base("GET", path, name, description) | ||
54 | { | 56 | { |
55 | m_assetService = assService; | 57 | m_assetService = assService; |
56 | } | 58 | } |
57 | 59 | ||
58 | public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap) | 60 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
59 | { | 61 | { |
60 | Hashtable responsedata = new Hashtable(); | 62 | // Try to parse the texture ID from the request URL |
61 | responsedata["int_response_code"] = 400; //501; //410; //404; | 63 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); |
62 | responsedata["content_type"] = "text/plain"; | 64 | string meshStr = query.GetOne("mesh_id"); |
63 | responsedata["keepalive"] = false; | ||
64 | responsedata["str_response_string"] = "Request wasn't what was expected"; | ||
65 | 65 | ||
66 | string meshStr = string.Empty; | 66 | // m_log.DebugFormat("Fetching mesh {0}", meshStr); |
67 | |||
68 | if (request.ContainsKey("mesh_id")) | ||
69 | meshStr = request["mesh_id"].ToString(); | ||
70 | 67 | ||
71 | UUID meshID = UUID.Zero; | 68 | UUID meshID = UUID.Zero; |
72 | if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) | 69 | if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID)) |
73 | { | 70 | { |
74 | if (m_assetService == null) | 71 | if (m_assetService == null) |
75 | { | 72 | { |
76 | responsedata["int_response_code"] = 404; //501; //410; //404; | 73 | httpResponse.StatusCode = 404; |
77 | responsedata["content_type"] = "text/plain"; | 74 | httpResponse.ContentType = "text/plain"; |
78 | responsedata["keepalive"] = false; | 75 | byte[] data = Encoding.UTF8.GetBytes("The asset service is unavailable. So is your mesh."); |
79 | responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh."; | 76 | httpResponse.Body.Write(data, 0, data.Length); |
80 | return responsedata; | 77 | return null; |
81 | } | 78 | } |
82 | 79 | ||
83 | AssetBase mesh = m_assetService.Get(meshID.ToString()); | 80 | AssetBase mesh = m_assetService.Get(meshID.ToString()); |
@@ -86,31 +83,32 @@ namespace OpenSim.Capabilities.Handlers | |||
86 | { | 83 | { |
87 | if (mesh.Type == (SByte)AssetType.Mesh) | 84 | if (mesh.Type == (SByte)AssetType.Mesh) |
88 | { | 85 | { |
89 | responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data); | 86 | byte[] data = mesh.Data; |
90 | responsedata["content_type"] = "application/vnd.ll.mesh"; | 87 | httpResponse.Body.Write(data, 0, data.Length); |
91 | responsedata["int_response_code"] = 200; | 88 | httpResponse.ContentType = "application/vnd.ll.mesh"; |
89 | httpResponse.StatusCode = 200; | ||
92 | } | 90 | } |
93 | // Optionally add additional mesh types here | 91 | // Optionally add additional mesh types here |
94 | else | 92 | else |
95 | { | 93 | { |
96 | responsedata["int_response_code"] = 404; //501; //410; //404; | 94 | httpResponse.StatusCode = 404; |
97 | responsedata["content_type"] = "text/plain"; | 95 | httpResponse.ContentType = "text/plain"; |
98 | responsedata["keepalive"] = false; | 96 | byte[] data = Encoding.UTF8.GetBytes("Unfortunately, this asset isn't a mesh."); |
99 | responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh."; | 97 | httpResponse.Body.Write(data, 0, data.Length); |
100 | return responsedata; | 98 | httpResponse.KeepAlive = false; |
101 | } | 99 | } |
102 | } | 100 | } |
103 | else | 101 | else |
104 | { | 102 | { |
105 | responsedata["int_response_code"] = 404; //501; //410; //404; | 103 | httpResponse.StatusCode = 404; |
106 | responsedata["content_type"] = "text/plain"; | 104 | httpResponse.ContentType = "text/plain"; |
107 | responsedata["keepalive"] = false; | 105 | byte[] data = Encoding.UTF8.GetBytes("Your Mesh wasn't found. Sorry!"); |
108 | responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!"; | 106 | httpResponse.Body.Write(data, 0, data.Length); |
109 | return responsedata; | 107 | httpResponse.KeepAlive = false; |
110 | } | 108 | } |
111 | } | 109 | } |
112 | 110 | ||
113 | return responsedata; | 111 | return null; |
114 | } | 112 | } |
115 | } | 113 | } |
116 | } \ No newline at end of file | 114 | } \ 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 | |||
65 | if (m_AssetService == null) | 65 | if (m_AssetService == null) |
66 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); | 66 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); |
67 | 67 | ||
68 | GetMeshHandler gmeshHandler = new GetMeshHandler(m_AssetService); | 68 | server.AddStreamHandler( |
69 | IRequestHandler reqHandler | 69 | new GetMeshHandler("/CAPS/GetMesh/" /*+ UUID.Random() */, m_AssetService, "GetMesh", null)); |
70 | = new RestHTTPHandler( | ||
71 | "GET", | ||
72 | "/CAPS/" + UUID.Random(), | ||
73 | httpMethod => gmeshHandler.ProcessGetMesh(httpMethod, UUID.Zero, null), | ||
74 | "GetMesh", | ||
75 | null); | ||
76 | server.AddStreamHandler(reqHandler); | ||
77 | } | 70 | } |
78 | } | 71 | } |
79 | } \ No newline at end of file | 72 | } \ No newline at end of file |