aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-09 04:03:32 +0000
committerMelanie Thielker2009-05-09 04:03:32 +0000
commitb3d29aaeb3816fdb963a038a2df840a69ccd21e8 (patch)
tree2c1f84543a40fc1be7925b2dcc9e5fc3589a38a1 /OpenSim
parentPlumb the remote asset hookup, all but the actual requests (diff)
downloadopensim-SC_OLD-b3d29aaeb3816fdb963a038a2df840a69ccd21e8.zip
opensim-SC_OLD-b3d29aaeb3816fdb963a038a2df840a69ccd21e8.tar.gz
opensim-SC_OLD-b3d29aaeb3816fdb963a038a2df840a69ccd21e8.tar.bz2
opensim-SC_OLD-b3d29aaeb3816fdb963a038a2df840a69ccd21e8.tar.xz
Make remote assets work through the new server system
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs46
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs58
-rw-r--r--OpenSim/Servers/Asset/AssetServerPostHandler.cs2
3 files changed, 83 insertions, 23 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs
index b754c36..71e5b69 100644
--- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs
+++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs
@@ -52,30 +52,42 @@ namespace OpenSim.Framework.Servers.HttpServer
52 52
53 WebRequest request = WebRequest.Create(requestUrl); 53 WebRequest request = WebRequest.Create(requestUrl);
54 request.Method = verb; 54 request.Method = verb;
55 request.ContentType = "text/xml";
56 55
57 MemoryStream buffer = new MemoryStream(); 56 if (verb == "POST")
57 {
58 request.ContentType = "text/xml";
58 59
59 XmlWriterSettings settings = new XmlWriterSettings(); 60 MemoryStream buffer = new MemoryStream();
60 settings.Encoding = Encoding.UTF8;
61 61
62 using (XmlWriter writer = XmlWriter.Create(buffer, settings)) 62 XmlWriterSettings settings = new XmlWriterSettings();
63 { 63 settings.Encoding = Encoding.UTF8;
64 XmlSerializer serializer = new XmlSerializer(type); 64
65 serializer.Serialize(writer, obj); 65 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
66 writer.Flush(); 66 {
67 } 67 XmlSerializer serializer = new XmlSerializer(type);
68 serializer.Serialize(writer, obj);
69 writer.Flush();
70 }
68 71
69 int length = (int) buffer.Length; 72 int length = (int) buffer.Length;
70 request.ContentLength = length; 73 request.ContentLength = length;
74
75 Stream requestStream = request.GetRequestStream();
76 requestStream.Write(buffer.ToArray(), 0, length);
77 }
71 78
72 Stream requestStream = request.GetRequestStream();
73 requestStream.Write(buffer.ToArray(), 0, length);
74 TResponse deserial = default(TResponse); 79 TResponse deserial = default(TResponse);
75 using (WebResponse resp = request.GetResponse()) 80 try
81 {
82 using (WebResponse resp = request.GetResponse())
83 {
84 XmlSerializer deserializer = new XmlSerializer(typeof (TResponse));
85 deserial = (TResponse) deserializer.Deserialize(resp.GetResponseStream());
86 }
87 }
88 catch (System.InvalidOperationException)
76 { 89 {
77 XmlSerializer deserializer = new XmlSerializer(typeof (TResponse)); 90 // This is what happens when there is invalid XML
78 deserial = (TResponse) deserializer.Deserialize(resp.GetResponseStream());
79 } 91 }
80 return deserial; 92 return deserial;
81 } 93 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
index 715cf6e..2cc2962 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
@@ -27,12 +27,15 @@
27 27
28using log4net; 28using log4net;
29using System; 29using System;
30using System.IO;
30using System.Reflection; 31using System.Reflection;
31using Nini.Config; 32using Nini.Config;
32using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Region.Framework.Interfaces; 35using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes; 36using OpenSim.Region.Framework.Scenes;
35using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
38using OpenSim.Framework.Communications;
36 39
37namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset 40namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
38{ 41{
@@ -76,6 +79,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
76 } 79 }
77 m_Enabled = true; 80 m_Enabled = true;
78 m_ServerURI = serviceURI; 81 m_ServerURI = serviceURI;
82
83 m_log.Info("[ASSET CONNECTOR]: Remote assets enabled");
79 } 84 }
80 } 85 }
81 } 86 }
@@ -106,31 +111,74 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
106 111
107 public AssetBase Get(string id) 112 public AssetBase Get(string id)
108 { 113 {
109 return null; 114 string uri = m_ServerURI + "/assets/" + id;
115
116 AssetBase asset = SynchronousRestObjectPoster.
117 BeginPostObject<int, AssetBase>("GET", uri, 0);
118 return asset;
110 } 119 }
111 120
112 public AssetMetadata GetMetadata(string id) 121 public AssetMetadata GetMetadata(string id)
113 { 122 {
114 return null; 123 string uri = m_ServerURI + "/assets/" + id + "/metadata";
124
125 AssetMetadata asset = SynchronousRestObjectPoster.
126 BeginPostObject<int, AssetMetadata>("GET", uri, 0);
127 return asset;
115 } 128 }
116 129
117 public byte[] GetData(string id) 130 public byte[] GetData(string id)
118 { 131 {
119 return new byte[0]; 132 RestClient rc = new RestClient(m_ServerURI);
133 rc.AddResourcePath("assets");
134 rc.AddResourcePath(id);
135 rc.AddResourcePath("data");
136
137 rc.RequestMethod = "GET";
138
139 Stream s = rc.Request();
140
141 if (s == null)
142 return null;
143
144 if (s.Length > 0)
145 {
146 byte[] ret = new byte[s.Length];
147 s.Read(ret, 0, (int)s.Length);
148
149 return ret;
150 }
151
152 return null;
120 } 153 }
121 154
122 public string Store(AssetBase asset) 155 public string Store(AssetBase asset)
123 { 156 {
124 return String.Empty; 157 string uri = m_ServerURI + "/assets/";
158
159 string newID = SynchronousRestObjectPoster.
160 BeginPostObject<AssetBase, string>("POST", uri, asset);
161 return newID;
125 } 162 }
126 163
127 public bool UpdateContent(string id, byte[] data) 164 public bool UpdateContent(string id, byte[] data)
128 { 165 {
129 return false; 166 AssetBase asset = new AssetBase();
167 asset.ID = id;
168 asset.Data = data;
169
170 string uri = m_ServerURI + "/assets/" + id;
171
172 return SynchronousRestObjectPoster.
173 BeginPostObject<AssetBase, bool>("POST", uri, asset);
130 } 174 }
131 175
132 public bool Delete(string id) 176 public bool Delete(string id)
133 { 177 {
178 string uri = m_ServerURI + "/assets/" + id;
179
180 return SynchronousRestObjectPoster.
181 BeginPostObject<int, bool>("DELETE", uri, 0);
134 return false; 182 return false;
135 } 183 }
136 } 184 }
diff --git a/OpenSim/Servers/Asset/AssetServerPostHandler.cs b/OpenSim/Servers/Asset/AssetServerPostHandler.cs
index 70cb16a..3bc7267 100644
--- a/OpenSim/Servers/Asset/AssetServerPostHandler.cs
+++ b/OpenSim/Servers/Asset/AssetServerPostHandler.cs
@@ -66,7 +66,7 @@ namespace OpenSim.Servers.AssetServer
66 if (p.Length > 1) 66 if (p.Length > 1)
67 { 67 {
68 bool result = 68 bool result =
69 m_AssetService.UpdateContent(asset.ID, asset.Data); 69 m_AssetService.UpdateContent(p[1], asset.Data);
70 70
71 xs = new XmlSerializer(typeof(bool)); 71 xs = new XmlSerializer(typeof(bool));
72 return ServerUtils.SerializeResult(xs, result); 72 return ServerUtils.SerializeResult(xs, result);