diff options
author | MW | 2007-10-31 09:26:06 +0000 |
---|---|---|
committer | MW | 2007-10-31 09:26:06 +0000 |
commit | 720065ef9e28896052cbcc1514ea35e068bda872 (patch) | |
tree | 2f48ac8f436ac9b0b0ce7a1e35a5c3870e0a874d /OpenSim/Framework/Servers/RestDeserialiseHandler.cs | |
parent | some small changes (diff) | |
download | opensim-SC-720065ef9e28896052cbcc1514ea35e068bda872.zip opensim-SC-720065ef9e28896052cbcc1514ea35e068bda872.tar.gz opensim-SC-720065ef9e28896052cbcc1514ea35e068bda872.tar.bz2 opensim-SC-720065ef9e28896052cbcc1514ea35e068bda872.tar.xz |
forgotten file
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Servers/RestDeserialiseHandler.cs | 41 |
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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using System.IO; | ||
5 | using System.Xml; | ||
6 | using System.Xml.Serialization; | ||
7 | |||
8 | namespace 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 | } | ||