Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.meterware.servletunit
Class InvocationContextImpl  view InvocationContextImpl download InvocationContextImpl.java

java.lang.Object
  extended bycom.meterware.servletunit.InvocationContextImpl
All Implemented Interfaces:
InvocationContext

class InvocationContextImpl
extends java.lang.Object
implements InvocationContext

This class represents the context in which a specific servlet request is being made. It contains the objects needed to unit test the methods of a servlet.


Nested Class Summary
(package private)  class InvocationContextImpl.AccessDeniedException
           
(package private) static class InvocationContextImpl.ExecutionContext
           
(package private) static class InvocationContextImpl.FilterContext
           
 
Field Summary
private  WebApplication _application
           
private  ServletUnitClient _client
           
private  java.util.Stack _contextStack
           
private  java.net.URL _effectiveURL
           
private  com.meterware.httpunit.FrameSelector _frame
           
private  com.meterware.httpunit.WebResponse _webResponse
           
 
Constructor Summary
(package private) InvocationContextImpl(ServletUnitClient client, ServletRunner runner, com.meterware.httpunit.FrameSelector frame, com.meterware.httpunit.WebRequest request, java.util.Dictionary clientHeaders, byte[] messageBody)
          Constructs a servlet invocation context for a specified servlet container, request, and cookie headers.
 
Method Summary
private  java.net.URL computeEffectiveUrl(javax.servlet.http.HttpServletRequest request, java.net.URL requestURL)
           
private  InvocationContextImpl.ExecutionContext getContext()
           
 javax.servlet.Filter getFilter()
          Returns the current active filter object.
 javax.servlet.FilterChain getFilterChain()
          Returns the current filter chain.
 com.meterware.httpunit.FrameSelector getFrame()
          Returns the target frame for the original request.
 javax.servlet.http.HttpServletRequest getRequest()
          Returns the request to be processed by the servlet or filter.
 javax.servlet.http.HttpServletResponse getResponse()
          Returns the response which the servlet or filter should modify during its operation.
 javax.servlet.Servlet getServlet()
          Returns the selected servlet, initialized to provide access to sessions and servlet context information.
 com.meterware.httpunit.WebResponse getServletResponse()
          Returns the final response from the servlet.
 boolean isFilterActive()
          Returns true if the current context is a filter, rather than a servlet.
 void popRequest()
          Removes the top request dispatcher or filter from this context.
 void pushFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          Pushes the current filter onto the execution stack and switches to the next filter or the selected servlet.
 void pushForwardRequest(javax.servlet.RequestDispatcher rd, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Adds a request dispatcher to this context to simulate a forward request.
 void pushIncludeRequest(javax.servlet.RequestDispatcher rd, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Adds a request dispatcher to this context to simulate an include request.
 void service()
          Invokes the current servlet or filter.
private  boolean userIsAuthorized(javax.servlet.http.HttpServletRequest request, java.net.URL requestURL)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_contextStack

private java.util.Stack _contextStack

_effectiveURL

private java.net.URL _effectiveURL

_client

private ServletUnitClient _client

_application

private WebApplication _application

_frame

private com.meterware.httpunit.FrameSelector _frame

_webResponse

private com.meterware.httpunit.WebResponse _webResponse
Constructor Detail

InvocationContextImpl

InvocationContextImpl(ServletUnitClient client,
                      ServletRunner runner,
                      com.meterware.httpunit.FrameSelector frame,
                      com.meterware.httpunit.WebRequest request,
                      java.util.Dictionary clientHeaders,
                      byte[] messageBody)
                throws java.io.IOException,
                       java.net.MalformedURLException
Constructs a servlet invocation context for a specified servlet container, request, and cookie headers.

Method Detail

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Returns the request to be processed by the servlet or filter.

Specified by:
getRequest in interface InvocationContext

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Returns the response which the servlet or filter should modify during its operation.

Specified by:
getResponse in interface InvocationContext

service

public void service()
             throws javax.servlet.ServletException,
                    java.io.IOException
Invokes the current servlet or filter.

Specified by:
service in interface InvocationContext

getServlet

public javax.servlet.Servlet getServlet()
                                 throws javax.servlet.ServletException
Returns the selected servlet, initialized to provide access to sessions and servlet context information.

Specified by:
getServlet in interface InvocationContext

getServletResponse

public com.meterware.httpunit.WebResponse getServletResponse()
                                                      throws java.io.IOException
Returns the final response from the servlet. Note that this method should only be invoked after all processing has been done to the servlet response.

Specified by:
getServletResponse in interface InvocationContext

getFrame

public com.meterware.httpunit.FrameSelector getFrame()
Description copied from interface: InvocationContext
Returns the target frame for the original request.

Specified by:
getFrame in interface InvocationContext

pushIncludeRequest

public void pushIncludeRequest(javax.servlet.RequestDispatcher rd,
                               javax.servlet.http.HttpServletRequest request,
                               javax.servlet.http.HttpServletResponse response)
                        throws javax.servlet.ServletException
Description copied from interface: InvocationContext
Adds a request dispatcher to this context to simulate an include request.

Specified by:
pushIncludeRequest in interface InvocationContext

pushForwardRequest

public void pushForwardRequest(javax.servlet.RequestDispatcher rd,
                               javax.servlet.http.HttpServletRequest request,
                               javax.servlet.http.HttpServletResponse response)
                        throws javax.servlet.ServletException
Description copied from interface: InvocationContext
Adds a request dispatcher to this context to simulate a forward request.

Specified by:
pushForwardRequest in interface InvocationContext

popRequest

public void popRequest()
Description copied from interface: InvocationContext
Removes the top request dispatcher or filter from this context.

Specified by:
popRequest in interface InvocationContext

isFilterActive

public boolean isFilterActive()
Description copied from interface: InvocationContext
Returns true if the current context is a filter, rather than a servlet.

Specified by:
isFilterActive in interface InvocationContext

getFilter

public javax.servlet.Filter getFilter()
                               throws javax.servlet.ServletException
Description copied from interface: InvocationContext
Returns the current active filter object. Only valid to call if InvocationContext.isFilterActive() 55 returns true.

Specified by:
getFilter in interface InvocationContext

getFilterChain

public javax.servlet.FilterChain getFilterChain()
Description copied from interface: InvocationContext
Returns the current filter chain. Only valid to call if InvocationContext.isFilterActive() 55 returns true.

Specified by:
getFilterChain in interface InvocationContext

pushFilter

public void pushFilter(javax.servlet.ServletRequest request,
                       javax.servlet.ServletResponse response)
Description copied from interface: InvocationContext
Pushes the current filter onto the execution stack and switches to the next filter or the selected servlet. This can be used to simulate the effect of the doFilter 55 call.
Note: this method specifies javax.servlet.ServletRequest and javax.servlet.ServletResponse because those are the types passed to Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)>Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) 55 ; however, HttpUnit requires the objects to implement javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse because they will eventually be passed to an javax.servlet.http.HttpServlet.

Specified by:
pushFilter in interface InvocationContext

computeEffectiveUrl

private java.net.URL computeEffectiveUrl(javax.servlet.http.HttpServletRequest request,
                                         java.net.URL requestURL)

userIsAuthorized

private boolean userIsAuthorized(javax.servlet.http.HttpServletRequest request,
                                 java.net.URL requestURL)

getContext

private InvocationContextImpl.ExecutionContext getContext()