forgotten file

afrisby
MW 2007-10-31 09:26:06 +00:00
parent a9ad16b13a
commit 720065ef9e
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace OpenSim.Framework.Servers
{
public delegate string RestDeserialiseMethod<TRequest>(TRequest request);
public class RestDeserialisehandler<TRequest> : BaseStreamHandler
where TRequest : new()
{
private RestDeserialiseMethod<TRequest> m_method;
public RestDeserialisehandler(string httpMethod, string path, RestDeserialiseMethod<TRequest> method)
: base(httpMethod, path)
{
m_method = method;
}
public override byte[] Handle(string path, Stream request)
{
Type type = typeof(TRequest);
TRequest deserial= default(TRequest);
using (XmlTextReader xreader = new XmlTextReader(request))
{
XmlSerializer serializer = new XmlSerializer(type);
deserial = (TRequest)serializer.Deserialize(xreader);
}
string response = m_method(deserial);
Encoding encoding = new UTF8Encoding(false);
return encoding.GetBytes(response);
}
}
}