aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/AssetServer/RestService.cs
diff options
context:
space:
mode:
authorlbsa712009-02-19 18:53:43 +0000
committerlbsa712009-02-19 18:53:43 +0000
commit00a5fb9484592d8d37b38cebd96d0f399bbe4ebf (patch)
tree13005261c263ecb09857e92fd0c9b8ae05afec8c /OpenSim/Grid/AssetServer/RestService.cs
parent* Changed Prebuild.xml back to specifying xmlns (diff)
downloadopensim-SC-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.zip
opensim-SC-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.tar.gz
opensim-SC-00a5fb9484592d8d37b38cebd96d0f399bbe4ebf.tar.bz2
opensim-SC-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/AssetServer/RestService.cs')
-rw-r--r--OpenSim/Grid/AssetServer/RestService.cs155
1 files changed, 0 insertions, 155 deletions
diff --git a/OpenSim/Grid/AssetServer/RestService.cs b/OpenSim/Grid/AssetServer/RestService.cs
deleted file mode 100644
index a9519ec..0000000
--- a/OpenSim/Grid/AssetServer/RestService.cs
+++ /dev/null
@@ -1,155 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.IO;
30using System.Reflection;
31using System.Text;
32using System.Xml;
33using System.Xml.Serialization;
34using log4net;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Framework.Servers;
38using OpenSim.Framework.Statistics;
39
40namespace OpenSim.Grid.AssetServer
41{
42 public class GetAssetStreamHandler : BaseStreamHandler
43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 // private OpenAsset_Main m_assetManager;
47 private IAssetDataPlugin m_assetProvider;
48
49 /// <summary>
50 /// Constructor.
51 /// </summary>
52 /// <param name="assetManager"></param>
53 /// <param name="assetProvider"></param>
54 public GetAssetStreamHandler(IAssetDataPlugin assetProvider)
55 : base("GET", "/assets")
56 {
57 m_log.Info("[REST]: In Get Request");
58 // m_assetManager = assetManager;
59 m_assetProvider = assetProvider;
60 }
61
62 public override byte[] Handle(string path, Stream request,
63 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
64 {
65 string param = GetParam(path);
66 byte[] result = new byte[] {};
67
68 string[] p = param.Split(new char[] {'/', '?', '&'}, StringSplitOptions.RemoveEmptyEntries);
69
70 if (p.Length > 0)
71 {
72 UUID assetID = UUID.Zero;
73
74 if (!UUID.TryParse(p[0], out assetID))
75 {
76 m_log.InfoFormat(
77 "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]);
78 return result;
79 }
80
81 if (StatsManager.AssetStats != null)
82 StatsManager.AssetStats.AddRequest();
83
84 AssetBase asset = m_assetProvider.FetchAsset(assetID);
85 if (asset != null)
86 {
87 XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
88 MemoryStream ms = new MemoryStream();
89 XmlTextWriter xw = new XmlTextWriter(ms, Encoding.UTF8);
90 xw.Formatting = Formatting.Indented;
91 xs.Serialize(xw, asset);
92 xw.Flush();
93
94 ms.Seek(0, SeekOrigin.Begin);
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}