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.18 $ $Date: 2006/10/24 11:12:33 $
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 url, char[] data, Map headers)
          Deprecated. Since XINS 1.5.0. The way the HTTP method is determined is incorrect. Use query(String,String,String,Map) instead.
 XINSServletResponse query(String url, char[] data, String contentType)
          Deprecated. Since XINS 1.5.0. The way the HTTP method is determined is incorrect. Use query(String,String,String,Map) instead.
 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 url,
                                 char[] data,
                                 String contentType)
                          throws IOException
Deprecated. Since XINS 1.5.0. The way the HTTP method is determined is incorrect. Use query(String,String,String,Map) instead.

Queries the servlet with the specified URL, content and MIME type.

Parameters:
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, can be null.
contentType - the content type of the request, can be null.
Returns:
the servlet response.
Throws:
IOException - If the query is not handled correctly by the servlet.
Since:
XINS 1.3.0

query

public XINSServletResponse query(String url,
                                 char[] data,
                                 Map headers)
                          throws IOException
Deprecated. Since XINS 1.5.0. The way the HTTP method is determined is incorrect. Use query(String,String,String,Map) instead.

Queries the Servlet with the specified URL with the specific content and the specified HTTP headers.

Parameters:
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.
Returns:
the servlet response.
Throws:
IOException - If the query is not handled correctly by the servlet.
Since:
XINS 1.4.0

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/.