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,6 +52,9 @@ namespace OpenSim.Framework.Servers.HttpServer
WebRequest request = WebRequest.Create(requestUrl); WebRequest request = WebRequest.Create(requestUrl);
request.Method = verb; request.Method = verb;
if (verb == "POST")
{
request.ContentType = "text/xml"; request.ContentType = "text/xml";
MemoryStream buffer = new MemoryStream(); MemoryStream buffer = new MemoryStream();
@ -71,12 +74,21 @@ namespace OpenSim.Framework.Servers.HttpServer
Stream requestStream = request.GetRequestStream(); Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer.ToArray(), 0, length); requestStream.Write(buffer.ToArray(), 0, length);
}
TResponse deserial = default(TResponse); TResponse deserial = default(TResponse);
try
{
using (WebResponse resp = request.GetResponse()) using (WebResponse resp = request.GetResponse())
{ {
XmlSerializer deserializer = new XmlSerializer(typeof (TResponse)); XmlSerializer deserializer = new XmlSerializer(typeof (TResponse));
deserial = (TResponse) deserializer.Deserialize(resp.GetResponseStream()); deserial = (TResponse) deserializer.Deserialize(resp.GetResponseStream());
} }
}
catch (System.InvalidOperationException)
{
// This is what happens when there is invalid XML
}
return deserial; return deserial;
} }
} }

View File

@ -27,12 +27,15 @@
using log4net; using log4net;
using System; using System;
using System.IO;
using System.Reflection; using System.Reflection;
using Nini.Config; using Nini.Config;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces; using OpenSim.Services.Interfaces;
using OpenSim.Framework.Communications;
namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
{ {
@ -76,6 +79,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
} }
m_Enabled = true; m_Enabled = true;
m_ServerURI = serviceURI; 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) 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) 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) 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) 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) 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) public bool Delete(string id)
{ {
string uri = m_ServerURI + "/assets/" + id;
return SynchronousRestObjectPoster.
BeginPostObject<int, bool>("DELETE", uri, 0);
return false; return false;
} }
} }

View File

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