public class InternalServer extends java.lang.Object implements SampXmlRpcServer
reqInfo
argument passed to the
handleCall
method of registered
SampXmlRpcHandler
s is the associated
HttpServer.Request
.Modifier and Type | Field and Description |
---|---|
private java.net.URL |
endpoint_ |
private static HttpServer.Response |
GET_RESPONSE |
private java.util.List |
handlerList_ |
private static HttpServer.Response |
HEAD_RESPONSE |
private static java.util.logging.Logger |
logger_ |
private HttpServer |
server_ |
private HttpServer.Handler |
serverHandler_ |
Constructor and Description |
---|
InternalServer()
Constructs a server running with default characteristics.
|
InternalServer(HttpServer httpServer,
java.lang.String path)
Constructor based on a given HTTP server.
|
Modifier and Type | Method and Description |
---|---|
void |
addHandler(SampXmlRpcHandler handler)
Adds a handler which can service certain XML-RPC methods.
|
private static HttpServer.Response |
createInfoResponse(boolean withData)
Returns a simple response suitable for GET/HEAD at the XML-RPC
server's endpoint.
|
java.net.URL |
getEndpoint()
Returns the server's endpoint.
|
private byte[] |
getFaultBytes(java.lang.Throwable error)
Turns an exception into an array of bytes giving an XML-RPC
methodResponse (fault) document.
|
HttpServer |
getHttpServer()
Returns the HTTP server hosting this XML-RPC server.
|
private byte[] |
getResultBytes(java.lang.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.
|
private java.lang.Object |
getXmlRpcResult(HttpServer.Request request)
Returns the SAMP-friendly (string, list and map only) object representing
the reply to an XML-RPC request given by a request.
|
protected java.lang.Object |
handleCall(SampXmlRpcHandler handler,
java.lang.String methodName,
java.util.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.
|
private final HttpServer server_
private final java.net.URL endpoint_
private final java.util.List handlerList_
private final HttpServer.Handler serverHandler_
private static final HttpServer.Response GET_RESPONSE
private static final HttpServer.Response HEAD_RESPONSE
private static final java.util.logging.Logger logger_
public InternalServer(HttpServer httpServer, java.lang.String path) throws java.io.IOException
httpServer
- server for processing HTTP requestspath
- path part of server endpoint (starts with "/");java.io.IOException
public InternalServer() throws java.io.IOException
UtilServer.getInstance()
is used.java.io.IOException
public java.net.URL getEndpoint()
SampXmlRpcServer
getEndpoint
in interface SampXmlRpcServer
public HttpServer getHttpServer()
public void addHandler(SampXmlRpcHandler handler)
SampXmlRpcServer
addHandler
in interface SampXmlRpcServer
handler
- handler to addpublic void removeHandler(SampXmlRpcHandler handler)
SampXmlRpcServer
removeHandler
in interface SampXmlRpcServer
handler
- handler to removeprotected HttpServer.Response getXmlRpcResponse(HttpServer.Request request)
request
- POSTed HTTP requestprivate java.lang.Object getXmlRpcResult(HttpServer.Request request) throws java.lang.Exception
request
- POSTed HTTP requestjava.lang.Exception
- in case of error (will become XML-RPC fault)protected java.lang.Object handleCall(SampXmlRpcHandler handler, java.lang.String methodName, java.util.List paramList, HttpServer.Request request) throws java.lang.Exception
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 originatedjava.lang.Exception
private byte[] getResultBytes(java.lang.Object result) throws java.io.IOException
result
- SAMP-friendly objectjava.io.IOException
private byte[] getFaultBytes(java.lang.Throwable error) throws java.io.IOException
error
- throwablejava.io.IOException
private static HttpServer.Response createInfoResponse(boolean withData)
withData
- true for text (GET), false for no text (HEAD)