Make remote assets work through the new server system

0.6.5-rc1
Melanie Thielker 2009-05-09 04:03:32 +00:00
parent b2b13c5a42
commit b3d29aaeb3
3 changed files with 84 additions and 24 deletions

View File

@ -52,30 +52,42 @@ namespace OpenSim.Framework.Servers.HttpServer
WebRequest request = WebRequest.Create(requestUrl);
request.Method = verb;
request.ContentType = "text/xml";
MemoryStream buffer = new MemoryStream();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
using (XmlWriter writer = XmlWriter.Create(buffer, settings))
if (verb == "POST")
{
XmlSerializer serializer = new XmlSerializer(type);
serializer.Serialize(writer, obj);
writer.Flush();
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);
}
int length = (int) buffer.Length;
request.ContentLength = length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer.ToArray(), 0, length);
TResponse deserial = default(TResponse);
using (WebResponse resp = request.GetResponse())
try
{
XmlSerializer deserializer = new XmlSerializer(typeof (TResponse));
deserial = (TResponse) deserializer.Deserialize(resp.GetResponseStream());
using (WebResponse resp = request.GetResponse())
{
XmlSerializer deserializer = new XmlSerializer(typeof (TResponse));
deserial = (TResponse) deserializer.Deserialize(resp.GetResponseStream());
}
}
catch (System.InvalidOperationException)
{
// This is what happens when there is invalid XML
}
return deserial;
}

View File

@ -27,12 +27,15 @@
using log4net;
using System;
using System.IO;
using System.Reflection;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using OpenSim.Framework.Communications;
namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
{
@ -76,6 +79,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
}
m_Enabled = true;
m_ServerURI = serviceURI;
m_log.Info("[ASSET CONNECTOR]: Remote assets enabled");
}
}
}
@ -106,31 +111,74 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
public AssetBase Get(string id)
{
return null;
string uri = m_ServerURI + "/assets/" + id;
AssetBase asset = SynchronousRestObjectPoster.
BeginPostObject<int, AssetBase>("GET", uri, 0);
return asset;
}
public AssetMetadata GetMetadata(string id)
{
return null;
string uri = m_ServerURI + "/assets/" + id + "/metadata";
AssetMetadata asset = SynchronousRestObjectPoster.
BeginPostObject<int, AssetMetadata>("GET", uri, 0);
return asset;
}
public byte[] GetData(string id)
{
return new byte[0];
RestClient rc = new RestClient(m_ServerURI);
rc.AddResourcePath("assets");
rc.AddResourcePath(id);
rc.AddResourcePath("data");
rc.RequestMethod = "GET";
Stream s = rc.Request();
if (s == null)
return null;
if (s.Length > 0)
{
byte[] ret = new byte[s.Length];
s.Read(ret, 0, (int)s.Length);
return ret;
}
return null;
}
public string Store(AssetBase asset)
{
return String.Empty;
string uri = m_ServerURI + "/assets/";
string newID = SynchronousRestObjectPoster.
BeginPostObject<AssetBase, string>("POST", uri, asset);
return newID;
}
public bool UpdateContent(string id, byte[] data)
{
return false;
AssetBase asset = new AssetBase();
asset.ID = id;
asset.Data = data;
string uri = m_ServerURI + "/assets/" + id;
return SynchronousRestObjectPoster.
BeginPostObject<AssetBase, bool>("POST", uri, asset);
}
public bool Delete(string id)
{
string uri = m_ServerURI + "/assets/" + id;
return SynchronousRestObjectPoster.
BeginPostObject<int, bool>("DELETE", uri, 0);
return false;
}
}

View File

@ -66,7 +66,7 @@ namespace OpenSim.Servers.AssetServer
if (p.Length > 1)
{
bool result =
m_AssetService.UpdateContent(asset.ID, asset.Data);
m_AssetService.UpdateContent(p[1], asset.Data);
xs = new XmlSerializer(typeof(bool));
return ServerUtils.SerializeResult(xs, result);