org.xins.common.servlet.container
Class LocalServletHandler

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

public class LocalServletHandler
extends Object

This class allows to invoke a XINS API without using HTTP. Example: LocalServletHandler handler = LocalServletHandler.getInstance("c:\\test\\myproject.war"); String xmlResult = handler.query("http://127.0.0.1:8080/myproject/?_function=MyFunction&gender=f&personLastName=Lee");

Version:
$Revision: 1.26 $ $Date: 2008/07/04 10:22:53 $
Author:
Anthony Goubard

Constructor Summary
LocalServletHandler(File warFile)
          Creates a Servlet handler that allow to invoke a Servlet without starting a HTTP server.
LocalServletHandler(String servletClassName)
          Creates a Servlet handler that allow to invoke a Servlet without starting a HTTP server.
 
Method Summary
 void close()
          Disposes the Servlet and closes this Servlet handler.
 Object getServlet()
          Gets the Servlet.
 void initServlet(File warFile)
          Initializes the Servlet.
 void initServlet(String servletClassName)
          Initializes the Servlet.
 XINSServletResponse query(String url)
          Queries the Servlet with the specified URL.
 XINSServletResponse query(String method, String url, String data, Map headers)
          Queries the servlet with the specified method, URL, content and HTTP headers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalServletHandler

public LocalServletHandler(File warFile)
                    throws ServletException
Creates a Servlet handler that allow to invoke a Servlet without starting a HTTP server.

Parameters:
warFile - the location of the war file containing the Servlet, cannot be null.
Throws:
ServletException - if the Servlet cannot be created.

LocalServletHandler

public LocalServletHandler(String servletClassName)
                    throws ServletException
Creates a Servlet handler that allow to invoke a Servlet without starting a HTTP server.

Parameters:
servletClassName - The name of the servlet's class to load, cannot be null.
Throws:
ServletException - if the Servlet cannot be created.
Method Detail

initServlet

public void initServlet(File warFile)
                 throws ServletException
Initializes the Servlet.

Parameters:
warFile - the location of the war file, cannot be null.
Throws:
ServletException - if the Servlet cannot be loaded.

initServlet

public void initServlet(String servletClassName)
                 throws ServletException
Initializes the Servlet.

Parameters:
servletClassName - The name of the servlet's class to load, cannot be null.
Throws:
ServletException - if the Servlet cannot be loaded.

getServlet

public Object getServlet()
Gets the Servlet.

Returns:
the created Servlet or null if no Servlet was created.

query

public XINSServletResponse query(String url)
                          throws IOException
Queries the Servlet with the specified URL.

Parameters:
url - the url query for the request.
Returns:
the servlet response.
Throws:
IOException - If the query is not handled correctly by the servlet.

query

public XINSServletResponse query(String method,
                                 String url,
                                 String data,
                                 Map headers)
                          throws IOException
Queries the servlet with the specified method, URL, content and HTTP headers.

Parameters:
method - the request method, cannot be null.
url - the url query for the request, if null then the / path is used as default with no parameters.
data - the data post for the request. null for HTTP GET queries.
headers - the HTTP headers passed with the query, cannot be null. The key and the value of the Map is String. The keys are all in uppercase.
Returns:
the servlet response.
Throws:
IOException - If the query is not handled correctly by the servlet.
Since:
XINS 1.5.0

close

public void close()
Disposes the Servlet and closes this Servlet handler.



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