aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
diff options
context:
space:
mode:
authorDr Scofield2008-05-19 11:52:51 +0000
committerDr Scofield2008-05-19 11:52:51 +0000
commit4e93228e25a941dde4b01c4ec934cd1907096a6f (patch)
tree8c7a7d1f36bbc55c834bc52b5fe1d0582f648c87 /OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
parentadding OSHttpRequest and OSHttpResponse which wrap HttpListenerRequest and Ht... (diff)
downloadopensim-SC-4e93228e25a941dde4b01c4ec934cd1907096a6f.zip
opensim-SC-4e93228e25a941dde4b01c4ec934cd1907096a6f.tar.gz
opensim-SC-4e93228e25a941dde4b01c4ec934cd1907096a6f.tar.bz2
opensim-SC-4e93228e25a941dde4b01c4ec934cd1907096a6f.tar.xz
fixing exception when RestPlugin not configured. refactors RestRegionPlugin, adds error checking.
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs')
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs76
1 files changed, 11 insertions, 65 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
index 0716cf6..9b888fa 100644
--- a/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
+++ b/OpenSim/ApplicationPlugins/Rest/Regions/RestRegionPlugin.cs
@@ -23,7 +23,7 @@
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
@@ -55,14 +55,11 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
55{ 55{
56 56
57 [Extension("/OpenSim/Startup")] 57 [Extension("/OpenSim/Startup")]
58 public class RestRegionPlugin : RestPlugin 58 public partial class RestRegionPlugin : RestPlugin
59 { 59 {
60 private static readonly log4net.ILog _log =
61 log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
62
63 #region overriding properties 60 #region overriding properties
64 public override string Name 61 public override string Name
65 { 62 {
66 get { return "REGION"; } 63 get { return "REGION"; }
67 } 64 }
68 65
@@ -86,18 +83,20 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
86 try 83 try
87 { 84 {
88 base.Initialise(openSim); 85 base.Initialise(openSim);
89 if (IsEnabled) 86 if (!IsEnabled)
90 m_log.InfoFormat("{0} Rest Plugins Enabled", MsgID); 87 {
91 else
92 m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID); 88 m_log.WarnFormat("{0} Rest Plugins are disabled", MsgID);
89 return;
90 }
91 m_log.InfoFormat("{0} REST region plugin enabled", MsgID);
93 92
94 // add REST method handlers 93 // add REST method handlers
95 AddRestStreamHandler("GET", "/regions/", GetHandler); 94 AddRestStreamHandler("GET", "/regions/", GetHandler);
96 } 95 }
97 catch (Exception e) 96 catch (Exception e)
98 { 97 {
99 _log.WarnFormat("{0} Initialization failed: {1}", MsgID, e.Message); 98 m_log.WarnFormat("{0} Initialization failed: {1}", MsgID, e.Message);
100 _log.DebugFormat("{0} Initialization failed: {1}", MsgID, e.ToString()); 99 m_log.DebugFormat("{0} Initialization failed: {1}", MsgID, e.ToString());
101 } 100 }
102 } 101 }
103 102
@@ -105,58 +104,5 @@ namespace OpenSim.ApplicationPlugins.Rest.Regions
105 { 104 {
106 } 105 }
107 #endregion overriding methods 106 #endregion overriding methods
108
109 #region methods
110 public string GetHandler(string request, string path, string param)
111 {
112 m_log.DebugFormat("{0} GET path {1} param {2}", MsgID, path, param);
113
114 // param empty: regions list
115 if (String.IsNullOrEmpty(param)) return GetHandlerRegions();
116
117 return GetHandlerRegion(param);
118 }
119
120 public string GetHandlerRegions()
121 {
122 StringWriter sw = new StringWriter();
123 XmlTextWriter xw = new XmlTextWriter(sw);
124 xw.Formatting = Formatting.Indented;
125
126 xw.WriteStartElement(String.Empty, "regions", String.Empty);
127 foreach (Scene s in App.SceneManager.Scenes)
128 {
129 xw.WriteStartElement(String.Empty, "uuid", String.Empty);
130 xw.WriteString(s.RegionInfo.RegionID.ToString());
131 xw.WriteEndElement();
132 }
133 xw.WriteEndElement();
134 xw.Close();
135
136 return sw.ToString();
137 }
138
139 public string GetHandlerRegion(string param)
140 {
141 string[] comps = param.Split('/');
142 LLUUID regionID = (LLUUID)comps[0];
143 _log.DebugFormat("{0} region UUID {1}", MsgID, regionID.ToString());
144
145 if (LLUUID.Zero == regionID) throw new Exception("missing region ID");
146
147 Scene scene = null;
148 App.SceneManager.TryGetScene(regionID, out scene);
149
150 XmlSerializer xs = new XmlSerializer(typeof(RegionDetails));
151 StringWriter sw = new StringWriter();
152 XmlTextWriter xw = new XmlTextWriter(sw);
153 xw.Formatting = Formatting.Indented;
154
155 xs.Serialize(xw, new RegionDetails(scene.RegionInfo));
156 xw.Close();
157
158 return sw.ToString();
159 }
160 #endregion methods
161 } 107 }
162} 108}