testing different rest post method/class for Grid asset client. (possible that I haven't set the post url correctly)

afrisby
MW 2007-11-03 14:04:59 +00:00
parent f8e0cf0f1d
commit 91c2c3c096
2 changed files with 60 additions and 9 deletions

View File

@ -32,6 +32,7 @@ using System.IO;
using System.Xml.Serialization; using System.Xml.Serialization;
using libsecondlife; using libsecondlife;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Framework.Servers;
namespace OpenSim.Framework.Communications.Cache namespace OpenSim.Framework.Communications.Cache
{ {
@ -103,16 +104,17 @@ namespace OpenSim.Framework.Communications.Cache
{ {
try try
{ {
MemoryStream s = new MemoryStream(); // MemoryStream s = new MemoryStream();
XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); // XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
xs.Serialize(s, asset); // xs.Serialize(s, asset);
RestClient rc = new RestClient(_assetServerUrl); // RestClient rc = new RestClient(_assetServerUrl);
MainLog.Instance.Verbose("ASSET", "Storing {0}", rc); MainLog.Instance.Verbose("ASSET", "Storing asset");
rc.AddResourcePath("assets"); //rc.AddResourcePath("assets");
rc.RequestMethod = "POST"; // rc.RequestMethod = "POST";
rc.Request(s); // rc.Request(s);
MainLog.Instance.Verbose("ASSET", "Stored {0}", rc); //MainLog.Instance.Verbose("ASSET", "Stored {0}", rc);
RestObjectPoster.BeginPostObject<AssetBase>(_assetRequests + "/assets/", asset);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -0,0 +1,49 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace OpenSim.Framework.Servers
{
public class RestObjectPoster
{
public static void BeginPostObject<TRequest>(string requestUrl, TRequest obj)
{
Type type = typeof(TRequest);
WebRequest request = WebRequest.Create(requestUrl);
request.Method = "POST";
request.ContentType = "text/xml";
MemoryStream buffer = new MemoryStream();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
using (XmlWriter writer = XmlWriter.Create(buffer, settings))
{
XmlSerializer serializer = new XmlSerializer(type);
serializer.Serialize(writer, obj);
writer.Flush();
}
int length = (int)buffer.Length;
request.ContentLength = length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer.ToArray(), 0, length);
IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
}
private static void AsyncCallback(IAsyncResult result)
{
WebRequest request = (WebRequest)result.AsyncState;
using (WebResponse resp = request.EndGetResponse(result))
{
}
}
}
}