aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/GetAssetStreamHandler.cs
diff options
context:
space:
mode:
authorlbsa712009-02-19 19:04:51 +0000
committerlbsa712009-02-19 19:04:51 +0000
commit1bcc489f5b4fa2ba945258777840eb980caab489 (patch)
treed3ed864a6119048b2401819d1f32b76ddec26d47 /OpenSim/Framework/Servers/GetAssetStreamHandler.cs
parent* moved the Get/PostAssetStreamHandler to the Servers namespace... slowly get... (diff)
downloadopensim-SC_OLD-1bcc489f5b4fa2ba945258777840eb980caab489.zip
opensim-SC_OLD-1bcc489f5b4fa2ba945258777840eb980caab489.tar.gz
opensim-SC_OLD-1bcc489f5b4fa2ba945258777840eb980caab489.tar.bz2
opensim-SC_OLD-1bcc489f5b4fa2ba945258777840eb980caab489.tar.xz
* Moved the AssetStreamHandlers to OpenSim.Framework.Servers
* And there, all refs to OpenSim.Grid.AssetServer.exe gone. /me takes a bow.
Diffstat (limited to 'OpenSim/Framework/Servers/GetAssetStreamHandler.cs')
-rw-r--r--OpenSim/Framework/Servers/GetAssetStreamHandler.cs94
1 files changed, 94 insertions, 0 deletions
diff --git a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs
new file mode 100644
index 0000000..093461d
--- /dev/null
+++ b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs
@@ -0,0 +1,94 @@
1using System;
2using System.IO;
3using System.Reflection;
4using System.Text;
5using System.Xml;
6using System.Xml.Serialization;
7using log4net;
8using OpenMetaverse;
9using OpenSim.Framework;
10using OpenSim.Framework.Servers;
11using OpenSim.Framework.Statistics;
12
13namespace OpenSim.Framework.Servers
14{
15 public class GetAssetStreamHandler : BaseStreamHandler
16 {
17 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
18
19 // private OpenAsset_Main m_assetManager;
20 private IAssetDataPlugin m_assetProvider;
21
22 /// <summary>
23 /// Constructor.
24 /// </summary>
25 /// <param name="assetManager"></param>
26 /// <param name="assetProvider"></param>
27 public GetAssetStreamHandler(IAssetDataPlugin assetProvider)
28 : base("GET", "/assets")
29 {
30 m_log.Info("[REST]: In Get Request");
31 // m_assetManager = assetManager;
32 m_assetProvider = assetProvider;
33 }
34
35 public override byte[] Handle(string path, Stream request,
36 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
37 {
38 string param = GetParam(path);
39 byte[] result = new byte[] {};
40
41 string[] p = param.Split(new char[] {'/', '?', '&'}, StringSplitOptions.RemoveEmptyEntries);
42
43 if (p.Length > 0)
44 {
45 UUID assetID = UUID.Zero;
46
47 if (!UUID.TryParse(p[0], out assetID))
48 {
49 m_log.InfoFormat(
50 "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]);
51 return result;
52 }
53
54 if (StatsManager.AssetStats != null)
55 StatsManager.AssetStats.AddRequest();
56
57 AssetBase asset = m_assetProvider.FetchAsset(assetID);
58 if (asset != null)
59 {
60 XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
61 MemoryStream ms = new MemoryStream();
62 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
63 xw.Formatting = Formatting.Indented;
64 xs.Serialize(xw, asset);
65 xw.Flush();
66
67 ms.Seek(0, SeekOrigin.Begin);
68 //StreamReader sr = new StreamReader(ms);
69
70 result = ms.GetBuffer();
71
72//Ckrinke 1/11/09 Commenting out the succesful REST message as under heavy use there
73//are multiple messages in a second and that is usually (in my experience) meaning
74//the logging itself is slowing down the program. Leaving the unsuccesful message
75//as we need to know about that path.
76// m_log.InfoFormat(
77// "[REST]: GET:/asset found {0} with name {1}, size {2} bytes",
78// assetID, asset.Name, result.Length);
79
80 Array.Resize<byte>(ref result, (int) ms.Length);
81 }
82 else
83 {
84 if (StatsManager.AssetStats != null)
85 StatsManager.AssetStats.AddNotFoundRequest();
86
87 m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID);
88 }
89 }
90
91 return result;
92 }
93 }
94} \ No newline at end of file