public class LocalServletHandler extends Object
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");
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public LocalServletHandler(File warFile) throws ServletException
warFile
- the location of the war file containing the Servlet, cannot be
null
.ServletException
- if the Servlet cannot be created.public LocalServletHandler(String servletClassName) throws ServletException
servletClassName
- The name of the servlet's class to load, cannot be null
.ServletException
- if the Servlet cannot be created.public void initServlet(File warFile) throws ServletException
warFile
- the location of the war file, cannot be null
.ServletException
- if the Servlet cannot be loaded.public void initServlet(String servletClassName) throws ServletException
servletClassName
- The name of the servlet's class to load, cannot be null
.ServletException
- if the Servlet cannot be loaded.public Object getServlet()
null
if no Servlet was created.public XINSServletResponse query(String url) throws IOException
url
- the url query for the request.IOException
- If the query is not handled correctly by the servlet.public XINSServletResponse query(String method, String url, String data, Map headers) throws IOException
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.IOException
- If the query is not handled correctly by the servlet.public void close()
See http://www.xins.org/.