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


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  java.lang.String extractSession()
          Extract the session from the request.
abstract  java.lang.String 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)
           
 long getCreated()
           
 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.
 java.lang.String 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 ).
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)
           
 java.lang.String toString()
           
 
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.

Parameters:
request -
response -
registry -
Returns:

extractRequestType

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

extractSession

public abstract java.lang.String 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 java.lang.String 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.

Parameters:
session -
Returns:
the external key sent by the remote, null is something went wrong.
Throws:
java.io.IOException

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.


getRequestBody

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

Returns:

getRequest

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

Returns:

getResponse

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

Returns:

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 java.lang.String 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.

Returns:

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

getCreated

public long getCreated()

getRegistry

public Registry getRegistry()


Copyright © 2011. All Rights Reserved.