aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid
diff options
context:
space:
mode:
authorlbsa712009-02-19 18:53:43 +0000
committerlbsa712009-02-19 18:53:43 +0000
commit00a5fb9484592d8d37b38cebd96d0f399bbe4ebf (patch)
tree13005261c263ecb09857e92fd0c9b8ae05afec8c /OpenSim/Grid
parent* Changed Prebuild.xml back to specifying xmlns (diff)
downloadopensim-SC_OLD-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.zip
opensim-SC_OLD-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.tar.gz
opensim-SC_OLD-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.tar.bz2
opensim-SC_OLD-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.tar.xz
* Split RestService.cs into GetAssetStreamHandler.cs and PostAssetStreamHandler.cs - then killed off original (misnomed) file.
* Really, who wrote this jurassic shit code all with totally wrong file names? Ah yeah, that'd be me. Sorry.
Diffstat (limited to 'OpenSim/Grid')
-rw-r--r--OpenSim/Grid/AssetServer/GetAssetStreamHandler.cs (renamed from OpenSim/Grid/AssetServer/RestService.cs)249
-rw-r--r--OpenSim/Grid/AssetServer/PostAssetStreamHandler.cs44
2 files changed, 138 insertions, 155 deletions
diff --git a/OpenSim/Grid/AssetServer/RestService.cs b/OpenSim/Grid/AssetServer/GetAssetStreamHandler.cs
index a9519ec..56cd52b 100644
--- a/OpenSim/Grid/AssetServer/RestService.cs
+++ b/OpenSim/Grid/AssetServer/GetAssetStreamHandler.cs
@@ -1,155 +1,94 @@
1/* 1using System;
2 * Copyright (c) Contributors, http://opensimulator.org/ 2using System.IO;
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3using System.Reflection;
4 * 4using System.Text;
5 * Redistribution and use in source and binary forms, with or without 5using System.Xml;
6 * modification, are permitted provided that the following conditions are met: 6using System.Xml.Serialization;
7 * * Redistributions of source code must retain the above copyright 7using log4net;
8 * notice, this list of conditions and the following disclaimer. 8using OpenMetaverse;
9 * * Redistributions in binary form must reproduce the above copyright 9using OpenSim.Framework;
10 * notice, this list of conditions and the following disclaimer in the 10using OpenSim.Framework.Servers;
11 * documentation and/or other materials provided with the distribution. 11using OpenSim.Framework.Statistics;
12 * * Neither the name of the OpenSim Project nor the 12
13 * names of its contributors may be used to endorse or promote products 13namespace OpenSim.Grid.AssetServer
14 * derived from this software without specific prior written permission. 14{
15 * 15 public class GetAssetStreamHandler : BaseStreamHandler
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 {
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 // private OpenAsset_Main m_assetManager;
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 private IAssetDataPlugin m_assetProvider;
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 /// <summary>
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 /// Constructor.
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 /// </summary>
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 /// <param name="assetManager"></param>
26 */ 26 /// <param name="assetProvider"></param>
27 27 public GetAssetStreamHandler(IAssetDataPlugin assetProvider)
28using System; 28 : base("GET", "/assets")
29using System.IO; 29 {
30using System.Reflection; 30 m_log.Info("[REST]: In Get Request");
31using System.Text; 31 // m_assetManager = assetManager;
32using System.Xml; 32 m_assetProvider = assetProvider;
33using System.Xml.Serialization; 33 }
34using log4net; 34
35using OpenMetaverse; 35 public override byte[] Handle(string path, Stream request,
36using OpenSim.Framework; 36 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
37using OpenSim.Framework.Servers; 37 {
38using OpenSim.Framework.Statistics; 38 string param = GetParam(path);
39 39 byte[] result = new byte[] {};
40namespace OpenSim.Grid.AssetServer 40
41{ 41 string[] p = param.Split(new char[] {'/', '?', '&'}, StringSplitOptions.RemoveEmptyEntries);
42 public class GetAssetStreamHandler : BaseStreamHandler 42
43 { 43 if (p.Length > 0)
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 {
45 45 UUID assetID = UUID.Zero;
46 // private OpenAsset_Main m_assetManager; 46
47 private IAssetDataPlugin m_assetProvider; 47 if (!UUID.TryParse(p[0], out assetID))
48 48 {
49 /// <summary> 49 m_log.InfoFormat(
50 /// Constructor. 50 "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]);
51 /// </summary> 51 return result;
52 /// <param name="assetManager"></param> 52 }
53 /// <param name="assetProvider"></param> 53
54 public GetAssetStreamHandler(IAssetDataPlugin assetProvider) 54 if (StatsManager.AssetStats != null)
55 : base("GET", "/assets") 55 StatsManager.AssetStats.AddRequest();
56 { 56
57 m_log.Info("[REST]: In Get Request"); 57 AssetBase asset = m_assetProvider.FetchAsset(assetID);
58 // m_assetManager = assetManager; 58 if (asset != null)
59 m_assetProvider = assetProvider; 59 {
60 } 60 XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
61 61 MemoryStream ms = new MemoryStream();
62 public override byte[] Handle(string path, Stream request, 62 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
63 OSHttpRequest httpRequest, OSHttpResponse httpResponse) 63 xw.Formatting = Formatting.Indented;
64 { 64 xs.Serialize(xw, asset);
65 string param = GetParam(path); 65 xw.Flush();
66 byte[] result = new byte[] {}; 66
67 67 ms.Seek(0, SeekOrigin.Begin);
68 string[] p = param.Split(new char[] {'/', '?', '&'}, StringSplitOptions.RemoveEmptyEntries); 68 //StreamReader sr = new StreamReader(ms);
69 69
70 if (p.Length > 0) 70 result = ms.GetBuffer();
71 { 71
72 UUID assetID = UUID.Zero; 72//Ckrinke 1/11/09 Commenting out the succesful REST message as under heavy use there
73 73//are multiple messages in a second and that is usually (in my experience) meaning
74 if (!UUID.TryParse(p[0], out assetID)) 74//the logging itself is slowing down the program. Leaving the unsuccesful message
75 { 75//as we need to know about that path.
76 m_log.InfoFormat( 76// m_log.InfoFormat(
77 "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]); 77// "[REST]: GET:/asset found {0} with name {1}, size {2} bytes",
78 return result; 78// assetID, asset.Name, result.Length);
79 } 79
80 80 Array.Resize<byte>(ref result, (int) ms.Length);
81 if (StatsManager.AssetStats != null) 81 }
82 StatsManager.AssetStats.AddRequest(); 82 else
83 83 {
84 AssetBase asset = m_assetProvider.FetchAsset(assetID); 84 if (StatsManager.AssetStats != null)
85 if (asset != null) 85 StatsManager.AssetStats.AddNotFoundRequest();
86 { 86
87 XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); 87 m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID);
88 MemoryStream ms = new MemoryStream(); 88 }
89 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8); 89 }
90 xw.Formatting = Formatting.Indented; 90
91 xs.Serialize(xw, asset); 91 return result;
92 xw.Flush(); 92 }
93 93 }
94 ms.Seek(0, SeekOrigin.Begin); 94} \ No newline at end of file
95 //StreamReader sr = new StreamReader(ms);
96
97 result = ms.GetBuffer();
98
99//Ckrinke 1/11/09 Commenting out the succesful REST message as under heavy use there
100//are multiple messages in a second and that is usually (in my experience) meaning
101//the logging itself is slowing down the program. Leaving the unsuccesful message
102//as we need to know about that path.
103// m_log.InfoFormat(
104// "[REST]: GET:/asset found {0} with name {1}, size {2} bytes",
105// assetID, asset.Name, result.Length);
106
107 Array.Resize<byte>(ref result, (int) ms.Length);
108 }
109 else
110 {
111 if (StatsManager.AssetStats != null)
112 StatsManager.AssetStats.AddNotFoundRequest();
113
114 m_log.InfoFormat("[REST]: GET:/asset failed to find {0}", assetID);
115 }
116 }
117
118 return result;
119 }
120 }
121
122 public class PostAssetStreamHandler : BaseStreamHandler
123 {
124 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
125
126 // private OpenAsset_Main m_assetManager;
127 private IAssetDataPlugin m_assetProvider;
128
129 public override byte[] Handle(string path, Stream request,
130 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
131 {
132 string param = GetParam(path);
133
134 UUID assetId;
135 if (param.Length > 0)
136 UUID.TryParse(param, out assetId);
137 // byte[] txBuffer = new byte[4096];
138
139 XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
140 AssetBase asset = (AssetBase) xs.Deserialize(request);
141
142 m_log.InfoFormat("[REST]: Creating asset {0}", asset.FullID);
143 m_assetProvider.CreateAsset(asset);
144
145 return new byte[] {};
146 }
147
148 public PostAssetStreamHandler(IAssetDataPlugin assetProvider)
149 : base("POST", "/assets")
150 {
151 // m_assetManager = assetManager;
152 m_assetProvider = assetProvider;
153 }
154 }
155}
diff --git a/OpenSim/Grid/AssetServer/PostAssetStreamHandler.cs b/OpenSim/Grid/AssetServer/PostAssetStreamHandler.cs
new file mode 100644
index 0000000..69551d8
--- /dev/null
+++ b/OpenSim/Grid/AssetServer/PostAssetStreamHandler.cs
@@ -0,0 +1,44 @@
1using System.IO;
2using System.Reflection;
3using System.Xml.Serialization;
4using log4net;
5using OpenMetaverse;
6using OpenSim.Framework;
7using OpenSim.Framework.Servers;
8
9namespace OpenSim.Grid.AssetServer
10{
11 public class PostAssetStreamHandler : BaseStreamHandler
12 {
13 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
14
15 // private OpenAsset_Main m_assetManager;
16 private IAssetDataPlugin m_assetProvider;
17
18 public override byte[] Handle(string path, Stream request,
19 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
20 {
21 string param = GetParam(path);
22
23 UUID assetId;
24 if (param.Length > 0)
25 UUID.TryParse(param, out assetId);
26 // byte[] txBuffer = new byte[4096];
27
28 XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
29 AssetBase asset = (AssetBase) xs.Deserialize(request);
30
31 m_log.InfoFormat("[REST]: Creating asset {0}", asset.FullID);
32 m_assetProvider.CreateAsset(asset);
33
34 return new byte[] {};
35 }
36
37 public PostAssetStreamHandler(IAssetDataPlugin assetProvider)
38 : base("POST", "/assets")
39 {
40 // m_assetManager = assetManager;
41 m_assetProvider = assetProvider;
42 }
43 }
44} \ No newline at end of file