From afb06c7b88f4dab1a4cb0ba6b2002a19e40683c2 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 18 Apr 2008 15:41:13 +0000 Subject: * Refactor: Remove redundant try/catch from asset request since this is now handled by the base http server --- OpenSim/Grid/AssetServer/RestService.cs | 89 ++++++++++++++++----------------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/OpenSim/Grid/AssetServer/RestService.cs b/OpenSim/Grid/AssetServer/RestService.cs index a9856da..ae56a68 100644 --- a/OpenSim/Grid/AssetServer/RestService.cs +++ b/OpenSim/Grid/AssetServer/RestService.cs @@ -62,60 +62,55 @@ namespace OpenSim.Grid.AssetServer { string param = GetParam(path); byte[] result = new byte[] {}; - try - { - string[] p = param.Split(new char[] {'/', '?', '&'}, StringSplitOptions.RemoveEmptyEntries); - if (p.Length > 0) + string[] p = param.Split(new char[] {'/', '?', '&'}, StringSplitOptions.RemoveEmptyEntries); + + if (p.Length > 0) + { + LLUUID assetID = null; + + if (!LLUUID.TryParse(p[0], out assetID)) + { + m_log.InfoFormat( + "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]); + return result; + } + + if (StatsManager.AssetStats != null) + StatsManager.AssetStats.AddRequest(); + + AssetBase asset = m_assetProvider.FetchAsset(assetID); + if (asset != null) { - LLUUID assetID = null; + XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); + MemoryStream ms = new MemoryStream(); + XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8); + xw.Formatting = Formatting.Indented; + xs.Serialize(xw, asset); + xw.Flush(); + + ms.Seek(0, SeekOrigin.Begin); + //StreamReader sr = new StreamReader(ms); + + result = ms.GetBuffer(); - if (!LLUUID.TryParse(p[0], out assetID)) - { - m_log.InfoFormat( - "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]); - return result; - } - + m_log.InfoFormat( + "[REST]: GET:/asset found {0} with name {1}, size {2} bytes", + assetID, asset.Name, result.Length); + + Array.Resize<byte>(ref result, (int) ms.Length); + } + else + { if (StatsManager.AssetStats != null) - StatsManager.AssetStats.AddRequest(); + StatsManager.AssetStats.AddNotFoundRequest(); - AssetBase asset = m_assetProvider.FetchAsset(assetID); - if (asset != null) - { - XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); - MemoryStream ms = new MemoryStream(); - XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8); - xw.Formatting = Formatting.Indented; - xs.Serialize(xw, asset); - xw.Flush(); - - ms.Seek(0, SeekOrigin.Begin); - //StreamReader sr = new StreamReader(ms); - - result = ms.GetBuffer(); - - m_log.InfoFormat( - "[REST]: GET:/asset found {0} with name {1}, size {2} bytes", - assetID, asset.Name, result.Length); - - Array.Resize<byte>(ref result, (int) ms.Length); - } - else - { - if (StatsManager.AssetStats != null) - StatsManager.AssetStats.AddNotFoundRequest(); - - m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID); - } + m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID); } } - catch (Exception e) - { - m_log.Error(e.ToString()); - } - return result; - } + + return result; + } } public class PostAssetStreamHandler : BaseStreamHandler -- cgit v1.1