org.apache.anteater.test
Class SendResponse

java.lang.Object
  |
  +--org.apache.tools.ant.ProjectComponent
        |
        +--org.apache.tools.ant.Task
              |
              +--org.apache.anteater.test.BaseTask
                    |
                    +--org.apache.anteater.test.ContentHandlerTask
                          |
                          +--org.apache.anteater.test.SendResponse
All Implemented Interfaces:
ContentHandler, Groupable, ObjectModel, org.apache.tools.ant.TaskContainer

public class SendResponse
extends ContentHandlerTask
implements ObjectModel, ContentHandler

Sends an HTTP response back in the servlet thread.

This task looks in the object model for a stored HttpServletResponse and Writer, which it uses to write the response.

See here for a description of how this interacts with other classes.

Since:
October 1, 2001
Version:
$Revision: 1.12 $ $Date: 2003/01/18 01:54:18 $
Author:
Ovidiu Predescu, Jeff Turner

Field Summary
protected  String body
           
protected  String contentType
           
protected  List headers
           
protected  String href
           
protected  Map objectModel
           
protected  int responseCode
           
 
Fields inherited from class org.apache.anteater.test.ContentHandlerTask
handlerFactory, matcherTests
 
Fields inherited from class org.apache.anteater.test.BaseTask
debug, debugWasSet
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Fields inherited from interface org.apache.anteater.test.ObjectModel
NAMESPACES_KEY, PROPERTIES_KEY
 
Constructor Summary
SendResponse()
           
 
Method Summary
 void addText(String text)
          Sets the body text.
 void execute()
          Retrieves the HttpServletResponse and Writer, and uses the contents of the file specified by setHref(java.lang.String) to write a response.
 String getContent(Object obj)
          Handle body tasks through the ContentHandler interface.
 String[] getHandledTypes()
          Specify the body tasks we are able to handle.
 String getHref()
           
 String getText()
          Retrieves the body text.
 void init()
           
 void setContentType(String contentType)
          Set MIME content type to label body contents as.
 void setHref(String href)
          Set the path of the file whose contents will constitute the HTTP body returned to the caller.
 void setObjectModel(Map objectModel)
          Set the context in the receiving object.
 void setResponseCode(int code)
          Set the HTTP response code to send to the client.
 void writeTo(javax.servlet.http.HttpServletResponse response, Writer responseWriter)
          Sends a response back to the HTTP client.
 
Methods inherited from class org.apache.anteater.test.ContentHandlerTask
addTask
 
Methods inherited from class org.apache.anteater.test.BaseTask
debug, getDebug, getGroup, print, println, resolveContentURL, setDebug, setGroup, setGroup
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorOutput, handleOutput, isInvalid, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

body

protected String body

href

protected String href

contentType

protected String contentType

responseCode

protected int responseCode

headers

protected List headers

objectModel

protected Map objectModel
Constructor Detail

SendResponse

public SendResponse()
Method Detail

init

public void init()
Overrides:
init in class org.apache.tools.ant.Task

getHandledTypes

public String[] getHandledTypes()
Specify the body tasks we are able to handle.

Specified by:
getHandledTypes in interface ContentHandler

getContent

public String getContent(Object obj)
                  throws Exception
Handle body tasks through the ContentHandler interface. We can't use the normal addConfiguredXxx methods because we want to maintain backwards-compat with the 0.9.11 ability to define the HTTP body as nested text.

Specified by:
getContent in interface ContentHandler
Parameters:
obj - An object that the ContentHandler implementation knows how to process. Typically an Ant task.
Returns:
A String representation of the result of processing the object. Can be null, which represents 'no content'.
Exception

setHref

public void setHref(String href)
Set the path of the file whose contents will constitute the HTTP body returned to the caller.

Parameters:
href - Path to a file

getHref

public String getHref()

addText

public void addText(String text)
             throws org.apache.tools.ant.BuildException
Sets the body text.

Specified by:
addText in class ContentHandlerTask
org.apache.tools.ant.BuildException

getText

public String getText()
               throws org.apache.tools.ant.BuildException
Retrieves the body text.

org.apache.tools.ant.BuildException

setContentType

public void setContentType(String contentType)
Set MIME content type to label body contents as.

Parameters:
contentType - MIME type, eg text/html or text/plain.

setResponseCode

public void setResponseCode(int code)
                     throws org.apache.tools.ant.BuildException
Set the HTTP response code to send to the client.

Parameters:
code - HTTP response code, eg 200 (OK), 400 (Bad request), 404 (Not Found).
org.apache.tools.ant.BuildException

setObjectModel

public void setObjectModel(Map objectModel)
Description copied from interface: ObjectModel
Set the context in the receiving object.

Specified by:
setObjectModel in interface ObjectModel
Parameters:
objectModel - a HashMap value

writeTo

public void writeTo(javax.servlet.http.HttpServletResponse response,
                    Writer responseWriter)
             throws IOException,
                    org.apache.tools.ant.BuildException
Sends a response back to the HTTP client.

Parameters:
response - The HttpServletResponse set by the servlet. This will have it's content type and status set.
responseWriter - a Writer, which will send bytes through an inter-thread pipe to the servlet, and then on to the client as the response body.
IOException
org.apache.tools.ant.BuildException

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Retrieves the HttpServletResponse and Writer, and uses the contents of the file specified by setHref(java.lang.String) to write a response.

Overrides:
execute in class ContentHandlerTask
org.apache.tools.ant.BuildException


Ant Functional Tester -- see Project home page for details