org.openqa.grid.web.servlet.handler
Class RequestHandler

java.lang.Object
  extended by org.openqa.grid.web.servlet.handler.RequestHandler
All Implemented Interfaces:
java.lang.Comparable<RequestHandler>
Direct Known Subclasses:
Selenium1RequestHandler, WebDriverRequestHandler

public abstract class RequestHandler
extends java.lang.Object
implements java.lang.Comparable<RequestHandler>

Base stuff to handle the request coming from a remote. Ideally, there should be only 1 concrete class, but to support both legacy selenium1 and web driver, 2 classes are needed.

Selenium1RequestHandler for the part specific to selenium1 protocol WebDriverRequestHandler for the part specific to webdriver protocol Threading notes; RequestHandlers are instantiated per-request, run on the servlet container thread. The instance is also accessed by the matcher thread.


Constructor Summary
protected RequestHandler(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Registry registry)
           
 
Method Summary
 void bindSession(TestSession session)
           
 int compareTo(RequestHandler o)
           
static RequestHandler createHandler(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Registry registry)
          Detect what kind of protocol ( selenium1 vs webdriver ) is used by the request and create the associated handler.
 java.lang.String debug()
           
 boolean equals(java.lang.Object obj)
           
abstract  java.util.Map<java.lang.String,java.lang.Object> extractDesiredCapability()
          Parse the request to extract the desiredCapabilities.
abstract  RequestType extractRequestType()
           
abstract  ExternalSessionKey extractSession()
          Extract the session from the request.
abstract  ExternalSessionKey forwardNewSessionRequest(TestSession session)
          Forward the new session request to the TestSession that has been assigned, and parse the response to extract and return the external key assigned by the remote.
protected  void forwardRequest(TestSession session, RequestHandler handler)
           
 java.util.Map<java.lang.String,java.lang.Object> getDesiredCapabilities()
           
 Registry getRegistry()
           
 javax.servlet.http.HttpServletRequest getRequest()
          the HttpServletRequest this hanlder is processing.
protected  java.lang.String getRequestBody()
          reads the input stream of the request and returns its content.
protected  RequestType getRequestType()
           
 javax.servlet.http.HttpServletResponse getResponse()
          the HttpServletResponse the handler is writing to.
 ExternalSessionKey getServerSession()
          return the session from the server ( = opaque handle used by the server to determine where to route session-specific commands fro mthe JSON wire protocol ). will be null until the request has been processed.
protected  TestSession getSession()
           
 int hashCode()
           
 void process()
          forwards the request to the remote, allocating / releasing the resources if necessary.
protected  void setDesiredCapabilities(java.util.Map<java.lang.String,java.lang.Object> desiredCapabilities)
           
protected  void setRequestType(RequestType requestType)
           
protected  void setSession(TestSession session)
           
 void stop()
           
 java.lang.String toString()
           
 void waitForSessionBound()
          wait for the registry to match the request with a TestSlot.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RequestHandler

protected RequestHandler(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response,
                         Registry registry)
Method Detail

createHandler

public static RequestHandler createHandler(javax.servlet.http.HttpServletRequest request,
                                           javax.servlet.http.HttpServletResponse response,
                                           Registry registry)
Detect what kind of protocol ( selenium1 vs webdriver ) is used by the request and create the associated handler.


extractRequestType

public abstract RequestType extractRequestType()
Returns:
the type of the request.

extractSession

public abstract ExternalSessionKey extractSession()
Extract the session from the request. This only works for a request that has a session already assigned. It shouldn't be called for a new session request.

Returns:
the external session id sent by the remote. Null is the session cannot be found.

extractDesiredCapability

public abstract java.util.Map<java.lang.String,java.lang.Object> extractDesiredCapability()
Parse the request to extract the desiredCapabilities. For non web driver protocol ( selenium1 ) some mapping will be necessary

Returns:
the desired capabilities requested by the client.

forwardNewSessionRequest

public abstract ExternalSessionKey forwardNewSessionRequest(TestSession session)
                                                     throws NewSessionException
Forward the new session request to the TestSession that has been assigned, and parse the response to extract and return the external key assigned by the remote.

Returns:
the external key sent by the remote.
Throws:
NewSessionException - in case anything wrong happens during the new session process.

forwardRequest

protected void forwardRequest(TestSession session,
                              RequestHandler handler)
                       throws java.io.IOException
Throws:
java.io.IOException

process

public void process()
forwards the request to the remote, allocating / releasing the resources if necessary.


waitForSessionBound

public void waitForSessionBound()
                         throws java.lang.InterruptedException,
                                java.util.concurrent.TimeoutException
wait for the registry to match the request with a TestSlot.

Throws:
java.lang.InterruptedException
java.util.concurrent.TimeoutException - if the request reaches the new session wait timeout before being assigned.

getRequestBody

protected java.lang.String getRequestBody()
reads the input stream of the request and returns its content.


getRequest

public javax.servlet.http.HttpServletRequest getRequest()
the HttpServletRequest this hanlder is processing.


getResponse

public javax.servlet.http.HttpServletResponse getResponse()
the HttpServletResponse the handler is writing to.


getDesiredCapabilities

public java.util.Map<java.lang.String,java.lang.Object> getDesiredCapabilities()

setDesiredCapabilities

protected void setDesiredCapabilities(java.util.Map<java.lang.String,java.lang.Object> desiredCapabilities)

compareTo

public int compareTo(RequestHandler o)
Specified by:
compareTo in interface java.lang.Comparable<RequestHandler>

getRequestType

protected RequestType getRequestType()

setRequestType

protected void setRequestType(RequestType requestType)

setSession

protected void setSession(TestSession session)

bindSession

public void bindSession(TestSession session)

getSession

protected TestSession getSession()

getServerSession

public ExternalSessionKey getServerSession()
return the session from the server ( = opaque handle used by the server to determine where to route session-specific commands fro mthe JSON wire protocol ). will be null until the request has been processed.


stop

public void stop()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

debug

public java.lang.String debug()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getRegistry

public Registry getRegistry()


Copyright © 2011. All Rights Reserved.