Class InternalServer
java.lang.Object
org.astrogrid.samp.xmlrpc.internal.InternalServer
- All Implemented Interfaces:
SampXmlRpcServer
- Direct Known Subclasses:
RpcLoggingInternalServer
,XmlLoggingInternalServer
SampXmlRpcServer implementation without external dependencies.
The
reqInfo
argument passed to the
handleCall
method of registered
SampXmlRpcHandler
s is the associated
HttpServer.Request
.- Since:
- 27 Aug 2008
- Author:
- Mark Taylor
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a server running with default characteristics.InternalServer
(HttpServer httpServer, String path) Constructor based on a given HTTP server. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHandler
(SampXmlRpcHandler handler) Adds a handler which can service certain XML-RPC methods.Returns the server's endpoint.static byte[]
getFaultBytes
(Throwable error) Turns an exception into an array of bytes giving an XML-RPC methodResponse (fault) document.Returns the HTTP server hosting this XML-RPC server.static byte[]
getResultBytes
(Object result) Turns a SAMP-friendly (string, list, map only) object into an array of bytes giving an XML-RPC methodResponse document.protected HttpServer.Response
getXmlRpcResponse
(HttpServer.Request request) Returns the HTTP response object given an incoming XML-RPC POST request.protected Object
handleCall
(SampXmlRpcHandler handler, String methodName, List paramList, HttpServer.Request request) Actually passes the XML-RPC method name and parameter list to one of the registered servers for processing.void
removeHandler
(SampXmlRpcHandler handler) Removes a previously-added handler.
-
Constructor Details
-
InternalServer
Constructor based on a given HTTP server. It is the caller's responsibility to configure and start the HttpServer.- Parameters:
httpServer
- server for processing HTTP requestspath
- path part of server endpoint (starts with "/");- Throws:
IOException
-
InternalServer
Constructs a server running with default characteristics. Currently, the default serverUtilServer.getInstance()
is used.- Throws:
IOException
-
-
Method Details
-
getEndpoint
Description copied from interface:SampXmlRpcServer
Returns the server's endpoint.- Specified by:
getEndpoint
in interfaceSampXmlRpcServer
- Returns:
- URL to which XML-RPC requests are POSTed
-
getHttpServer
Returns the HTTP server hosting this XML-RPC server.- Returns:
- http server
-
addHandler
Description copied from interface:SampXmlRpcServer
Adds a handler which can service certain XML-RPC methods.- Specified by:
addHandler
in interfaceSampXmlRpcServer
- Parameters:
handler
- handler to add
-
removeHandler
Description copied from interface:SampXmlRpcServer
Removes a previously-added handler.- Specified by:
removeHandler
in interfaceSampXmlRpcServer
- Parameters:
handler
- handler to remove
-
getXmlRpcResponse
Returns the HTTP response object given an incoming XML-RPC POST request. Any error should be handled by returning a fault-type methodResponse element rather than by throwing an exception.- Parameters:
request
- POSTed HTTP request- Returns:
- XML-RPC response (possibly fault)
-
handleCall
protected Object handleCall(SampXmlRpcHandler handler, String methodName, List paramList, HttpServer.Request request) throws Exception Actually passes the XML-RPC method name and parameter list to one of the registered servers for processing.- Parameters:
handler
- handler which has declared it can handle the named methodmethodName
- XML-RPC method nameparamList
- list of parameters to XML-RPC callrequest
- HTTP request from which this call originated- Throws:
Exception
-
getResultBytes
Turns a SAMP-friendly (string, list, map only) object into an array of bytes giving an XML-RPC methodResponse document.- Parameters:
result
- SAMP-friendly object- Returns:
- XML methodResponse document as byte array
- Throws:
IOException
-
getFaultBytes
Turns an exception into an array of bytes giving an XML-RPC methodResponse (fault) document.- Parameters:
error
- throwable- Returns:
- XML methodResponse document as byte array
- Throws:
IOException
-