diff options
author | lbsa71 | 2009-02-19 18:53:43 +0000 |
---|---|---|
committer | lbsa71 | 2009-02-19 18:53:43 +0000 |
commit | 00a5fb9484592d8d37b38cebd96d0f399bbe4ebf (patch) | |
tree | 13005261c263ecb09857e92fd0c9b8ae05afec8c /OpenSim/Grid/AssetServer/GetAssetStreamHandler.cs | |
parent | * Changed Prebuild.xml back to specifying xmlns (diff) | |
download | opensim-SC_OLD-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.zip opensim-SC_OLD-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.tar.gz opensim-SC_OLD-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.tar.bz2 opensim-SC_OLD-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.tar.xz |
* Split RestService.cs into GetAssetStreamHandler.cs and PostAssetStreamHandler.cs - then killed off original (misnomed) file.
* Really, who wrote this jurassic shit code all with totally wrong file names? Ah yeah, that'd be me. Sorry.
Diffstat (limited to 'OpenSim/Grid/AssetServer/GetAssetStreamHandler.cs')
-rw-r--r-- | OpenSim/Grid/AssetServer/GetAssetStreamHandler.cs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/OpenSim/Grid/AssetServer/GetAssetStreamHandler.cs b/OpenSim/Grid/AssetServer/GetAssetStreamHandler.cs new file mode 100644 index 0000000..56cd52b --- /dev/null +++ b/OpenSim/Grid/AssetServer/GetAssetStreamHandler.cs | |||
@@ -0,0 +1,94 @@ | |||
1 | using System; | ||
2 | using System.IO; | ||
3 | using System.Reflection; | ||
4 | using System.Text; | ||
5 | using System.Xml; | ||
6 | using System.Xml.Serialization; | ||
7 | using log4net; | ||
8 | using OpenMetaverse; | ||
9 | using OpenSim.Framework; | ||
10 | using OpenSim.Framework.Servers; | ||
11 | using OpenSim.Framework.Statistics; | ||
12 | |||
13 | namespace OpenSim.Grid.AssetServer | ||
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 | ||