org.apache.cocoon.servletservice
Class AbstractServletConnection

java.lang.Object
  extended by org.apache.cocoon.servletservice.AbstractServletConnection
All Implemented Interfaces:
ServletConnection
Direct Known Subclasses:
AbsoluteServletConnection, RelativeServletConnection

public abstract class AbstractServletConnection
extends Object
implements ServletConnection

Since:
1.0.0
Version:
$Id: AbstractServletConnection.html 1422810 2012-12-17 09:13:50Z ilgrosso $

Nested Class Summary
protected static class AbstractServletConnection.NoServletContextAvailableException
          A special exception indicating that there is no servlet context available.
 
Field Summary
protected  boolean connected
          If already connected
protected  javax.servlet.ServletContext context
          The current block context
protected  org.apache.commons.logging.Log logger
          By default we use the logger for this class.
protected  ServletServiceRequest request
          Connection request
protected  ByteArrayOutputStream requestBody
           
protected  ServletServiceResponse response
          Connection response
protected  InputStream responseBody
           
protected  URI uri
           
 
Constructor Summary
AbstractServletConnection()
           
 
Method Summary
 void connect()
          Connect to the servlet service.
 String getContentType()
          Get the mime-type of the servlet-service.
 long getDateHeader(String name, long defaultValue)
           
 String getHeaderField(String name)
          Get a response header with the given name.
 long getHeaderFieldDate(String name, long defaultValue)
           
 Map getHeaders()
          Get all response header fields.
 InputStream getInputStream()
          Return an InputStream object to read from the source.
 long getLastModified()
          Get the last modification date of the servlet service.
 OutputStream getOutputStream()
          Returns an output stream that writes as POST to this connection.
 int getResponseCode()
           
 URI getURI()
          Get a URI representing this servlet connection.
protected abstract  void performConnect()
          Access the servlet and fill the response object.
 void setIfModifiedSince(long ifmodifiedsince)
          Set the last modification date if you want to make use of caching.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
By default we use the logger for this class.


request

protected ServletServiceRequest request
Connection request


response

protected ServletServiceResponse response
Connection response


context

protected javax.servlet.ServletContext context
The current block context


connected

protected boolean connected
If already connected


requestBody

protected ByteArrayOutputStream requestBody

responseBody

protected InputStream responseBody

uri

protected URI uri
Constructor Detail

AbstractServletConnection

public AbstractServletConnection()
Method Detail

connect

public void connect()
             throws IOException,
                    javax.servlet.ServletException
Description copied from interface: ServletConnection
Connect to the servlet service. Establishing a connection means that the service is executed and the response is available.

Specified by:
connect in interface ServletConnection
Throws:
IOException - The connection to the servlet service can't be established.
javax.servlet.ServletException - Any other problem when connecting to a servlet service.

performConnect

protected abstract void performConnect()
                                throws javax.servlet.ServletException,
                                       IOException
Access the servlet and fill the response object.

Throws:
javax.servlet.ServletException
IOException

getInputStream

public InputStream getInputStream()
                           throws IOException,
                                  javax.servlet.ServletException
Return an InputStream object to read from the source.

Specified by:
getInputStream in interface ServletConnection
Returns:
An input stream on the servlet service response.
Throws:
IOException
javax.servlet.ServletException

setIfModifiedSince

public void setIfModifiedSince(long ifmodifiedsince)
Description copied from interface: ServletConnection
Set the last modification date if you want to make use of caching. This method has to be called before any of the other methods of this interface is invoked.

Specified by:
setIfModifiedSince in interface ServletConnection
Parameters:
ifmodifiedsince - The timestamp of the last known resource.

getLastModified

public long getLastModified()
Description copied from interface: ServletConnection
Get the last modification date of the servlet service.

Specified by:
getLastModified in interface ServletConnection
Returns:
The last modification date of the servlet service.

getContentType

public String getContentType()
Description copied from interface: ServletConnection
Get the mime-type of the servlet-service.

Specified by:
getContentType in interface ServletConnection
Returns:
The mime-type of the servlet-service.

getDateHeader

public long getDateHeader(String name,
                          long defaultValue)

getHeaderField

public String getHeaderField(String name)
Description copied from interface: ServletConnection
Get a response header with the given name.

Specified by:
getHeaderField in interface ServletConnection
Parameters:
name - The name of the header parameter
Returns:
The value of the header parameter

getHeaderFieldDate

public long getHeaderFieldDate(String name,
                               long defaultValue)

getHeaders

public Map getHeaders()
Description copied from interface: ServletConnection
Get all response header fields.

Specified by:
getHeaders in interface ServletConnection
Returns:
A Map that contains all response headers.

getResponseCode

public int getResponseCode()
                    throws IOException
Specified by:
getResponseCode in interface ServletConnection
Returns:
The HTTP status code returned by the servlet service.
Throws:
IOException

getOutputStream

public OutputStream getOutputStream()
                             throws IllegalStateException
Returns an output stream that writes as POST to this connection.

Specified by:
getOutputStream in interface ServletConnection
Returns:
an output stream that writes as POST to this connection.
Throws:
IllegalStateException - - if already connected

getURI

public URI getURI()
Description copied from interface: ServletConnection
Get a URI representing this servlet connection.

Specified by:
getURI in interface ServletConnection
Returns:
a URI representing this servlet connection.


Copyright © 1999-2012 The Apache Software Foundation. All Rights Reserved.