* Refactor: Remove redundant try/catch from asset request since this is now handled by the base http server

0.6.0-stable
Justin Clarke Casey 2008-04-18 15:41:13 +00:00
parent acb0b06fed
commit afb06c7b88
1 changed files with 42 additions and 47 deletions

View File

@ -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))
{
LLUUID assetID = null;
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)
{
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