* refactor: Create IHttpServer interface instead of accessing BaseHttpServer via CommunicationsManager directly

0.6.5-rc1
Justin Clarke Casey 2009-03-19 18:11:44 +00:00
parent b05be5b06b
commit bd2180d9af
9 changed files with 159 additions and 74 deletions

View File

@ -38,7 +38,7 @@ using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Communications.Capabilities;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Interfaces;
@ -97,9 +97,10 @@ namespace OpenSim.Client.Linden
}
//TODO: fix casting.
LibraryRootFolder rootFolder = m_firstScene.CommsManager.UserProfileCacheService.LibraryRoot as LibraryRootFolder;
LibraryRootFolder rootFolder
= m_firstScene.CommsManager.UserProfileCacheService.LibraryRoot as LibraryRootFolder;
BaseHttpServer httpServer = m_firstScene.CommsManager.HttpServer;
IHttpServer httpServer = m_firstScene.CommsManager.HttpServer;
//TODO: fix the casting of the user service, maybe by registering the userManagerBase with scenes, or refactoring so we just need a IUserService reference
m_loginService = new LLStandaloneLoginService((UserManagerBase)m_firstScene.CommsManager.UserService, welcomeMessage, m_firstScene.CommsManager.InterServiceInventoryService, m_firstScene.CommsManager.NetworkServersInfo, authenticate, rootFolder, this);

View File

