diff options
author | lbsa71 | 2007-10-31 12:45:03 +0000 |
---|---|---|
committer | lbsa71 | 2007-10-31 12:45:03 +0000 |
commit | 0d528e1d226283fa9acfafbd60b8a7461f509a85 (patch) | |
tree | 961a56c1e0f4857787a38ba5167dfc48404a9a90 /OpenSim/Framework/Servers/RestDeserialiseHandler.cs | |
parent | fixed bug with user not getting land properties on login (diff) | |
download | opensim-SC-0d528e1d226283fa9acfafbd60b8a7461f509a85.zip opensim-SC-0d528e1d226283fa9acfafbd60b8a7461f509a85.tar.gz opensim-SC-0d528e1d226283fa9acfafbd60b8a7461f509a85.tar.bz2 opensim-SC-0d528e1d226283fa9acfafbd60b8a7461f509a85.tar.xz |
* Added a streamhandler that does streams both in and out
* The RestDeserialisehandler now does streams and returns an object instead of string
Diffstat (limited to 'OpenSim/Framework/Servers/RestDeserialiseHandler.cs')
-rw-r--r-- | OpenSim/Framework/Servers/RestDeserialiseHandler.cs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/OpenSim/Framework/Servers/RestDeserialiseHandler.cs b/OpenSim/Framework/Servers/RestDeserialiseHandler.cs index cb500ca..28084e2 100644 --- a/OpenSim/Framework/Servers/RestDeserialiseHandler.cs +++ b/OpenSim/Framework/Servers/RestDeserialiseHandler.cs | |||
@@ -7,35 +7,35 @@ using System.Xml.Serialization; | |||
7 | 7 | ||
8 | namespace OpenSim.Framework.Servers | 8 | namespace OpenSim.Framework.Servers |
9 | { | 9 | { |
10 | public delegate string RestDeserialiseMethod<TRequest>(TRequest request); | 10 | public delegate TResponse RestDeserialiseMethod<TRequest, TResponse>(TRequest request); |
11 | 11 | ||
12 | public class RestDeserialisehandler<TRequest> : BaseStreamHandler | 12 | public class RestDeserialisehandler<TRequest, TResponse> : BaseRequestHandler, IStreamHandler |
13 | where TRequest : new() | 13 | where TRequest : new() |
14 | { | 14 | { |
15 | private RestDeserialiseMethod<TRequest> m_method; | 15 | private RestDeserialiseMethod<TRequest, TResponse> m_method; |
16 | 16 | ||
17 | public RestDeserialisehandler(string httpMethod, string path, RestDeserialiseMethod<TRequest> method) | 17 | public RestDeserialisehandler(string httpMethod, string path, RestDeserialiseMethod<TRequest, TResponse> method) |
18 | : base(httpMethod, path) | 18 | : base(httpMethod, path) |
19 | { | 19 | { |
20 | m_method = method; | 20 | m_method = method; |
21 | } | 21 | } |
22 | 22 | ||
23 | public override byte[] Handle(string path, Stream request) | 23 | public void Handle(string path, Stream request, Stream responseStream ) |
24 | { | 24 | { |
25 | Type type = typeof(TRequest); | 25 | TRequest deserial; |
26 | 26 | using (XmlTextReader xmlReader = new XmlTextReader(request)) | |
27 | TRequest deserial= default(TRequest); | ||
28 | using (XmlTextReader xreader = new XmlTextReader(request)) | ||
29 | { | 27 | { |
30 | XmlSerializer serializer = new XmlSerializer(type); | 28 | XmlSerializer deserializer = new XmlSerializer(typeof(TRequest)); |
31 | deserial = (TRequest)serializer.Deserialize(xreader); | 29 | deserial = (TRequest)deserializer.Deserialize(xmlReader); |
32 | } | 30 | } |
33 | 31 | ||
34 | string response = m_method(deserial); | 32 | TResponse response = m_method(deserial); |
35 | |||
36 | Encoding encoding = new UTF8Encoding(false); | ||
37 | return encoding.GetBytes(response); | ||
38 | 33 | ||
34 | using (XmlWriter xmlWriter = XmlTextWriter.Create( responseStream )) | ||
35 | { | ||
36 | XmlSerializer serializer = new XmlSerializer(typeof(TResponse)); | ||
37 | serializer.Serialize(xmlWriter, response ); | ||
38 | } | ||
39 | } | 39 | } |
40 | } | 40 | } |
41 | } | 41 | } |