Class InternalServer

    • Constructor Summary

      Constructors 
      Constructor Description
      InternalServer()
      Constructs a server running with default characteristics.
      InternalServer​(HttpServer httpServer, java.lang.String path)
      Constructor based on a given HTTP server.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addHandler​(SampXmlRpcHandler handler)
      Adds a handler which can service certain XML-RPC methods.
      java.net.URL getEndpoint()
      Returns the server's endpoint.
      static 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.
      static 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.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InternalServer

        public InternalServer​(HttpServer httpServer,
                              java.lang.String path)
                       throws java.io.IOException
        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 requests
        path - path part of server endpoint (starts with "/");
        Throws:
        java.io.IOException
      • InternalServer

        public InternalServer()
                       throws java.io.IOException
        Constructs a server running with default characteristics. Currently, the default server UtilServer.getInstance() is used.
        Throws:
        java.io.IOException
    • Method Detail

      • getEndpoint

        public java.net.URL getEndpoint()
        Description copied from interface: SampXmlRpcServer
        Returns the server's endpoint.
        Specified by:
        getEndpoint in interface SampXmlRpcServer
        Returns:
        URL to which XML-RPC requests are POSTed
      • getHttpServer

        public HttpServer getHttpServer()
        Returns the HTTP server hosting this XML-RPC server.
        Returns:
        http server
      • getXmlRpcResponse

        protected HttpServer.Response getXmlRpcResponse​(HttpServer.Request request)
        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 java.lang.Object handleCall​(SampXmlRpcHandler handler,
                                              java.lang.String methodName,
                                              java.util.List paramList,
                                              HttpServer.Request request)
                                       throws java.lang.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 method
        methodName - XML-RPC method name
        paramList - list of parameters to XML-RPC call
        request - HTTP request from which this call originated
        Throws:
        java.lang.Exception
      • getResultBytes

        public static byte[] getResultBytes​(java.lang.Object result)
                                     throws java.io.IOException
        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:
        java.io.IOException
      • getFaultBytes

        public static byte[] getFaultBytes​(java.lang.Throwable error)
                                    throws java.io.IOException
        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:
        java.io.IOException