aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Servers/RestDeserialiseHandler.cs41
1 files changed, 41 insertions, 0 deletions
diff --git a/OpenSim/Framework/Servers/RestDeserialiseHandler.cs b/OpenSim/Framework/Servers/RestDeserialiseHandler.cs
new file mode 100644
index 0000000..cb500ca
--- /dev/null
+++ b/OpenSim/Framework/Servers/RestDeserialiseHandler.cs
@@ -0,0 +1,41 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using System.Xml;
6using System.Xml.Serialization;
7
8namespace OpenSim.Framework.Servers
9{
10 public delegate string RestDeserialiseMethod<TRequest>(TRequest request);
11
12 public class RestDeserialisehandler<TRequest> : BaseStreamHandler
13 where TRequest : new()
14 {
15 private RestDeserialiseMethod<TRequest> m_method;
16
17 public RestDeserialisehandler(string httpMethod, string path, RestDeserialiseMethod<TRequest> method)
18 : base(httpMethod, path)
19 {
20 m_method = method;
21 }
22
23 public override byte[] Handle(string path, Stream request)
24 {
25 Type type = typeof(TRequest);
26
27 TRequest deserial= default(TRequest);
28 using (XmlTextReader xreader = new XmlTextReader(request))
29 {
30 XmlSerializer serializer = new XmlSerializer(type);
31 deserial = (TRequest)serializer.Deserialize(xreader);
32 }
33
34 string response = m_method(deserial);
35
36 Encoding encoding = new UTF8Encoding(false);
37 return encoding.GetBytes(response);
38
39 }
40 }
41}