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