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

java.lang.Object
  extended by org.inria.ns.reflex.util.wunit.XClient
All Implemented Interfaces:
Unwrappable, XOperable
Direct Known Subclasses:
IntrusiveXClient

public class XClient
extends Object
implements XOperable, Unwrappable

A Web client (#wunit:x-client) that can discuss with a Web server.

Author:
Philippe Poulard

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.structures.Unwrappable
Unwrappable.Unwrapper
 
Field Summary
 
Fields inherited from interface org.inria.ns.reflex.structures.Unwrappable
UNWRAPPER
 
Constructor Summary
XClient(WebClient client)
          Create an X-operable window.
 
Method Summary
 void createSession(URI uri, String sessionID)
          Store a session ID in this client.
 HttpState getClientState()
           
 List getCookies(URI uri)
          Return the cookies that match a given URI.
 URI getCurrentURI()
          Return the URI of the current page in the current window.
 HttpClient getHttpClient()
           
 Page getPage(String uri)
          Lookup for the page that has the given URI.
 Page getPage(WebRequestSettings request)
          Get a page from the server.
 String getSessionID(URI uri)
          Return the session ID stored in this client for a given URI.
 XOperator getXOperator()
          Return the XOperator for this class.
 WebRequestSettings newRequest(String method, String url)
          Create a new request.
 void removeSession(URI uri)
          Remove the session for this client.
 Object unwrap()
          Return the wrapped Web window.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XClient

public XClient(WebClient client)
Create an X-operable window.

Parameters:
client - The window of the browser.
Method Detail

getXOperator

public XOperator getXOperator()
Return the XOperator for this class.

Specified by:
getXOperator in interface XOperable
Returns:
The XOperator.

unwrap

public Object unwrap()
Return the wrapped Web window.

Specified by:
unwrap in interface Unwrappable
Returns:
The Web window.
See Also:
WebWindow

newRequest

public WebRequestSettings newRequest(String method,
                                     String url)
                              throws MalformedURLException
Create a new request.

Parameters:
method - The HTTP method.
url - The target URL.
Returns:
The HTTP request.
Throws:
MalformedURLException - When the URL is malformed.

getPage

public Page getPage(WebRequestSettings request)
             throws FailingHttpStatusCodeException,
                    IOException
Get a page from the server.

Parameters:
request - The request to send.
Returns:
The page.
Throws:
FailingHttpStatusCodeException - Shouldn't be thrown, as the client is not configured to throw exceptions on HTTP errors.
IOException - When an I/O error occurs.
See Also:
newRequest(String, String)

getSessionID

public String getSessionID(URI uri)
Return the session ID stored in this client for a given URI.

Parameters:
uri - Contains the target host and a path to a Web application.
Returns:
The session ID for the URI if the relevant cookie is defined by this client, or null.
See Also:
createSession(URI, String), removeSession(URI)

getClientState

public HttpState getClientState()

getHttpClient

public HttpClient getHttpClient()

getCookies

public List getCookies(URI uri)
Return the cookies that match a given URI.

Parameters:
uri - Contains the target host and a path to a Web application.
Returns:
The non-null list of cookies for the URI if the relevant cookies are defined by this client.
See Also:
Cookie

createSession

public void createSession(URI uri,
                          String sessionID)
Store a session ID in this client. This default implementation just create a session cookie ; a client that discusses with a server emulator will be able to create a session server-side.

Parameters:
uri - Contains the target host that must match the host emulated and a path within the Web application hosted.
sessionID - The session ID.
See Also:
ServerEmulator, getSessionID(URI), removeSession(URI)

removeSession

public void removeSession(URI uri)
Remove the session for this client. This default implementation just remove a session cookie ; a client that discusses with a server emulator will be able to remove a session server-side.

Parameters:
uri - Contains the target host and a path.
See Also:
ServerEmulator, getSessionID(URI), createSession(URI, String)

getCurrentURI

public URI getCurrentURI()
                  throws URISyntaxException
Return the URI of the current page in the current window.

Returns:
The URI.
Throws:
URISyntaxException

getPage

public Page getPage(String uri)
Lookup for the page that has the given URI.

Parameters:
uri - The URI to lookup.
Returns:
The page with that URI.