diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index 0f0c79020a..ebb2691dfd 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -56,14 +56,14 @@ namespace OpenSim.Framework.Servers.HttpServer request.ContentType = "text/www-form-urlencoded"; MemoryStream buffer = new MemoryStream(); - + int length = 0; using (StreamWriter writer = new StreamWriter(buffer)) { writer.WriteLine(obj); writer.Flush(); + length = (int)buffer.Length; } - int length = (int) buffer.Length; request.ContentLength = length; Stream requestStream = request.GetRequestStream(); diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs index 6c2b3ed031..656fcf5432 100644 --- a/OpenSim/Server/Base/ServerUtils.cs +++ b/OpenSim/Server/Base/ServerUtils.cs @@ -258,6 +258,8 @@ namespace OpenSim.Server.Base public static Dictionary ParseXmlResponse(string data) { + //m_log.DebugFormat("[XXX]: received xml string: {0}", data); + Dictionary ret = new Dictionary(); XmlDocument doc = new XmlDocument(); @@ -284,7 +286,7 @@ namespace OpenSim.Server.Base foreach (XmlNode part in partL) { - XmlNode type = part.Attributes.GetNamedItem("Type"); + XmlNode type = part.Attributes.GetNamedItem("type"); if (type == null || type.Value != "List") { ret[part.Name] = part.InnerText; diff --git a/OpenSim/Server/Handlers/Grid/GridServerConnector.cs b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs index 7bf2e664d7..ebdf489ed5 100644 --- a/OpenSim/Server/Handlers/Grid/GridServerConnector.cs +++ b/OpenSim/Server/Handlers/Grid/GridServerConnector.cs @@ -45,7 +45,7 @@ namespace OpenSim.Server.Handlers.Grid if (serverConfig == null) throw new Exception("No section 'Server' in config file"); - string gridService = serverConfig.GetString("GridServiceModule", + string gridService = serverConfig.GetString("LocalServiceModule", String.Empty); if (gridService == String.Empty) diff --git a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs index e72c2eb491..eaeed6f584 100644 --- a/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Grid/GridServerPostHandler.cs @@ -63,6 +63,7 @@ namespace OpenSim.Server.Handlers.Grid StreamReader sr = new StreamReader(requestData); string body = sr.ReadToEnd(); sr.Close(); + body = body.Trim(); Dictionary request = ServerUtils.ParseQueryString(body); @@ -98,11 +99,11 @@ namespace OpenSim.Server.Handlers.Grid case "get_region_range": return GetRegionRange(request); - default: - m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method); - return FailureResult(); } + m_log.DebugFormat("[GRID HANDLER XXX]: unknown method {0} request {1}", method.Length, method); + return FailureResult(); + } #region Method-specific handlers @@ -155,11 +156,12 @@ namespace OpenSim.Server.Handlers.Grid UUID regionID = UUID.Zero; if (request["REGIONID"] != null) - UUID.TryParse(request["REGIONID"], out scopeID); + UUID.TryParse(request["REGIONID"], out regionID); else m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours"); List rinfos = m_GridService.GetNeighbours(scopeID, regionID); + //m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); Dictionary result = new Dictionary(); int i = 0; @@ -171,6 +173,7 @@ namespace OpenSim.Server.Handlers.Grid } string xmlString = ServerUtils.BuildXmlResponse(result); + //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); UTF8Encoding encoding = new UTF8Encoding(); return encoding.GetBytes(xmlString); diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs index 0a867db630..fa197c89c7 100644 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs @@ -97,9 +97,11 @@ namespace OpenSim.Services.Connectors sendData["METHOD"] = "register"; + string reqString = ServerUtils.BuildQueryString(sendData); + m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString); string reply = SynchronousRestFormsRequester.MakeRequest("POST", m_ServerURI + "/grid", - ServerUtils.BuildQueryString(sendData)); + reqString); Dictionary replyData = ServerUtils.ParseXmlResponse(reply); @@ -138,9 +140,10 @@ namespace OpenSim.Services.Connectors sendData["METHOD"] = "get_neighbours"; + string reqString = ServerUtils.BuildQueryString(sendData); string reply = SynchronousRestFormsRequester.MakeRequest("POST", m_ServerURI + "/grid", - ServerUtils.BuildQueryString(sendData)); + reqString); Dictionary replyData = ServerUtils.ParseXmlResponse(reply); @@ -148,6 +151,7 @@ namespace OpenSim.Services.Connectors if (replyData != null) { Dictionary.ValueCollection rinfosList = replyData.Values; + m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); foreach (object r in rinfosList) { if (r is Dictionary) @@ -156,8 +160,8 @@ namespace OpenSim.Services.Connectors rinfos.Add(rinfo); } else - m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received invalid response", - scopeID, regionID); + m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received invalid response type {2}", + scopeID, regionID, r.GetType()); } } else diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs index a188f7e0d0..d12276f789 100644 --- a/OpenSim/Services/Interfaces/IGridService.cs +++ b/OpenSim/Services/Interfaces/IGridService.cs @@ -277,6 +277,15 @@ namespace OpenSim.Services.Interfaces public GridRegion(Dictionary kvp) { + if (kvp["uuid"] != null) + RegionID = new UUID((string)kvp["uuid"]); + + if (kvp["locX"] != null) + RegionLocX = Convert.ToInt32((string)kvp["locX"]); + + if (kvp["locY"] != null) + RegionLocY = Convert.ToInt32((string)kvp["locY"]); + if ((kvp["external_ip_address"] != null) && (kvp["external_port"] != null)) { int port = 0; diff --git a/OpenSim/Tests/Clients/Grid/GridClient.cs b/OpenSim/Tests/Clients/Grid/GridClient.cs new file mode 100644 index 0000000000..0b84f9ba8e --- /dev/null +++ b/OpenSim/Tests/Clients/Grid/GridClient.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Reflection; + +using OpenMetaverse; +using log4net; +using log4net.Appender; +using log4net.Layout; + +using OpenSim.Framework; +using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; +using OpenSim.Services.Connectors; + +namespace OpenSim.Tests.Clients.GridClient +{ + public class GridClient + { + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); + + public static void Main(string[] args) + { + ConsoleAppender consoleAppender = new ConsoleAppender(); + consoleAppender.Layout = + new PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"); + log4net.Config.BasicConfigurator.Configure(consoleAppender); + + string serverURI = "http://127.0.0.1:8002"; + GridServicesConnector m_Connector = new GridServicesConnector(serverURI); + + GridRegion r1 = CreateRegion("Test Region 1", 1000, 1000); + GridRegion r2 = CreateRegion("Test Region 2", 1001, 1000); + GridRegion r3 = CreateRegion("Test Region 3", 1005, 1000); + + Console.WriteLine("[GRID CLIENT]: Registering region 1"); + bool success = m_Connector.RegisterRegion(UUID.Zero, r1); + if (success) + Console.WriteLine("[GRID CLIENT]: Successfully registered region 1"); + else + Console.WriteLine("[GRID CLIENT]: region 1 failed to register"); + + Console.WriteLine("[GRID CLIENT]: Registering region 2"); + success = m_Connector.RegisterRegion(UUID.Zero, r2); + if (success) + Console.WriteLine("[GRID CLIENT]: Successfully registered region 2"); + else + Console.WriteLine("[GRID CLIENT]: region 2 failed to register"); + + Console.WriteLine("[GRID CLIENT]: Registering region 3"); + success = m_Connector.RegisterRegion(UUID.Zero, r3); + if (success) + Console.WriteLine("[GRID CLIENT]: Successfully registered region 3"); + else + Console.WriteLine("[GRID CLIENT]: region 3 failed to register"); + + + Console.WriteLine("[GRID CLIENT]: Deregistering region 3"); + success = m_Connector.DeregisterRegion(r3.RegionID); + if (success) + Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 3"); + else + Console.WriteLine("[GRID CLIENT]: region 3 failed to deregister"); + Console.WriteLine("[GRID CLIENT]: Registering region 3 again"); + success = m_Connector.RegisterRegion(UUID.Zero, r3); + if (success) + Console.WriteLine("[GRID CLIENT]: Successfully registered region 3"); + else + Console.WriteLine("[GRID CLIENT]: region 3 failed to register"); + + Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1"); + List regions = m_Connector.GetNeighbours(UUID.Zero, r1.RegionID); + if (regions == null) + Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 failed"); + else if (regions.Count > 0) + { + if (regions.Count != 1) + Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned more neighbours than expected: " + regions.Count); + else + Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned the right neighbour " + regions[0].RegionName); + } + else + Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned 0 neighbours"); + + + } + + private static GridRegion CreateRegion(string name, uint xcell, uint ycell) + { + GridRegion region = new GridRegion(xcell, ycell); + region.RegionName = name; + region.RegionID = UUID.Random(); + region.ExternalHostName = "127.0.0.1"; + region.HttpPort = 9000; + region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0); + + return region; + } + } +} diff --git a/prebuild.xml b/prebuild.xml index cb2031906a..6ac7b68f9f 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -3221,6 +3221,35 @@ + + + + + ../../../../bin/ + + + + + ../../../../bin/ + + + + ../../../../bin/ + + + + + + + + + + + + + + +