org.inria.ns.reflex.util.wunit
Class ServerEmulator

java.lang.Object
  extended by org.inria.ns.reflex.util.wunit.ClientFactory
      extended by org.inria.ns.reflex.util.wunit.ServerEmulator

public class ServerEmulator
extends ClientFactory

Emulates a Web server. This emulator can supply Web clients that can send requests and receive response without using connexions, which allows to get server-side components (application, service, session, request, response).

Author:
Philippe Poulard

Constructor Summary
ServerEmulator(File deploymentDescriptor, URI uri)
          Create a new emulator with a main Web application (the main Web application is not necessary deployed on the root).
 
Method Summary
 void addApplication(File deploymentDescriptor, URI uri)
          Add a Web application to this emulator.
 HttpServlet getHttpServlet(URI uri)
          Return the servlet that match a given URI.
 HttpService getService(URI uri, InputStream inputRequest, OutputStream outputResponse)
          Get the service that can process an HTTP request.
 ServletContext getServletContext(URI uri)
          Return the servlet context that match a given URI.
 HttpSession getSession(URI uri, XClient client)
          Get or create a session.
 void stop()
          Release the host emulated.
 
Methods inherited from class org.inria.ns.reflex.util.wunit.ClientFactory
getInstance, newClient
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerEmulator

public ServerEmulator(File deploymentDescriptor,
                      URI uri)
               throws IOException,
                      SAXException
Create a new emulator with a main Web application (the main Web application is not necessary deployed on the root).

Parameters:
deploymentDescriptor - The deployment descriptor of the Web application. Can be either : the file "WEB-INF/web.xml", the war file "xxx.war", or a directory that contains the file "WEB-INF/web.xml".
uri - The uri that serves the Web application : the host, port and optional context path of the Web application, e.g. "http://www.example.com:80/myApp/"
dataSet - The data set that will receive the $wunit:XXX properties.
Throws:
SAXException - When the web.xml file is not valid or not well-formed.
IOException - When the web.xml file cause an I/O exception.
See Also:
addApplication(File, URI)
Method Detail

addApplication

public void addApplication(File deploymentDescriptor,
                           URI uri)
                    throws IOException
Add a Web application to this emulator.

Parameters:
deploymentDescriptor - The deployment descriptor of the Web application. Can be either : the file "WEB-INF/web.xml", the war file "xxx.war", or a directory that contains the file "WEB-INF/web.xml".
uri - The uri that serves the Web application : the host, port and optional context path of the Web application, e.g. "http://www.example.com:80/myApp/"
Throws:
IOException
SAXException - When the web.xml file is not valid or not well-formed.
IOException - When the web.xml file cause an I/O exception.

getService

public HttpService getService(URI uri,
                              InputStream inputRequest,
                              OutputStream outputResponse)
                       throws IOException,
                              ServletException
Get the service that can process an HTTP request.

Parameters:
uri - Contains the target host that must match the host emulated.
input - The plain HTTP input request.
output - The output that will receive the response. Note that nothing is written in the output until the service is invoked.
Returns:
An abstraction of server-side components ready to process the request.
Throws:
IOException - When an I/O error occur.
ServletException - When the emulator fails to process the request.
See Also:
HttpService.service()

getServletContext

public ServletContext getServletContext(URI uri)
Return the servlet context that match a given URI.

Parameters:
uri - Contains the target host that must match the host emulated and a path within the Web application hosted.
Returns:
The servlet context that matches the URI, or null.

getHttpServlet

public HttpServlet getHttpServlet(URI uri)
Return the servlet that match a given URI.

Parameters:
uri - Contains the target host that must match the host emulated and a path within the Web application hosted.
Returns:
The servlet that matches the URI, or null.

getSession

public HttpSession getSession(URI uri,
                              XClient client)
Get or create a session.

Parameters:
uri - Contains the target host that must match the host emulated and a path within the Web application hosted.
client - The client that hold the state that either already refer to an existing session or to which the new session ID will be stored. null is returned if the URI doesn't match a Web application hold in this emulator.
Returns:
A session.
See Also:
XClient.getCurrentURI()

stop

public void stop()
Release the host emulated.