aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
diff options
context:
space:
mode:
authorMike Mazur2009-02-16 02:28:34 +0000
committerMike Mazur2009-02-16 02:28:34 +0000
commitab5e3328323a66028bfd47562d9d515dbec433be (patch)
treed81184cd1f8788c20b4600649195be66e03f48c3 /OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
parentWe need to return a zero-length byte array from the Handle() routine. (diff)
downloadopensim-SC_OLD-ab5e3328323a66028bfd47562d9d515dbec433be.zip
opensim-SC_OLD-ab5e3328323a66028bfd47562d9d515dbec433be.tar.gz
opensim-SC_OLD-ab5e3328323a66028bfd47562d9d515dbec433be.tar.bz2
opensim-SC_OLD-ab5e3328323a66028bfd47562d9d515dbec433be.tar.xz
- removed OpenSim.Grid.AssetInventoryServer.Metadata class in favor of
OpenSim.Framework.AssetMetadata and related updates in AssetInventory server - removed dependency on MySql.Data.MySqlClient - commented out the bulk of OpenSimInventoryStorage due to missing MySql.Data dependency - refactor asset creation in OpenSimAssetFrontend - commented out ForEach implementation, which also depended on MySql.Data, until it's supported by OpenSim backends - commented out some handlers in BrowseFrontend and ReferenceFrontend as they relied on either ForEach or the removed Metadata class
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs')
-rw-r--r--OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs392
1 files changed, 196 insertions, 196 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
index 7ff5dfa..f19be08 100644
--- a/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
+++ b/OpenSim/Grid/AssetInventoryServer/Plugins/ReferenceFrontendPlugin.cs
@@ -55,13 +55,13 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
55 m_server = server; 55 m_server = server;
56 56
57 // Asset metadata request 57 // Asset metadata request
58 m_server.HttpServer.AddStreamHandler(new MetadataRequestHandler(server)); 58 //m_server.HttpServer.AddStreamHandler(new MetadataRequestHandler(server));
59 59
60 // Asset data request 60 // Asset data request
61 m_server.HttpServer.AddStreamHandler(new DataRequestHandler(server)); 61 m_server.HttpServer.AddStreamHandler(new DataRequestHandler(server));
62 62
63 // Asset creation 63 // Asset creation
64 m_server.HttpServer.AddStreamHandler(new CreateRequestHandler(server)); 64 //m_server.HttpServer.AddStreamHandler(new CreateRequestHandler(server));
65 65
66 m_log.Info("[ASSET] Reference Frontend loaded."); 66 m_log.Info("[ASSET] Reference Frontend loaded.");
67 } 67 }
@@ -92,95 +92,95 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
92 92
93 #endregion IPlugin implementation 93 #endregion IPlugin implementation
94 94
95 public class MetadataRequestHandler : IStreamedRequestHandler 95 //public class MetadataRequestHandler : IStreamedRequestHandler
96 { 96 //{
97 AssetInventoryServer m_server; 97 // AssetInventoryServer m_server;
98 string m_contentType; 98 // string m_contentType;
99 string m_httpMethod; 99 // string m_httpMethod;
100 string m_path; 100 // string m_path;
101 101
102 public MetadataRequestHandler(AssetInventoryServer server) 102 // public MetadataRequestHandler(AssetInventoryServer server)
103 { 103 // {
104 m_server = server; 104 // m_server = server;
105 m_contentType = null; 105 // m_contentType = null;
106 m_httpMethod = "GET"; 106 // m_httpMethod = "GET";
107 m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata"; 107 // m_path = @"^/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/metadata";
108 } 108 // }
109 109
110 #region IStreamedRequestHandler implementation 110 // #region IStreamedRequestHandler implementation
111 111
112 public string ContentType 112 // public string ContentType
113 { 113 // {
114 get { return m_contentType; } 114 // get { return m_contentType; }
115 } 115 // }
116 116
117 public string HttpMethod 117 // public string HttpMethod
118 { 118 // {
119 get { return m_httpMethod; } 119 // get { return m_httpMethod; }
120 } 120 // }
121 121
122 public string Path 122 // public string Path
123 { 123 // {
124 get { return m_path; } 124 // get { return m_path; }
125 } 125 // }
126 126
127 public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) 127 // public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
128 { 128 // {
129 byte[] serializedData = null; 129 // byte[] serializedData = null;
130 UUID assetID; 130 // UUID assetID;
131 // Split the URL up into an AssetID and a method 131 // // Split the URL up into an AssetID and a method
132 string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/'); 132 // string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
133 133
134 if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID)) 134 // if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
135 { 135 // {
136 UUID authToken = Utils.GetAuthToken(httpRequest); 136 // UUID authToken = Utils.GetAuthToken(httpRequest);
137 137
138 if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID)) 138 // if (m_server.AuthorizationProvider.IsMetadataAuthorized(authToken, assetID))
139 { 139 // {
140 Metadata metadata; 140 // AssetMetadata metadata;
141 BackendResponse storageResponse = m_server.StorageProvider.TryFetchMetadata(assetID, out metadata); 141 // BackendResponse storageResponse = m_server.StorageProvider.TryFetchMetadata(assetID, out metadata);
142 142
143 if (storageResponse == BackendResponse.Success) 143 // if (storageResponse == BackendResponse.Success)
144 { 144 // {
145 // If the asset data location wasn't specified in the metadata, specify it 145 // // If the asset data location wasn't specified in the metadata, specify it
146 // manually here by pointing back to this asset server 146 // // manually here by pointing back to this asset server
147 if (!metadata.Methods.ContainsKey("data")) 147 // if (!metadata.Methods.ContainsKey("data"))
148 { 148 // {
149 metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data", 149 // metadata.Methods["data"] = new Uri(String.Format("{0}://{1}/{2}/data",
150 httpRequest.Url.Scheme, httpRequest.Url.Authority, assetID)); 150 // httpRequest.Url.Scheme, httpRequest.Url.Authority, assetID));
151 } 151 // }
152 152
153 serializedData = metadata.SerializeToBytes(); 153 // serializedData = metadata.SerializeToBytes();
154 154
155 httpResponse.StatusCode = (int) HttpStatusCode.OK; 155 // httpResponse.StatusCode = (int) HttpStatusCode.OK;
156 httpResponse.ContentType = "application/json"; 156 // httpResponse.ContentType = "application/json";
157 httpResponse.ContentLength = serializedData.Length; 157 // httpResponse.ContentLength = serializedData.Length;
158 httpResponse.Body.Write(serializedData, 0, serializedData.Length); 158 // httpResponse.Body.Write(serializedData, 0, serializedData.Length);
159 } 159 // }
160 else if (storageResponse == BackendResponse.NotFound) 160 // else if (storageResponse == BackendResponse.NotFound)
161 { 161 // {
162 m_log.Warn("Could not find metadata for asset " + assetID.ToString()); 162 // m_log.Warn("Could not find metadata for asset " + assetID.ToString());
163 httpResponse.StatusCode = (int) HttpStatusCode.NotFound; 163 // httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
164 } 164 // }
165 else 165 // else
166 { 166 // {
167 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; 167 // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
168 } 168 // }
169 } 169 // }
170 else 170 // else
171 { 171 // {
172 httpResponse.StatusCode = (int) HttpStatusCode.Forbidden; 172 // httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
173 } 173 // }
174 174
175 return serializedData; 175 // return serializedData;
176 } 176 // }
177 177
178 httpResponse.StatusCode = (int) HttpStatusCode.NotFound; 178 // httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
179 return serializedData; 179 // return serializedData;
180 } 180 // }
181 181
182 #endregion IStreamedRequestHandler implementation 182 // #endregion IStreamedRequestHandler implementation
183 } 183 //}
184 184
185 public class DataRequestHandler : IStreamedRequestHandler 185 public class DataRequestHandler : IStreamedRequestHandler
186 { 186 {
@@ -261,110 +261,110 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins
261 #endregion IStreamedRequestHandler implementation 261 #endregion IStreamedRequestHandler implementation
262 } 262 }
263 263
264 public class CreateRequestHandler : IStreamedRequestHandler 264 //public class CreateRequestHandler : IStreamedRequestHandler
265 { 265 //{
266 AssetInventoryServer m_server; 266 // AssetInventoryServer m_server;
267 string m_contentType; 267 // string m_contentType;
268 string m_httpMethod; 268 // string m_httpMethod;
269 string m_path; 269 // string m_path;
270 270
271 public CreateRequestHandler(AssetInventoryServer server) 271 // public CreateRequestHandler(AssetInventoryServer server)
272 { 272 // {
273 m_server = server; 273 // m_server = server;
274 m_contentType = null; 274 // m_contentType = null;
275 m_httpMethod = "POST"; 275 // m_httpMethod = "POST";
276 m_path = "^/createasset"; 276 // m_path = "^/createasset";
277 } 277 // }
278 278
279 #region IStreamedRequestHandler implementation 279 // #region IStreamedRequestHandler implementation
280 280
281 public string ContentType 281 // public string ContentType
282 { 282 // {
283 get { return m_contentType; } 283 // get { return m_contentType; }
284 } 284 // }
285 285
286 public string HttpMethod 286 // public string HttpMethod
287 { 287 // {
288 get { return m_httpMethod; } 288 // get { return m_httpMethod; }
289 } 289 // }
290 290
291 public string Path 291 // public string Path
292 { 292 // {
293 get { return m_path; } 293 // get { return m_path; }
294 } 294 // }
295 295
296 public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) 296 // public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
297 { 297 // {
298 byte[] responseData = null; 298 // byte[] responseData = null;
299 UUID authToken = Utils.GetAuthToken(httpRequest); 299 // UUID authToken = Utils.GetAuthToken(httpRequest);
300 300
301 if (m_server.AuthorizationProvider.IsCreateAuthorized(authToken)) 301 // if (m_server.AuthorizationProvider.IsCreateAuthorized(authToken))
302 { 302 // {
303 try 303 // try
304 { 304 // {
305 OSD osdata = OSDParser.DeserializeJson(new StreamReader(httpRequest.InputStream).ReadToEnd()); 305 // OSD osdata = OSDParser.DeserializeJson(new StreamReader(httpRequest.InputStream).ReadToEnd());
306 306
307 if (osdata.Type == OSDType.Map) 307 // if (osdata.Type == OSDType.Map)
308 { 308 // {
309 OSDMap map = (OSDMap)osdata; 309 // OSDMap map = (OSDMap)osdata;
310 Metadata metadata = new Metadata(); 310 // Metadata metadata = new Metadata();
311 metadata.Deserialize(map); 311 // metadata.Deserialize(map);
312 312
313 byte[] assetData = map["data"].AsBinary(); 313 // byte[] assetData = map["data"].AsBinary();
314 314
315 if (assetData != null && assetData.Length > 0) 315 // if (assetData != null && assetData.Length > 0)
316 { 316 // {
317 BackendResponse storageResponse; 317 // BackendResponse storageResponse;
318 318
319 if (metadata.ID != UUID.Zero) 319 // if (metadata.ID != UUID.Zero)
320 storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData); 320 // storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData);
321 else 321 // else
322 storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID); 322 // storageResponse = m_server.StorageProvider.TryCreateAsset(metadata, assetData, out metadata.ID);
323 323
324 if (storageResponse == BackendResponse.Success) 324 // if (storageResponse == BackendResponse.Success)
325 { 325 // {
326 httpResponse.StatusCode = (int) HttpStatusCode.Created; 326 // httpResponse.StatusCode = (int) HttpStatusCode.Created;
327 OSDMap responseMap = new OSDMap(1); 327 // OSDMap responseMap = new OSDMap(1);
328 responseMap["id"] = OSD.FromUUID(metadata.ID); 328 // responseMap["id"] = OSD.FromUUID(metadata.ID);
329 LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap); 329 // LitJson.JsonData jsonData = OSDParser.SerializeJson(responseMap);
330 responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson()); 330 // responseData = System.Text.Encoding.UTF8.GetBytes(jsonData.ToJson());
331 httpResponse.Body.Write(responseData, 0, responseData.Length); 331 // httpResponse.Body.Write(responseData, 0, responseData.Length);
332 httpResponse.Body.Flush(); 332 // httpResponse.Body.Flush();
333 } 333 // }
334 else if (storageResponse == BackendResponse.NotFound) 334 // else if (storageResponse == BackendResponse.NotFound)
335 { 335 // {
336 httpResponse.StatusCode = (int) HttpStatusCode.NotFound; 336 // httpResponse.StatusCode = (int) HttpStatusCode.NotFound;
337 } 337 // }
338 else 338 // else
339 { 339 // {
340 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; 340 // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
341 } 341 // }
342 } 342 // }
343 else 343 // else
344 { 344 // {
345 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; 345 // httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
346 } 346 // }
347 } 347 // }
348 else 348 // else
349 { 349 // {
350 httpResponse.StatusCode = (int) HttpStatusCode.BadRequest; 350 // httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
351 } 351 // }
352 } 352 // }
353 catch (Exception ex) 353 // catch (Exception ex)
354 { 354 // {
355 httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError; 355 // httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
356 httpResponse.StatusDescription = ex.Message; 356 // httpResponse.StatusDescription = ex.Message;
357 } 357 // }
358 } 358 // }
359 else 359 // else
360 { 360 // {
361 httpResponse.StatusCode = (int) HttpStatusCode.Forbidden; 361 // httpResponse.StatusCode = (int) HttpStatusCode.Forbidden;
362 } 362 // }
363 363
364 return responseData; 364 // return responseData;
365 } 365 // }
366 366
367 #endregion IStreamedRequestHandler implementation 367 // #endregion IStreamedRequestHandler implementation
368 } 368 //}
369 } 369 }
370} 370}