* Catch and report deserialization exceptions on rest handlers * Thanks Diva!0.6.0-stable
parent
39691e61a2
commit
ee178c76ae
|
@ -2,10 +2,13 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
using log4net;
|
||||||
|
|
||||||
namespace OpenSim.Framework.Servers
|
namespace OpenSim.Framework.Servers
|
||||||
{
|
{
|
||||||
public class RestSessionObject<TRequest>
|
public class RestSessionObject<TRequest>
|
||||||
|
@ -146,6 +149,9 @@ namespace OpenSim.Framework.Servers
|
||||||
public class RestDeserialiseSecureHandler<TRequest, TResponse> : BaseRequestHandler, IStreamHandler
|
public class RestDeserialiseSecureHandler<TRequest, TResponse> : BaseRequestHandler, IStreamHandler
|
||||||
where TRequest : new()
|
where TRequest : new()
|
||||||
{
|
{
|
||||||
|
private static readonly ILog m_log
|
||||||
|
= LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
private RestDeserialiseMethod<TRequest, TResponse> m_method;
|
private RestDeserialiseMethod<TRequest, TResponse> m_method;
|
||||||
private CheckIdentityMethod m_smethod;
|
private CheckIdentityMethod m_smethod;
|
||||||
|
|
||||||
|
@ -161,15 +167,25 @@ namespace OpenSim.Framework.Servers
|
||||||
public void Handle(string path, Stream request, Stream responseStream,
|
public void Handle(string path, Stream request, Stream responseStream,
|
||||||
OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||||
{
|
{
|
||||||
RestSessionObject<TRequest> deserial;
|
RestSessionObject<TRequest> deserial = default(RestSessionObject<TRequest>);
|
||||||
|
bool fail = false;
|
||||||
|
|
||||||
using (XmlTextReader xmlReader = new XmlTextReader(request))
|
using (XmlTextReader xmlReader = new XmlTextReader(request))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
XmlSerializer deserializer = new XmlSerializer(typeof(RestSessionObject<TRequest>));
|
XmlSerializer deserializer = new XmlSerializer(typeof(RestSessionObject<TRequest>));
|
||||||
deserial = (RestSessionObject<TRequest>)deserializer.Deserialize(xmlReader);
|
deserial = (RestSessionObject<TRequest>)deserializer.Deserialize(xmlReader);
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.Error("[REST]: Deserialization problem. Ignoring request. " + e);
|
||||||
|
fail = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TResponse response = default(TResponse);
|
TResponse response = default(TResponse);
|
||||||
if (m_smethod(deserial.SessionID, deserial.AvatarID))
|
if (!fail && m_smethod(deserial.SessionID, deserial.AvatarID))
|
||||||
{
|
{
|
||||||
response = m_method(deserial.Body);
|
response = m_method(deserial.Body);
|
||||||
}
|
}
|
||||||
|
@ -187,6 +203,9 @@ namespace OpenSim.Framework.Servers
|
||||||
public class RestDeserialiseTrustedHandler<TRequest, TResponse> : BaseRequestHandler, IStreamHandler
|
public class RestDeserialiseTrustedHandler<TRequest, TResponse> : BaseRequestHandler, IStreamHandler
|
||||||
where TRequest : new()
|
where TRequest : new()
|
||||||
{
|
{
|
||||||
|
private static readonly ILog m_log
|
||||||
|
= LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The operation to perform once trust has been established.
|
/// The operation to perform once trust has been established.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -211,15 +230,25 @@ namespace OpenSim.Framework.Servers
|
||||||
public void Handle(string path, Stream request, Stream responseStream,
|
public void Handle(string path, Stream request, Stream responseStream,
|
||||||
OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||||
{
|
{
|
||||||
TRequest deserial;
|
TRequest deserial = default(TRequest);
|
||||||
|
bool fail = false;
|
||||||
|
|
||||||
using (XmlTextReader xmlReader = new XmlTextReader(request))
|
using (XmlTextReader xmlReader = new XmlTextReader(request))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
XmlSerializer deserializer = new XmlSerializer(typeof(TRequest));
|
XmlSerializer deserializer = new XmlSerializer(typeof(TRequest));
|
||||||
deserial = (TRequest)deserializer.Deserialize(xmlReader);
|
deserial = (TRequest)deserializer.Deserialize(xmlReader);
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.Error("[REST]: Deserialization problem. Ignoring request. " + e);
|
||||||
|
fail = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TResponse response = default(TResponse);
|
TResponse response = default(TResponse);
|
||||||
if (m_tmethod(httpRequest.RemoteIPEndPoint))
|
if (!fail && m_tmethod(httpRequest.RemoteIPEndPoint))
|
||||||
{
|
{
|
||||||
response = m_method(deserial);
|
response = m_method(deserial);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue