org.xins.common.servlet.container
Class HTTPServletHandler

java.lang.Object
  extended byorg.xins.common.servlet.container.HTTPServletHandler

public class HTTPServletHandler
extends Object

HTTP server used to invoke the XINS servlet.

Version:
$Revision: 1.49 $ $Date: 2006/10/31 15:41:44 $
Author:
Anthony Goubard, Ernst de Haan

Field Summary
static int DEFAULT_PORT_NUMBER
          The default port number is 8080.
 
Constructor Summary
HTTPServletHandler(File warFile)
          Creates a new HTTPServletHandler.
HTTPServletHandler(File warFile, int port, boolean daemon)
          Creates a new HTTPSevletHandler.
HTTPServletHandler(int port, boolean daemon)
          Creates a new HTTPSevletHandler with no Servlet.
HTTPServletHandler(String servletClassName)
          Creates a new HTTPSevletHandler.
HTTPServletHandler(String servletClassName, int port, boolean daemon)
          Creates a new HTTPSevletHandler.
 
Method Summary
 void addServlet(String servletClassName, String virtualPath)
          Adds a new servlet.
 void addWAR(File warFile, String virtualPath)
          Adds a WAR file to the server.
 void close()
          Disposes the servlet and stops the web server.
 int getPort()
          Returns the port the server is accepting connections on.
 void httpQuery(InputStream in, OutputStream out)
          This method parses the data sent from the client to get the input parameters and format the result as a compatible HTTP result.
 void removeServlet(String virtualPath)
          Remove a servlet from the server.
 void serviceClient(Socket client)
          This method is invoked when a client connects to the server.
 void startServer(int port, boolean daemon)
          Starts the web server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT_NUMBER

public static final int DEFAULT_PORT_NUMBER
The default port number is 8080.

See Also:
Constant Field Values
Constructor Detail

HTTPServletHandler

public HTTPServletHandler(int port,
                          boolean daemon)
                   throws IOException
Creates a new HTTPSevletHandler with no Servlet. Use the addServlet methods to add the WAR files or the Servlets.

Parameters:
port - The port of the servlet server.
daemon - true if the thread listening to connection should be a daemon thread, false otherwise.
Throws:
IOException - if the servlet container cannot be started.

HTTPServletHandler

public HTTPServletHandler(File warFile)
                   throws ServletException,
                          IOException
Creates a new HTTPServletHandler. This servlet handler starts a web server on port 8080 and wait for calls from the XINSServiceCaller.

Note that all the libraries used by this WAR file should already be in the classpath.

Parameters:
warFile - the war file of the application to deploy, cannot be null.
Throws:
ServletException - if the servlet cannot be initialized.
IOException - if the servlet container cannot be started.

HTTPServletHandler

public HTTPServletHandler(File warFile,
                          int port,
                          boolean daemon)
                   throws ServletException,
                          IOException
Creates a new HTTPSevletHandler. This servlet handler starts a web server on the specified port and waits for calls from the XINSServiceCaller. Note that all the libraries used by this WAR file should already be in the classpath.

Parameters:
warFile - the war file of the application to deploy, cannot be null.
port - The port of the servlet server.
daemon - true if the thread listening to connection should be a daemon thread, false otherwise.
Throws:
ServletException - if the servlet cannot be initialized.
IOException - if the servlet container cannot be started.

HTTPServletHandler

public HTTPServletHandler(String servletClassName)
                   throws ServletException,
                          IOException
Creates a new HTTPSevletHandler. This Servlet handler starts a web server and wait for calls from the XINSServiceCaller.

Parameters:
servletClassName - The name of the servlet's class to load, cannot be null.
Throws:
ServletException - if the servlet cannot be initialized.
IOException - if the servlet container cannot be started.

HTTPServletHandler

public HTTPServletHandler(String servletClassName,
                          int port,
                          boolean daemon)
                   throws ServletException,
                          IOException
Creates a new HTTPSevletHandler. This Servlet handler starts a web server and wait for calls from the XINSServiceCaller.

Parameters:
servletClassName - The name of the servlet's class to load, cannot be null.
port - The port of the servlet server.
daemon - true if the thread listening to connection should be a daemon thread, false otherwise.
Throws:
ServletException - if the servlet cannot be initialized.
IOException - if the servlet container cannot be started.
Method Detail

addWAR

public void addWAR(File warFile,
                   String virtualPath)
            throws ServletException
Adds a WAR file to the server. The servlet with the virtual path "/" will be the default one. Note that all the libraries used by this WAR file should already be in the classpath.

Parameters:
warFile - The war file of the application to deploy, cannot be null.
virtualPath - The virtual path of the HTTP server that links to this WAR file, cannot be null.
Throws:
ServletException - if the servlet cannot be initialized.

addServlet

public void addServlet(String servletClassName,
                       String virtualPath)
                throws ServletException
Adds a new servlet. The servlet with the virtual path "/" will be the default one.

Parameters:
servletClassName - The name of the servlet's class to load, cannot be null.
virtualPath - The virtual path of the HTTP server that links to this WAR file, cannot be null.
Throws:
ServletException - if the servlet cannot be initialized.

removeServlet

public void removeServlet(String virtualPath)
Remove a servlet from the server.

Parameters:
virtualPath - The virtual path of the servlet to remove, cannot be null.

startServer

public void startServer(int port,
                        boolean daemon)
                 throws IOException
Starts the web server.

Parameters:
port - the port of the servlet server.
daemon - true if the thread listening to connection should be a daemon thread, false otherwise.
Throws:
IOException - if the web server cannot be started.

getPort

public int getPort()
            throws IllegalStateException
Returns the port the server is accepting connections on.

Returns:
the server socket, e.g. 8080.
Throws:
IllegalStateException - if the port cannot be determined, for example because the server is not started.
Since:
XINS 1.5.0

close

public void close()
Disposes the servlet and stops the web server.


serviceClient

public void serviceClient(Socket client)
                   throws IllegalArgumentException,
                          IOException
This method is invoked when a client connects to the server.

Parameters:
client - the connection with the client, cannot be null.
Throws:
IllegalArgumentException - if client == null.
IOException - if the query is not handled correctly.

httpQuery

public void httpQuery(InputStream in,
                      OutputStream out)
               throws IOException
This method parses the data sent from the client to get the input parameters and format the result as a compatible HTTP result. This method will used the servlet associated with the passed virtual path. If no servlet is associated with the virtual path, the servlet with the virtual path "/" is used as default. If there is no servlet then with the virtual path "/" is found then HTTP 404 is returned.

Parameters:
in - the input byte stream that contains the request sent by the client.
out - the output byte stream that must be fed the response towards the client.
Throws:
IOException - if the query is not handled correctly.
Since:
XINS 1.5.0.


See http://www.xins.org/.