From df5e4a1e5b8ef0f02b6b796a1f3fd72671a81a79 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Wed, 29 Dec 2010 20:47:51 -0800 Subject: Standardize the way WebRequests are made in the SimulationServiceConnector. Added debugging calls for tracking performance of web requests. --- OpenSim/Framework/WebUtil.cs | 168 ++++++- .../Hypergrid/GatekeeperServiceConnector.cs | 64 +-- .../Simulation/SimulationServiceConnector.cs | 553 +++++---------------- 3 files changed, 313 insertions(+), 472 deletions(-) diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 1c856af..1cd9054 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -50,6 +50,8 @@ namespace OpenSim.Framework LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType); + private static int m_requestNumber = 0; + /// /// Send LLSD to an HTTP client in application/llsd+json form /// @@ -123,12 +125,145 @@ namespace OpenSim.Framework } /// + /// PUT JSON-encoded data to a web service that returns LLSD or + /// JSON data + /// + public static OSDMap PutToService(string url, OSDMap data) + { + return ServiceOSDRequest(url,data,"PUT",10000); + } + + public static OSDMap PostToService(string url, OSDMap data) + { + return ServiceOSDRequest(url,data,"POST",10000); + } + + public static OSDMap GetFromService(string url) + { + return ServiceOSDRequest(url,null,"GET",10000); + } + + public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout) + { + int reqnum = m_requestNumber++; + m_log.WarnFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method); + + string errorMessage = "unknown error"; + int tickstart = Util.EnvironmentTickCount(); + try + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + request.Method = method; + request.Timeout = timeout; + //request.KeepAlive = false; + + // If there is some input, write it into the request + if (data != null) + { + string strBuffer = OSDParser.SerializeJsonString(data); + byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); + + request.ContentType = "application/json"; + request.ContentLength = buffer.Length; //Count bytes to send + using (Stream requestStream = request.GetRequestStream()) + { + requestStream.Write(buffer, 0, strBuffer.Length); //Send it + } + } + + using (WebResponse webResponse = request.GetResponse()) + { + using (Stream responseStream = webResponse.GetResponseStream()) + { + string responseStr = null; + responseStr = responseStream.GetStreamString(); + m_log.WarnFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr); + return CanonicalizeResults(responseStr); + } + } + } + catch (WebException we) + { + errorMessage = we.Message; + if (we.Status == WebExceptionStatus.ProtocolError) + { + HttpWebResponse webResponse = (HttpWebResponse)we.Response; + errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription); + } + } + catch (Exception ex) + { + errorMessage = ex.Message; + } + finally + { + int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); + if (tickdiff > 100) + m_log.WarnFormat("[WEB UTIL]: request <{0}> took {1} milliseconds",reqnum,tickdiff); + } + + m_log.WarnFormat("[WEB UTIL] <{0}> request failed: {1}",reqnum,errorMessage); + return ErrorResponseMap(errorMessage); + } + + /// + /// Since there are no consistencies in the way web requests are + /// formed, we need to do a little guessing about the result format. + /// Keys: + /// Success|success == the success fail of the request + /// _RawResult == the raw string that came back + /// _Result == the OSD unpacked string + /// + private static OSDMap CanonicalizeResults(string response) + { + OSDMap result = new OSDMap(); + + // Default values + result["Success"] = OSD.FromBoolean(true); + result["success"] = OSD.FromBoolean(true); + result["_RawResult"] = OSD.FromString(response); + result["_Result"] = new OSDMap(); + + if (response.Equals("true",System.StringComparison.OrdinalIgnoreCase)) + return result; + + if (response.Equals("false",System.StringComparison.OrdinalIgnoreCase)) + { + result["Success"] = OSD.FromBoolean(false); + result["success"] = OSD.FromBoolean(false); + return result; + } + + try + { + OSD responseOSD = OSDParser.Deserialize(response); + if (responseOSD.Type == OSDType.Map) + { + result["_Result"] = (OSDMap)responseOSD; + return result; + } + } + catch (Exception e) + { + // don't need to treat this as an error... we're just guessing anyway + m_log.DebugFormat("[WEB UTIL] couldn't decode result: <{0}>",response); + } + + return result; + } + + /// /// POST URL-encoded form data to a web service that returns LLSD or /// JSON data /// public static OSDMap PostToService(string url, NameValueCollection data) { + int reqnum = m_requestNumber++; + string method = data["RequestMethod"] != null ? data["RequestMethod"] : "unknown"; + m_log.WarnFormat("[WEB UTIL]: <{0}> start form request for {1}, method {2}",reqnum,url,method); + string errorMessage; + int tickstart = Util.EnvironmentTickCount(); try { @@ -139,7 +274,7 @@ namespace OpenSim.Framework request.Method = "POST"; request.ContentLength = requestData.Length; request.ContentType = "application/x-www-form-urlencoded"; - + Stream requestStream = request.GetRequestStream(); requestStream.Write(requestData, 0, requestData.Length); requestStream.Close(); @@ -169,15 +304,42 @@ namespace OpenSim.Framework } } } + catch (WebException we) + { + errorMessage = we.Message; + if (we.Status == WebExceptionStatus.ProtocolError) + { + HttpWebResponse webResponse = (HttpWebResponse)we.Response; + errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription); + } + } catch (Exception ex) { - m_log.Warn("POST to URL " + url + " failed: " + ex); errorMessage = ex.Message; } + finally + { + int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); + if (tickdiff > 100) + m_log.WarnFormat("[WEB UTIL]: request <{0}> took {1} milliseconds",reqnum,tickdiff); + } - return new OSDMap { { "Message", OSD.FromString("Service request failed. " + errorMessage) } }; + m_log.WarnFormat("[WEB UTIL]: <{0}> request failed: {1}",reqnum,errorMessage); + return ErrorResponseMap(errorMessage); } + /// + /// Create a response map for an error, trying to keep + /// the result formats consistent + /// + private static OSDMap ErrorResponseMap(string msg) + { + OSDMap result = new OSDMap(); + result["Success"] = "False"; + result["Message"] = OSD.FromString("Service request failed: " + msg); + return result; + } + #region Uri /// diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs index a1d9167..6c69fec 100644 --- a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs @@ -283,46 +283,52 @@ namespace OpenSim.Services.Connectors.Hypergrid public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason) { - HttpWebRequest AgentCreateRequest = null; + m_log.WarnFormat("[GATEKEEPER SERVICE CONNECTOR]: CreateAgent start"); + myipaddress = String.Empty; reason = String.Empty; - if (SendRequest(destination, aCircuit, flags, out reason, out AgentCreateRequest)) + if (destination == null) { - string response = GetResponse(AgentCreateRequest, out reason); - bool success = true; - UnpackResponse(response, out success, out reason, out myipaddress); - return success; + m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Given destination is null"); + return false; } - return false; - } - - protected void UnpackResponse(string response, out bool result, out string reason, out string ipaddress) - { - result = true; - reason = string.Empty; - ipaddress = string.Empty; + string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/"; - if (!String.IsNullOrEmpty(response)) + try { - try - { - // we assume we got an OSDMap back - OSDMap r = Util.GetOSDMap(response); - result = r["success"].AsBoolean(); - reason = r["reason"].AsString(); - ipaddress = r["your_ip"].AsString(); - } - catch (NullReferenceException e) + OSDMap args = aCircuit.PackAgentCircuitData(); + + args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); + args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); + args["destination_name"] = OSD.FromString(destination.RegionName); + args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); + args["teleport_flags"] = OSD.FromString(flags.ToString()); + + OSDMap result = WebUtil.PostToService(uri,args); + if (result["Success"].AsBoolean()) { - m_log.InfoFormat("[GATEKEEPER SERVICE CONNECTOR]: exception on UnpackResponse of DoCreateChildAgentCall {0}", e.Message); - reason = "Internal error"; - result = false; + OSDMap unpacked = (OSDMap)result["_Result"]; + + if (unpacked != null) + { + reason = unpacked["reason"].AsString(); + myipaddress = unpacked["your_ip"].AsString(); + return unpacked["success"].AsBoolean(); + } } + + reason = result["Message"] != null ? result["Message"].AsString() : "error"; + return false; + } + catch (Exception e) + { + m_log.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString()); + reason = e.Message; } - } - + return false; + } } } diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs index 4e3cfa5..4facc4a 100644 --- a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs +++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs @@ -75,469 +75,193 @@ namespace OpenSim.Services.Connectors.Simulation return "agent/"; } + /// + /// + /// public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason) { - HttpWebRequest AgentCreateRequest = null; - reason = String.Empty; - - if (SendRequest(destination, aCircuit, flags, out reason, out AgentCreateRequest)) - { - string response = GetResponse(AgentCreateRequest, out reason); - bool success = true; - UnpackResponse(response, out success, out reason); - return success; - } - - return false; - } - - - protected bool SendRequest(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason, out HttpWebRequest AgentCreateRequest) - { + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent start"); + reason = String.Empty; - AgentCreateRequest = null; - if (destination == null) { - reason = "Destination is null"; m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null"); return false; } string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/"; - - AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); - AgentCreateRequest.Method = "POST"; - AgentCreateRequest.ContentType = "application/json"; - AgentCreateRequest.Timeout = 10000; - //AgentCreateRequest.KeepAlive = false; - //AgentCreateRequest.Headers.Add("Authorization", authKey); - - // Fill it in - OSDMap args = PackCreateAgentArguments(aCircuit, destination, flags); - if (args == null) - return false; - - string strBuffer = ""; - byte[] buffer = new byte[1]; + try { - strBuffer = OSDParser.SerializeJsonString(args); - Encoding str = Util.UTF8; - buffer = str.GetBytes(strBuffer); + OSDMap args = aCircuit.PackAgentCircuitData(); - } - catch (Exception e) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message); - // ignore. buffer will be empty, caller should check. - } + args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); + args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); + args["destination_name"] = OSD.FromString(destination.RegionName); + args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); + args["teleport_flags"] = OSD.FromString(flags.ToString()); - Stream os = null; - try - { // send the Post - AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send - os = AgentCreateRequest.GetRequestStream(); - os.Write(buffer, 0, strBuffer.Length); //Send it - m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}", - uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY); - } - //catch (WebException ex) - catch - { - //m_log.ErrorFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message); - reason = "cannot contact remote region"; + OSDMap result = WebUtil.PostToService(uri,args); + if (result["Success"].AsBoolean()) + return true; + + reason = result["Message"] != null ? result["Message"].AsString() : "error"; return false; } - finally - { - if (os != null) - os.Close(); - } - - return true; - } - - protected string GetResponse(HttpWebRequest AgentCreateRequest, out string reason) - { - // Let's wait for the response - //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); - reason = string.Empty; - - WebResponse webResponse = null; - StreamReader sr = null; - string response = string.Empty; - try - { - webResponse = AgentCreateRequest.GetResponse(); - if (webResponse == null) - { - m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on DoCreateChildAgentCall post"); - } - else - { - - sr = new StreamReader(webResponse.GetResponseStream()); - response = sr.ReadToEnd().Trim(); - m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); - } - } - catch (WebException ex) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); - reason = "Destination did not reply"; - return string.Empty; - } - finally - { - if (sr != null) - sr.Close(); - } - - return response; - } - - protected void UnpackResponse(string response, out bool result, out string reason) - { - result = true; - reason = string.Empty; - if (!String.IsNullOrEmpty(response)) - { - try - { - // we assume we got an OSDMap back - OSDMap r = Util.GetOSDMap(response); - result = r["success"].AsBoolean(); - reason = r["reason"].AsString(); - } - catch (NullReferenceException e) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); - - // check for old style response - if (response.ToLower().StartsWith("true")) - result = true; - - result = false; - } - } - } - - protected virtual OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion destination, uint flags) - { - OSDMap args = null; - try - { - args = aCircuit.PackAgentCircuitData(); - } catch (Exception e) { - m_log.Warn("[REMOTE SIMULATION CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); - return null; + m_log.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString()); + reason = e.Message; } - - // Add the input arguments - args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); - args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); - args["destination_name"] = OSD.FromString(destination.RegionName); - args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); - args["teleport_flags"] = OSD.FromString(flags.ToString()); - - return args; + + return false; } + /// + /// Send complete data about an agent in this region to a neighbor + /// public bool UpdateAgent(GridRegion destination, AgentData data) { return UpdateAgent(destination, (IAgentData)data); } + /// + /// Send updated position information about an agent in this region to a neighbor + /// This operation may be called very frequently if an avatar is moving about in + /// the region. + /// public bool UpdateAgent(GridRegion destination, AgentPosition data) { + // we need a better throttle for these + return false; + return UpdateAgent(destination, (IAgentData)data); } + /// + /// This is the worker function to send AgentData to a neighbor region + /// private bool UpdateAgent(GridRegion destination, IAgentData cAgentData) { - // Eventually, we want to use a caps url instead of the agentID + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: UpdateAgent start"); + // Eventually, we want to use a caps url instead of the agentID string uri = destination.ServerURI + AgentPath() + cAgentData.AgentID + "/"; - HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri); - ChildUpdateRequest.Method = "PUT"; - ChildUpdateRequest.ContentType = "application/json"; - ChildUpdateRequest.Timeout = 30000; - //ChildUpdateRequest.KeepAlive = false; - - // Fill it in - OSDMap args = null; try { - args = cAgentData.Pack(); - } - catch (Exception e) - { - m_log.Warn("[REMOTE SIMULATION CONNECTOR]: PackUpdateMessage failed with exception: " + e.Message); - } - // Add the input arguments - args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); - args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); - args["destination_name"] = OSD.FromString(destination.RegionName); - args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); - - string strBuffer = ""; - byte[] buffer = new byte[1]; - try - { - strBuffer = OSDParser.SerializeJsonString(args); - Encoding str = Util.UTF8; - buffer = str.GetBytes(strBuffer); - - } - catch (Exception e) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildUpdate: {0}", e.Message); - // ignore. buffer will be empty, caller should check. - } + OSDMap args = cAgentData.Pack(); - Stream os = null; - try - { // send the Post - ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send - os = ChildUpdateRequest.GetRequestStream(); - os.Write(buffer, 0, strBuffer.Length); //Send it - //m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted AgentUpdate request to remote sim {0}", uri); - } - catch (WebException ex) - //catch - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on AgentUpdate {0}", ex.Message); + args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); + args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); + args["destination_name"] = OSD.FromString(destination.RegionName); + args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); - return false; + OSDMap result = WebUtil.PutToService(uri,args); + return result["Success"].AsBoolean(); } - finally - { - if (os != null) - os.Close(); - } - - // Let's wait for the response - //m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after ChildAgentUpdate"); - - WebResponse webResponse = null; - StreamReader sr = null; - try - { - webResponse = ChildUpdateRequest.GetResponse(); - if (webResponse == null) - { - m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on ChilAgentUpdate post"); - } - - sr = new StreamReader(webResponse.GetResponseStream()); - //reply = sr.ReadToEnd().Trim(); - sr.ReadToEnd().Trim(); - sr.Close(); - //m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); - - } - catch (WebException ex) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ChilAgentUpdate from {0}: {1}", uri, ex.Message); - // ignore, really - } - finally + catch (Exception e) { - if (sr != null) - sr.Close(); + m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString()); } - return true; + return false; } + /// + /// Not sure what sequence causes this function to be invoked. The only calling + /// path is through the GET method + /// public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent) { + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: RetrieveAgent start"); + agent = null; + // Eventually, we want to use a caps url instead of the agentID string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); - request.Method = "GET"; - request.Timeout = 10000; - //request.Headers.Add("authorization", ""); // coming soon - - HttpWebResponse webResponse = null; - string reply = string.Empty; - StreamReader sr = null; try { - webResponse = (HttpWebResponse)request.GetResponse(); - if (webResponse == null) + OSDMap result = WebUtil.GetFromService(uri); + if (result["Success"].AsBoolean()) { - m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent get "); + // OSDMap args = Util.GetOSDMap(result["_RawResult"].AsString()); + OSDMap args = (OSDMap)result["_Result"]; + if (args != null) + { + agent = new CompleteAgentData(); + agent.Unpack(args); + return true; + } } - - sr = new StreamReader(webResponse.GetResponseStream()); - reply = sr.ReadToEnd().Trim(); - - } - catch (WebException ex) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent get {0}", ex.Message); - // ignore, really - return false; - } - finally - { - if (sr != null) - sr.Close(); - } - - if (webResponse.StatusCode == HttpStatusCode.OK) + catch (Exception e) { - // we know it's jason - OSDMap args = Util.GetOSDMap(reply); - if (args == null) - { - return false; - } - - agent = new CompleteAgentData(); - agent.Unpack(args); - return true; + m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString()); } return false; } + /// + /// public bool QueryAccess(GridRegion destination, UUID id) { + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: QueryAccess start"); + IPEndPoint ext = destination.ExternalEndPoint; if (ext == null) return false; + // Eventually, we want to use a caps url instead of the agentID string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); - request.Method = "QUERYACCESS"; - request.Timeout = 10000; - //request.Headers.Add("authorization", ""); // coming soon - - HttpWebResponse webResponse = null; - string reply = string.Empty; - StreamReader sr = null; try { - webResponse = (HttpWebResponse)request.GetResponse(); - if (webResponse == null) - { - m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent query "); - } - - sr = new StreamReader(webResponse.GetResponseStream()); - reply = sr.ReadToEnd().Trim(); - - - } - catch (WebException ex) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent query {0}", ex.Message); - // ignore, really - return false; + OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"QUERYACCESS",10000); + return result["Success"].AsBoolean(); } - finally + catch (Exception e) { - if (sr != null) - sr.Close(); + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] QueryAcess failed with exception; {0}",e.ToString()); } - - if (webResponse.StatusCode == HttpStatusCode.OK) - { - try - { - bool result; - - result = bool.Parse(reply); - - return result; - } - catch - { - return false; - } - } - + return false; } + /// + /// public bool ReleaseAgent(UUID origin, UUID id, string uri) { - WebRequest request = WebRequest.Create(uri); - request.Method = "DELETE"; - request.Timeout = 10000; + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: ReleaseAgent start"); - StreamReader sr = null; try { - WebResponse webResponse = request.GetResponse(); - if (webResponse == null) - { - m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on ReleaseAgent"); - } - - sr = new StreamReader(webResponse.GetResponseStream()); - //reply = sr.ReadToEnd().Trim(); - sr.ReadToEnd().Trim(); - sr.Close(); - //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); - - } - catch (WebException ex) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ReleaseAgent {0}", ex.Message); - return false; + OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"DELETE",10000); } - finally + catch (Exception e) { - if (sr != null) - sr.Close(); + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] ReleaseAgent failed with exception; {0}",e.ToString()); } - + return true; } + /// + /// public bool CloseAgent(GridRegion destination, UUID id) { - string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: CloseAgent start"); - WebRequest request = WebRequest.Create(uri); - request.Method = "DELETE"; - request.Timeout = 10000; + string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; - StreamReader sr = null; try { - WebResponse webResponse = request.GetResponse(); - if (webResponse == null) - { - m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent delete "); - } - - sr = new StreamReader(webResponse.GetResponseStream()); - //reply = sr.ReadToEnd().Trim(); - sr.ReadToEnd().Trim(); - sr.Close(); - //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); - - } - catch (WebException ex) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent delete from {0}: {1}", destination.RegionName, ex.Message); - return false; + OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"DELETE",10000); } - finally + catch (Exception e) { - if (sr != null) - sr.Close(); + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] CloseAgent failed with exception; {0}",e.ToString()); } return true; @@ -552,97 +276,46 @@ namespace OpenSim.Services.Connectors.Simulation return "object/"; } + /// + /// + /// public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) { - string uri - = destination.ServerURI + ObjectPath() + sog.UUID + "/"; - //m_log.Debug(" >>> DoCreateObjectCall <<< " + uri); - - WebRequest ObjectCreateRequest = WebRequest.Create(uri); - ObjectCreateRequest.Method = "POST"; - ObjectCreateRequest.ContentType = "application/json"; - ObjectCreateRequest.Timeout = 10000; - - OSDMap args = new OSDMap(2); - args["sog"] = OSD.FromString(sog.ToXml2()); - args["extra"] = OSD.FromString(sog.ExtraToXmlString()); - args["modified"] = OSD.FromBoolean(sog.HasGroupChanged); - string state = sog.GetStateSnapshot(); - if (state.Length > 0) - args["state"] = OSD.FromString(state); - // Add the input general arguments - args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); - args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); - args["destination_name"] = OSD.FromString(destination.RegionName); - args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); - - string strBuffer = ""; - byte[] buffer = new byte[1]; - try - { - strBuffer = OSDParser.SerializeJsonString(args); - Encoding str = Util.UTF8; - buffer = str.GetBytes(strBuffer); + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: CreateObject start"); - } - catch (Exception e) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of CreateObject: {0}", e.Message); - // ignore. buffer will be empty, caller should check. - } + string uri = destination.ServerURI + ObjectPath() + sog.UUID + "/"; - Stream os = null; try - { // send the Post - ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send - os = ObjectCreateRequest.GetRequestStream(); - os.Write(buffer, 0, strBuffer.Length); //Send it - m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateObject request to remote sim {0}", uri); - } - catch (WebException ex) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on CreateObject {0}", ex.Message); - return false; - } - finally { - if (os != null) - os.Close(); - } + OSDMap args = new OSDMap(2); - // Let's wait for the response - //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); + args["sog"] = OSD.FromString(sog.ToXml2()); + args["extra"] = OSD.FromString(sog.ExtraToXmlString()); + args["modified"] = OSD.FromBoolean(sog.HasGroupChanged); - StreamReader sr = null; - try - { - WebResponse webResponse = ObjectCreateRequest.GetResponse(); - if (webResponse == null) - { - m_log.Warn("[REMOTE SIMULATION CONNECTOR]: Null reply on CreateObject post"); - return false; - } + string state = sog.GetStateSnapshot(); + if (state.Length > 0) + args["state"] = OSD.FromString(state); - sr = new StreamReader(webResponse.GetResponseStream()); - //reply = sr.ReadToEnd().Trim(); - sr.ReadToEnd().Trim(); - //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", reply); + // Add the input general arguments + args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); + args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); + args["destination_name"] = OSD.FromString(destination.RegionName); + args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); + OSDMap result = WebUtil.PostToService(uri,args); } - catch (WebException ex) - { - m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of CreateObject {0}", ex.Message); - return false; - } - finally + catch (Exception e) { - if (sr != null) - sr.Close(); + m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] CreateObject failed with exception; {0}",e.ToString()); } return true; } + /// + /// + /// public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) { // TODO, not that urgent -- cgit v1.1