diff options
author | lbsa71 | 2009-02-20 02:26:27 +0000 |
---|---|---|
committer | lbsa71 | 2009-02-20 02:26:27 +0000 |
commit | 5e39e515f93649da113973835596749a94637689 (patch) | |
tree | 10210e2531261f643ba1950824fba7decb88eb71 /OpenSim/Framework | |
parent | This moves the 2 friends-related interregion messages out of OGS1 and into th... (diff) | |
download | opensim-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')
-rw-r--r-- | OpenSim/Framework/Servers/GetAssetStreamHandler.cs | 95 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/PostAssetStreamHandler.cs | 45 |
2 files changed, 140 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 @@ | |||
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.Data; | ||
10 | using OpenSim.Framework; | ||
11 | using OpenSim.Framework.Servers; | ||
12 | using OpenSim.Framework.Statistics; | ||
13 | |||
14 | namespace 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 | ||
diff --git a/OpenSim/Framework/Servers/PostAssetStreamHandler.cs b/OpenSim/Framework/Servers/PostAssetStreamHandler.cs new file mode 100644 index 0000000..6e96361 --- /dev/null +++ b/OpenSim/Framework/Servers/PostAssetStreamHandler.cs | |||
@@ -0,0 +1,45 @@ | |||
1 | using System.IO; | ||
2 | using System.Reflection; | ||
3 | using System.Xml.Serialization; | ||
4 | using log4net; | ||
5 | using OpenMetaverse; | ||
6 | using OpenSim.Data; | ||
7 | using OpenSim.Framework; | ||
8 | using OpenSim.Framework.Servers; | ||
9 | |||
10 | namespace OpenSim.Framework.Servers | ||
11 | { | ||
12 | public class PostAssetStreamHandler : BaseStreamHandler | ||
13 | { | ||
14 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
15 | |||
16 | // private OpenAsset_Main m_assetManager; | ||
17 | private IAssetDataPlugin m_assetProvider; | ||
18 | |||
19 | public override byte[] Handle(string path, Stream request, | ||
20 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
21 | { | ||
22 | string param = GetParam(path); | ||
23 | |||
24 | UUID assetId; | ||
25 | if (param.Length > 0) | ||
26 | UUID.TryParse(param, out assetId); | ||
27 | // byte[] txBuffer = new byte[4096]; | ||
28 | |||
29 | XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); | ||
30 | AssetBase asset = (AssetBase) xs.Deserialize(request); | ||
31 | |||
32 | m_log.InfoFormat("[REST]: Creating asset {0}", asset.FullID); | ||
33 | m_assetProvider.CreateAsset(asset); | ||
34 | |||
35 | return new byte[] {}; | ||
36 | } | ||
37 | |||
38 | public PostAssetStreamHandler(IAssetDataPlugin assetProvider) | ||
39 | : base("POST", "/assets") | ||
40 | { | ||
41 | // m_assetManager = assetManager; | ||
42 | m_assetProvider = assetProvider; | ||
43 | } | ||
44 | } | ||
45 | } \ No newline at end of file | ||