org.apache.lucene.gdata.server
Class GDataResponse

java.lang.Object
  extended by org.apache.lucene.gdata.server.GDataResponse

public class GDataResponse
extends Object

The FeedRequest Class wraps the current HttpServletResponse. Any action on the HttpServletRequest will be executed via this class. This represents an abstraction on the plain HttpServletResponse. Any action which has to be performed on the underlying HttpServletResponse will be executed within this class.

The GData basically writes two different kinds of response to the output stream.

  1. update, delete or insert requests will respond with a status code and if successful the feed entry modified or created
  2. get requests will respond with a status code and if successful the requested feed
For this purpose the GDataResponse class provides the overloaded method org.apache.lucene.gdata.server.GDataResponse#sendResponse(BaseEntry, ExtensionProfile) which sends the entry e.g feed to the output stream.

This class will set the HTTP Last-Modified Header to enable clients to send If-Modified-Since request header to avoid retrieving the content again if it hasn't changed. If the content hasn't changed since the If-Modified-Since time, then the GData service returns a 304 (Not Modified) HTTP response.

Author:
Simon Willnauer

Field Summary
static int BAD_REQUEST
          Response code bad request
static int CONFLICT
          Response code version conflict
static int CREATED
          Response code created
static int FORBIDDEN
          Response code forbidden access
static int NOT_FOUND
          Response code not found
static int NOT_MODIFIED
          Response code not modified since
static int SERVER_ERROR
          Response code internal server error
static int UNAUTHORIZED
          Response code unauthorized access
protected static String XMLMIME_ATOM
           
protected static String XMLMIME_RSS
           
 
Constructor Summary
GDataResponse(javax.servlet.http.HttpServletResponse response)
          Creates a new GDataResponse
 
Method Summary
 String getEncoding()
          This encoding will be used to encode the xml representation of feed or entry written to the HttpServletResponse output stream.
 GDataRequest.OutputFormat getOutputFormat()
           
 Writer getWriter()
           
 void sendError()
          This method sends the specified error to the user if set
 void sendResponse(com.google.gdata.data.BaseEntry entry, ProvidedService service)
          Sends a response for an update, insert or delete request.
 void sendResponse(com.google.gdata.data.BaseFeed feed, ProvidedService service)
          Sends a response for a get e.g.
 void setEncoding(String encoding)
          This encoding will be used to encode the xml representation of feed or entry written to the HttpServletResponse output stream.
 void setError(int errorCode)
          Sets an error code to this FeedResponse.
protected  void setLastModifiedHeader(long lastModified)
           
 void setOutputFormat(GDataRequest.OutputFormat outputFormat)
           
 void setResponseCode(int responseCode)
          Sets the status of the underlying response
 void setStatus(int status)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BAD_REQUEST

public static final int BAD_REQUEST
Response code bad request

See Also:
Constant Field Values

CONFLICT

public static final int CONFLICT
Response code version conflict

See Also:
Constant Field Values

FORBIDDEN

public static final int FORBIDDEN
Response code forbidden access

See Also:
Constant Field Values

SERVER_ERROR

public static final int SERVER_ERROR
Response code internal server error

See Also:
Constant Field Values

NOT_FOUND

public static final int NOT_FOUND
Response code not found

See Also:
Constant Field Values

NOT_MODIFIED

public static final int NOT_MODIFIED
Response code not modified since

See Also:
Constant Field Values

CREATED

public static final int CREATED
Response code created

See Also:
Constant Field Values

UNAUTHORIZED

public static final int UNAUTHORIZED
Response code unauthorized access

See Also:
Constant Field Values

XMLMIME_ATOM

protected static final String XMLMIME_ATOM
See Also:
Constant Field Values

XMLMIME_RSS

protected static final String XMLMIME_RSS
See Also:
Constant Field Values
Constructor Detail

GDataResponse

public GDataResponse(javax.servlet.http.HttpServletResponse response)
Creates a new GDataResponse

Parameters:
response - - The underlying HttpServletResponse
Method Detail

setError

public void setError(int errorCode)
Sets an error code to this FeedResponse.

Parameters:
errorCode - - HttpServletResponse error code

setResponseCode

public void setResponseCode(int responseCode)
Sets the status of the underlying response

Parameters:
responseCode - - the status of the response
See Also:
HttpServletResponse

sendError

public void sendError()
               throws IOException
This method sends the specified error to the user if set

Throws:
IOException - - if an I/O Exception occurs

getWriter

public Writer getWriter()
                 throws IOException
Returns:
- the HttpServletResponse writer
Throws:
IOException - - If an I/O exception occurs

sendResponse

public void sendResponse(com.google.gdata.data.BaseFeed feed,
                         ProvidedService service)
                  throws IOException
Sends a response for a get e.g. query request. This method must not invoked in a case of an error performing the requested action.

Parameters:
feed - - the feed to respond to the client
service - - the service to render the feed
Throws:
IOException - - if an I/O exception occurs, often caused by an already closed Writer or OutputStream

sendResponse

public void sendResponse(com.google.gdata.data.BaseEntry entry,
                         ProvidedService service)
                  throws IOException
Sends a response for an update, insert or delete request. This method must not invoked in a case of an error performing the requested action. If the specified response format is ATOM the default namespace will be set to ATOM.

Parameters:
entry - - the modified / created entry to send
service - - the service to render the feed
Throws:
IOException - - if an I/O exception occurs, often caused by an already closed Writer or OutputStream

getEncoding

public String getEncoding()
This encoding will be used to encode the xml representation of feed or entry written to the HttpServletResponse output stream.

Returns:
- the entry / feed encoding

setEncoding

public void setEncoding(String encoding)
This encoding will be used to encode the xml representation of feed or entry written to the HttpServletResponse output stream. UTF-8 ISO-8859-1

Parameters:
encoding - - string represents the encoding

getOutputFormat

public GDataRequest.OutputFormat getOutputFormat()
Returns:
- the response GDataRequest.OutputFormat

setOutputFormat

public void setOutputFormat(GDataRequest.OutputFormat outputFormat)
Parameters:
outputFormat - - the response GDataRequest.OutputFormat

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

setLastModifiedHeader

protected void setLastModifiedHeader(long lastModified)

setStatus

public void setStatus(int status)
Parameters:
status - - the request status code
See Also:
HttpServletResponse.setStatus(int)


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.