aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r--OpenSim/Framework/Servers/GetAssetStreamHandler.cs94
-rw-r--r--OpenSim/Framework/Servers/PostAssetStreamHandler.cs44
2 files changed, 138 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
diff --git a/OpenSim/Framework/Servers/PostAssetStreamHandler.cs b/OpenSim/Framework/Servers/PostAssetStreamHandler.cs
new file mode 100644
index 0000000..a62f2b0
--- /dev/null
+++ b/OpenSim/Framework/Servers/PostAssetStreamHandler.cs
@@ -0,0 +1,44 @@
1using System.IO;
2using System.Reflection;
3using System.Xml.Serialization;
4using log4net;
5using OpenMetaverse;
6using OpenSim.Framework;
7using OpenSim.Framework.Servers;
8
9namespace OpenSim.Framework.Servers
10{
11 public class PostAssetStreamHandler : BaseStreamHandler
12 {
13 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
14
15 // private OpenAsset_Main m_assetManager;
16 private IAssetDataPlugin m_assetProvider;
17
18 public override byte[] Handle(string path, Stream request,
19 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
20 {
21 string param = GetParam(path);
22
23 UUID assetId;
24 if (param.Length > 0)
25 UUID.TryParse(param, out assetId);
26 // byte[] txBuffer = new byte[4096];
27
28 XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
29 AssetBase asset = (AssetBase) xs.Deserialize(request);
30
31 m_log.InfoFormat("[REST]: Creating asset {0}", asset.FullID);
32 m_assetProvider.CreateAsset(asset);
33
34 return new byte[] {};
35 }
36
37 public PostAssetStreamHandler(IAssetDataPlugin assetProvider)
38 : base("POST", "/assets")
39 {
40 // m_assetManager = assetManager;
41 m_assetProvider = assetProvider;
42 }
43 }
44} \ No newline at end of file