- asset server functionality works with OpenSim's HttpServer
- start of removal of AssetInventoryServer.Metadata class0.6.3-post-fixes
parent
07b8d51da8
commit
f8ea274090
|
@ -77,7 +77,7 @@ namespace OpenSim.Grid.AssetInventoryServer
|
|||
{
|
||||
BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata);
|
||||
BackendResponse TryFetchData(UUID assetID, out byte[] assetData);
|
||||
BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData);
|
||||
BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset);
|
||||
BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData);
|
||||
BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID);
|
||||
int ForEach(Action<Metadata> action, int start, int count);
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
{
|
||||
public class OpenSimAssetFrontendPlugin : IAssetInventoryServerPlugin
|
||||
{
|
||||
private AssetInventoryServer server;
|
||||
private AssetInventoryServer m_server;
|
||||
|
||||
public OpenSimAssetFrontendPlugin()
|
||||
{
|
||||
|
@ -53,13 +53,13 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
|
||||
public void Initialise(AssetInventoryServer server)
|
||||
{
|
||||
this.server = server;
|
||||
m_server = server;
|
||||
|
||||
// Asset request
|
||||
server.HttpServer.AddStreamHandler(new AssetRequestHandler(server));
|
||||
m_server.HttpServer.AddStreamHandler(new AssetRequestHandler(server));
|
||||
|
||||
// Asset creation
|
||||
server.HttpServer.AddStreamHandler(new AssetPostHandler(server));
|
||||
m_server.HttpServer.AddStreamHandler(new AssetPostHandler(server));
|
||||
|
||||
Logger.Log.Info("[ASSET] OpenSim Asset Frontend loaded.");
|
||||
}
|
||||
|
@ -90,63 +90,31 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
|
||||
#endregion IPlugin implementation
|
||||
|
||||
public class AssetRequestHandler : IStreamedRequestHandler
|
||||
public class AssetRequestHandler : BaseStreamHandler
|
||||
{
|
||||
AssetInventoryServer m_server;
|
||||
string m_contentType;
|
||||
string m_httpMethod;
|
||||
string m_path;
|
||||
|
||||
public AssetRequestHandler(AssetInventoryServer server)
|
||||
//public AssetRequestHandler(AssetInventoryServer server) : base("GET", "^/assets")
|
||||
public AssetRequestHandler(AssetInventoryServer server) : base("GET", "/assets")
|
||||
{
|
||||
Logger.Log.Info("[REST]: In Get Request");
|
||||
m_server = server;
|
||||
m_contentType = null;
|
||||
m_httpMethod = "GET";
|
||||
m_path = @"^/assets/";
|
||||
}
|
||||
|
||||
#region IStreamedRequestHandler implementation
|
||||
|
||||
public string ContentType
|
||||
public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||
{
|
||||
get { return m_contentType; }
|
||||
}
|
||||
|
||||
public string HttpMethod
|
||||
{
|
||||
get { return m_httpMethod; }
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get { return m_path; }
|
||||
}
|
||||
|
||||
public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||
{
|
||||
byte[] buffer = null;
|
||||
byte[] buffer = new byte[] {};
|
||||
UUID assetID;
|
||||
// Split the URL up to get the asset ID out
|
||||
string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');
|
||||
|
||||
if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out assetID))
|
||||
{
|
||||
Metadata metadata;
|
||||
byte[] assetData;
|
||||
BackendResponse dataResponse;
|
||||
|
||||
if ((dataResponse = m_server.StorageProvider.TryFetchDataMetadata(assetID, out metadata, out assetData)) == BackendResponse.Success)
|
||||
{
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.Data = assetData;
|
||||
asset.Metadata.FullID = metadata.ID;
|
||||
asset.Metadata.Name = metadata.Name;
|
||||
asset.Metadata.Description = metadata.Description;
|
||||
asset.Metadata.CreationDate = metadata.CreationDate;
|
||||
asset.Metadata.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType);
|
||||
asset.Metadata.Local = false;
|
||||
asset.Metadata.Temporary = metadata.Temporary;
|
||||
|
||||
if ((dataResponse = m_server.StorageProvider.TryFetchDataMetadata(assetID, out asset)) == BackendResponse.Success)
|
||||
{
|
||||
XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
|
||||
MemoryStream ms = new MemoryStream();
|
||||
XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
|
||||
|
@ -155,12 +123,8 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
buffer = ms.GetBuffer();
|
||||
|
||||
Array.Resize<byte>(ref buffer, (int) ms.Length);
|
||||
httpResponse.StatusCode = (int) HttpStatusCode.OK;
|
||||
httpResponse.ContentType = "application/xml";
|
||||
httpResponse.ContentLength = ms.Length;
|
||||
httpResponse.Body.Write(buffer, 0, (int) ms.Length);
|
||||
httpResponse.Body.Flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -175,44 +139,19 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#endregion IStreamedRequestHandler implementation
|
||||
}
|
||||
|
||||
public class AssetPostHandler : IStreamedRequestHandler
|
||||
public class AssetPostHandler : BaseStreamHandler
|
||||
{
|
||||
AssetInventoryServer m_server;
|
||||
string m_contentType;
|
||||
string m_httpMethod;
|
||||
string m_path;
|
||||
|
||||
public AssetPostHandler(AssetInventoryServer server)
|
||||
//public AssetPostHandler(AssetInventoryServer server) : base("POST", "/^assets")
|
||||
public AssetPostHandler(AssetInventoryServer server) : base("POST", "/assets")
|
||||
{
|
||||
m_server = server;
|
||||
m_contentType = null;
|
||||
m_httpMethod = "POST";
|
||||
m_path = @"^/assets/";
|
||||
}
|
||||
|
||||
#region IStreamedRequestHandler implementation
|
||||
|
||||
public string ContentType
|
||||
{
|
||||
get { return m_contentType; }
|
||||
}
|
||||
|
||||
public string HttpMethod
|
||||
{
|
||||
get { return m_httpMethod; }
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get { return m_path; }
|
||||
}
|
||||
|
||||
public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||
//bool AssetPostHandler(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
|
||||
public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
|
||||
{
|
||||
Metadata metadata = new Metadata();
|
||||
|
||||
|
@ -254,8 +193,6 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion IStreamedRequestHandler implementation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,28 +137,11 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
|
|||
return ret;
|
||||
}
|
||||
|
||||
public BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData)
|
||||
public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset)
|
||||
{
|
||||
metadata = null;
|
||||
assetData = null;
|
||||
//BackendResponse ret;
|
||||
asset = m_assetProvider.FetchAsset(assetID);
|
||||
|
||||
AssetBase asset = m_assetProvider.FetchAsset(assetID);
|
||||
|
||||
if (asset != null)
|
||||
{
|
||||
metadata = new Metadata();
|
||||
metadata.ID = asset.Metadata.FullID;
|
||||
metadata.CreationDate = OpenMetaverse.Utils.Epoch;
|
||||
metadata.SHA1 = null;
|
||||
metadata.Name = asset.Metadata.Name;
|
||||
metadata.Description = asset.Metadata.Description;
|
||||
metadata.ContentType = Utils.SLAssetTypeToContentType(asset.Metadata.Type);
|
||||
metadata.Temporary = asset.Metadata.Temporary;
|
||||
|
||||
assetData = asset.Data;
|
||||
}
|
||||
else return BackendResponse.NotFound;
|
||||
if (asset == null) return BackendResponse.NotFound;
|
||||
|
||||
return BackendResponse.Success;
|
||||
}
|
||||
|
|
|
@ -95,10 +95,10 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
|
|||
return ret;
|
||||
}
|
||||
|
||||
public BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData)
|
||||
public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset)
|
||||
{
|
||||
metadata = null;
|
||||
assetData = null;
|
||||
Metadata metadata = null;
|
||||
byte[] assetData = null;
|
||||
string filename;
|
||||
BackendResponse ret;
|
||||
|
||||
|
@ -121,6 +121,16 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.Simple
|
|||
ret = BackendResponse.NotFound;
|
||||
}
|
||||
|
||||
asset = new AssetBase();
|
||||
asset.Data = assetData;
|
||||
asset.Metadata.FullID = metadata.ID;
|
||||
asset.Metadata.Name = metadata.Name;
|
||||
asset.Metadata.Description = metadata.Description;
|
||||
asset.Metadata.CreationDate = metadata.CreationDate;
|
||||
asset.Metadata.Type = (sbyte) Utils.ContentTypeToSLAssetType(metadata.ContentType);
|
||||
asset.Metadata.Local = false;
|
||||
asset.Metadata.Temporary = metadata.Temporary;
|
||||
|
||||
server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
|
||||
server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now);
|
||||
return ret;
|
||||
|
|
|
@ -770,7 +770,7 @@
|
|||
<Reference name="OpenMetaverseTypes"/>
|
||||
<Reference name="OpenMetaverse.StructuredData2"/>
|
||||
<Reference name="ExtensionLoader"/>
|
||||
<Reference name="HttpServer2"/>
|
||||
<Reference name="HttpServer"/>
|
||||
|
||||
<!-- for Simple Storage and MySQL storage -->
|
||||
<Reference name="System.Data"/>
|
||||
|
@ -805,7 +805,7 @@
|
|||
<Reference name="OpenMetaverse"/>
|
||||
<Reference name="OpenMetaverseTypes"/>
|
||||
<Reference name="OpenMetaverse.StructuredData2"/>
|
||||
<Reference name="HttpServer2"/>
|
||||
<Reference name="HttpServer"/>
|
||||
|
||||
<Files>
|
||||
<Match pattern="*.cs" recurse="false" />
|
||||
|
@ -834,7 +834,7 @@
|
|||
<Reference name="OpenMetaverse"/>
|
||||
<Reference name="OpenMetaverseTypes"/>
|
||||
<Reference name="OpenMetaverse.StructuredData2" />
|
||||
<Reference name="HttpServer2"/>
|
||||
<Reference name="HttpServer"/>
|
||||
|
||||
<!-- Remove these eventually -->
|
||||
<Reference name="MySql.Data" />
|
||||
|
@ -866,7 +866,7 @@
|
|||
<Reference name="OpenSim.Grid.AssetInventoryServer" />
|
||||
<Reference name="OpenMetaverseTypes"/>
|
||||
<Reference name="OpenMetaverse.StructuredData2" />
|
||||
<Reference name="HttpServer2"/>
|
||||
<Reference name="HttpServer"/>
|
||||
|
||||
<!-- Remove these eventually -->
|
||||
<Reference name="MySql.Data" />
|
||||
|
|
Loading…
Reference in New Issue