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