@ -33,6 +33,7 @@ using System.Reflection;
using log4net;
using OpenMetaverse;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.Interfaces;
// using OpenSim.Region.Framework.Interfaces;
@ -95,7 +96,7 @@ namespace OpenSim.Framework.Communications.Capabilities
// private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule.
//private string eventQueue = "0100/";
private BaseHttpServer m_httpListener;
private IHttpServer m_httpListener;
private UUID m_agentID;
private IAssetCache m_assetCache;
private int m_eventQueueCount = 1;
@ -120,7 +121,7 @@ namespace OpenSim.Framework.Communications.Capabilities
public FetchInventoryDescendentsCAPS CAPSFetchInventoryDescendents = null;
public GetClientDelegate GetClient = null;
public Caps(IAssetCache assetCache, BaseHttpServer httpServer, string httpListen, uint httpPort, string capsPath,
public Caps(IAssetCache assetCache, IHttpServer httpServer, string httpListen, uint httpPort, string capsPath,
UUID agent, bool dumpAssetsToFile, string regionName)
{
m_assetCache = assetCache;
@ -808,7 +809,7 @@ namespace OpenSim.Framework.Communications.Capabilities
private UUID newAssetID;
private UUID inventoryItemID;
private UUID parentFolder;
private BaseHttpServer httpListener;
private IHttpServer httpListener;
private bool m_dumpAssetsToFile;
private string m_assetName = String.Empty;
private string m_assetDes = String.Empty;
@ -818,7 +819,7 @@ namespace OpenSim.Framework.Communications.Capabilities
public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem,
UUID parentFolderID, string invType, string assetType, string path,
BaseHttpServer httpServer, bool dumpAssetsToFile)
IHttpServer httpServer, bool dumpAssetsToFile)
{
m_assetName = assetName;
m_assetDes = description;
@ -907,10 +908,10 @@ namespace OpenSim.Framework.Communications.Capabilities
private string uploaderPath = String.Empty;
private UUID inventoryItemID;
private BaseHttpServer httpListener;
private IHttpServer httpListener;
private bool m_dumpAssetToFile;
public ItemUpdater(UUID inventoryItem, string path, BaseHttpServer httpServer, bool dumpAssetToFile)
public ItemUpdater(UUID inventoryItem, string path, IHttpServer httpServer, bool dumpAssetToFile)
{
m_dumpAssetToFile = dumpAssetToFile;
@ -991,11 +992,11 @@ namespace OpenSim.Framework.Communications.Capabilities
private UUID inventoryItemID;
private UUID primID;
private bool isScriptRunning;
private BaseHttpServer httpListener;
private IHttpServer httpListener;
private bool m_dumpAssetToFile;
public TaskInventoryScriptUpdater(UUID inventoryItemID, UUID primID, int isScriptRunning,
string path, BaseHttpServer httpServer, bool dumpAssetToFile)
string path, IHttpServer httpServer, bool dumpAssetToFile)
{
m_dumpAssetToFile = dumpAssetToFile;

View File

@ -28,6 +28,7 @@
using System.Collections;
using System.Collections.Generic;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.Interfaces;
namespace OpenSim.Framework.Communications.Capabilities
{
@ -39,7 +40,7 @@ namespace OpenSim.Framework.Communications.Capabilities
public class CapsHandlers
{
private Dictionary <string, IRequestHandler> m_capsHandlers = new Dictionary<string, IRequestHandler>();
private BaseHttpServer m_httpListener;
private IHttpServer m_httpListener;
private string m_httpListenerHostName;
private uint m_httpListenerPort;
private bool m_useSSL = false;
@ -67,7 +68,7 @@ namespace OpenSim.Framework.Communications.Capabilities
/// <param name="httpListenerHostname">host name of the HTTP
/// server</param>
/// <param name="httpListenerPort">HTTP port</param>
public CapsHandlers(BaseHttpServer httpListener, string httpListenerHostname, uint httpListenerPort, bool https)
public CapsHandlers(IHttpServer httpListener, string httpListenerHostname, uint httpListenerPort, bool https)
{
m_httpListener = httpListener;
m_httpListenerHostName = httpListenerHostname;

View File

@ -29,7 +29,7 @@ using System;
using System.Collections.Generic;
using OpenMetaverse;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.Interfaces;
namespace OpenSim.Framework.Communications
{
@ -106,12 +106,14 @@ namespace OpenSim.Framework.Communications
}
protected IUserAdminService m_userAdminService;
public BaseHttpServer HttpServer
/// <value>
/// OpenSimulator's built in HTTP server
/// </value>
public IHttpServer HttpServer
{
get { return m_httpServer; }
}
protected BaseHttpServer m_httpServer;
protected IHttpServer m_httpServer;
/// <summary>
/// Constructor
@ -120,7 +122,7 @@ namespace OpenSim.Framework.Communications
/// <param name="httpServer"></param>
/// <param name="assetCache"></param>
/// <param name="dumpAssetsToFile"></param>
public CommunicationsManager(NetworkServersInfo serversInfo, BaseHttpServer httpServer, IAssetCache assetCache,
public CommunicationsManager(NetworkServersInfo serversInfo, IHttpServer httpServer, IAssetCache assetCache,
bool dumpAssetsToFile, LibraryRootFolder libraryRootFolder)
{
m_networkServersInfo = serversInfo;

View File

@ -41,10 +41,11 @@ using Nwc.XmlRpc;
using OpenMetaverse.StructuredData;
using CoolHTTPListener = HttpServer.HttpListener;
using HttpListener=System.Net.HttpListener;
using OpenSim.Framework.Servers.Interfaces;
namespace OpenSim.Framework.Servers
{
public class BaseHttpServer
public class BaseHttpServer : IHttpServer
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private HttpServerLogWriter httpserverlog = new HttpServerLogWriter();
@ -148,11 +149,6 @@ namespace OpenSim.Framework.Servers
return true;
}
/// <summary>
/// Gets the XML RPC handler for given method name
/// </summary>
/// <param name="method">Name of the method</param>
/// <returns>Returns null if not found</returns>
public XmlRpcMethod GetXmlRPCHandler(string method)
{
lock (m_rpcHandlers)
@ -168,32 +164,6 @@ namespace OpenSim.Framework.Servers
}
}
/// <summary>
/// Add a handler for an HTTP request
/// </summary>
///
/// This handler can actually be invoked either as
///
/// http://<hostname>:<port>/?method=<methodName>
///
/// or
///
/// http://<hostname>:<port><method>
///
/// if the method name starts with a slash. For example, AddHTTPHandler("/object/", ...) on a standalone region
/// server will register a handler that can be invoked with either
///
/// http://localhost:9000/?method=/object/
///
/// or
///
/// http://localhost:9000/object/
///
/// <param name="methodName"></param>
/// <param name="handler"></param>
/// <returns>
/// true if the handler was successfully registered, false if a handler with the same name already existed.
/// </returns>
public bool AddHTTPHandler(string methodName, GenericHTTPMethod handler)
{
//m_log.DebugFormat("[BASE HTTP SERVER]: Registering {0}", methodName);
@ -229,12 +199,6 @@ namespace OpenSim.Framework.Servers
return false;
}
/// <summary>
/// Adds a LLSD handler, yay.
/// </summary>
/// <param name="path">/resource/ path</param>
/// <param name="handler">handle the LLSD response</param>
/// <returns></returns>
public bool AddLLSDHandler(string path, LLSDMethod handler)
{
lock (m_llsdHandlers)
@ -1313,7 +1277,6 @@ namespace OpenSim.Framework.Servers
response.ContentLength64 = buffer.Length;
response.ContentEncoding = Encoding.UTF8;
try
{
response.OutputStream.Write(buffer, 0, buffer.Length);
@ -1334,8 +1297,7 @@ namespace OpenSim.Framework.Servers
// This has to be here to prevent a Linux/Mono crash
m_log.WarnFormat("[BASE HTTP SERVER] XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
}
}
}
}
public void SendHTML404(OSHttpResponse response, string host)
@ -1513,11 +1475,6 @@ namespace OpenSim.Framework.Servers
lock (m_streamHandlers) m_streamHandlers.Remove(handlerKey);
}
/// <summary>
/// Remove an HTTP handler
/// </summary>
/// <param name="httpMethod"></param>
/// <param name="path"></param>
public void RemoveHTTPHandler(string httpMethod, string path)
{
lock (m_HTTPHandlers)
@ -1532,12 +1489,6 @@ namespace OpenSim.Framework.Servers
}
}
/// <summary>
/// Remove the agent IF it is registered. Intercept the possible exception.
/// </summary>
/// <param name="agent"></param>
/// <param name="handler"></param>
/// <returns></returns>
public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler)
{
try

View File

@ -0,0 +1,127 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using Nwc.XmlRpc;
using OpenSim.Framework.Servers;
namespace OpenSim.Framework.Servers.Interfaces
{
/// <summary>
/// Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.)
/// for given URLs.
/// </summary>
public interface IHttpServer
{
uint SSLPort { get; }
string SSLCommonName { get; }
uint Port { get; }
bool UseSSL { get; }
// Note that the agent string is provided simply to differentiate
// the handlers - it is NOT required to be an actual agent header
// value.
bool AddAgentHandler(string agent, IHttpAgentHandler handler);
/// <summary>
/// Add a handler for an HTTP request
/// </summary>
///
/// This handler can actually be invoked either as
///
/// http://<hostname>:<port>/?method=<methodName>
///
/// or
///
/// http://<hostname>:<port><method>
///
/// if the method name starts with a slash. For example, AddHTTPHandler("/object/", ...) on a standalone region
/// server will register a handler that can be invoked with either
///
/// http://localhost:9000/?method=/object/
///
/// or
///
/// http://localhost:9000/object/
///
/// <param name="methodName"></param>
/// <param name="handler"></param>
/// <returns>
/// true if the handler was successfully registered, false if a handler with the same name already existed.
/// </returns>
bool AddHTTPHandler(string methodName, GenericHTTPMethod handler);
/// <summary>
/// Adds a LLSD handler, yay.
/// </summary>
/// <param name="path">/resource/ path</param>
/// <param name="handler">handle the LLSD response</param>
/// <returns></returns>
bool AddLLSDHandler(string path, LLSDMethod handler);
/// <summary>
/// Add a stream handler to the http server. If the handler already exists, then nothing happens.
/// </summary>
/// <param name="handler"></param>
void AddStreamHandler(IRequestHandler handler);
bool AddXmlRPCHandler(string method, XmlRpcMethod handler);
bool AddXmlRPCHandler(string method, XmlRpcMethod handler, bool keepAlive);
/// <summary>
/// Gets the XML RPC handler for given method name
/// </summary>
/// <param name="method">Name of the method</param>
/// <returns>Returns null if not found</returns>
XmlRpcMethod GetXmlRPCHandler(string method);
bool SetDefaultLLSDHandler(DefaultLLSDMethod handler);
/// <summary>
/// Remove the agent if it is registered.
/// </summary>
/// <param name="agent"></param>
/// <param name="handler"></param>
/// <returns></returns>
bool RemoveAgentHandler(string agent, IHttpAgentHandler handler);
/// <summary>
/// Remove an HTTP handler
/// </summary>
/// <param name="httpMethod"></param>
/// <param name="path"></param>
void RemoveHTTPHandler(string httpMethod, string path);
bool RemoveLLSDHandler(string path, LLSDMethod handler);
void RemoveStreamHandler(string httpMethod, string path);
string GetHTTP404(string host);
string GetHTTP500();
}
}

View File

@ -38,7 +38,7 @@ using Nwc.XmlRpc;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.Interfaces;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
@ -133,7 +133,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Currency.SampleMoney
if (m_enabled)
{
scene.RegisterModuleInterface<IMoneyModule>(this);
BaseHttpServer httpServer = scene.CommsManager.HttpServer;
IHttpServer httpServer = scene.CommsManager.HttpServer;
lock (m_scenel)
{

View File

@ -35,6 +35,7 @@ using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.Interfaces;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
@ -116,7 +117,7 @@ namespace OpenSim.Region.CoreModules.Hypergrid
IAssetDataPlugin m_assetProvider
= ((AssetServerBase)m_scene.CommsManager.AssetCache.AssetServer).AssetProviderPlugin;
BaseHttpServer httpServer = m_scene.CommsManager.HttpServer;
IHttpServer httpServer = m_scene.CommsManager.HttpServer;
httpServer.AddStreamHandler(new GetAssetStreamHandler(m_assetProvider));
httpServer.AddStreamHandler(new PostAssetStreamHandler(m_assetProvider));

View File

@ -35,6 +35,7 @@ using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Servers.Interfaces;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
@ -114,7 +115,7 @@ namespace OpenSim.Region.CoreModules.Hypergrid
protected void AddHttpHandlers(Scene m_scene)
{
BaseHttpServer httpServer = m_scene.CommsManager.HttpServer;
IHttpServer httpServer = m_scene.CommsManager.HttpServer;
httpServer.AddStreamHandler(
new RestDeserialiseSecureHandler<Guid, InventoryCollection>(