FileDocCategorySizeDatePackage
GDataResponse.javaAPI DocApache Lucene 2.1.016455Wed Feb 14 10:46:06 GMT 2007org.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 {@link HttpServletResponse}. Any action which has to be performed on the underlying {@link 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 {@link GDataResponse} class provides the overloaded method {@link 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

Fields Summary
public static final int
BAD_REQUEST
Response code bad request
public static final int
CONFLICT
Response code version conflict
public static final int
FORBIDDEN
Response code forbidden access
public static final int
SERVER_ERROR
Response code internal server error
public static final int
NOT_FOUND
Response code not found
public static final int
NOT_MODIFIED
Response code not modified since
public static final int
CREATED
Response code created
public static final int
UNAUTHORIZED
Response code unauthorized access
static final Log
LOG
private int
error
private boolean
isError
private String
encoding
private org.apache.lucene.gdata.server.GDataRequest.OutputFormat
outputFormat
private final HttpServletResponse
response
protected static final String
XMLMIME_ATOM
protected static final String
XMLMIME_RSS
private static final String
HEADER_LASTMODIFIED
Constructors Summary
public GDataResponse(HttpServletResponse response)
Creates a new GDataResponse

param
response - The underlying {@link HttpServletResponse}


                                
       
        if (response == null)
            throw new IllegalArgumentException("response must not be null");
        this.response = response;

    
Methods Summary
public java.lang.StringgetEncoding()
This encoding will be used to encode the xml representation of feed or entry written to the {@link HttpServletResponse} output stream.

return
- the entry / feed encoding

        return this.encoding;
    
public org.apache.lucene.gdata.server.GDataRequest.OutputFormatgetOutputFormat()

return
- the response {@link org.apache.lucene.gdata.server.GDataRequest.OutputFormat}

        return this.outputFormat;
    
public java.io.WritergetWriter()

return
- the {@link HttpServletResponse} writer
throws
IOException - If an I/O exception occurs

        return this.response.getWriter();
    
public voidsendError()
This method sends the specified error to the user if set

throws
IOException - if an I/O Exception occurs

        if (this.isError)
            this.response.sendError(this.error);
        
    
public voidsendResponse(com.google.gdata.data.BaseFeed feed, org.apache.lucene.gdata.server.registry.ProvidedService service)
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.

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

        if (feed == null)
            throw new IllegalArgumentException("feed must not be null");
        if (service == null)
            throw new IllegalArgumentException(
                    "provided service must not be null");
        DateTime time = feed.getUpdated();
        if (time != null)
            setLastModifiedHeader(time.getValue());
        FormatWriter writer = FormatWriter.getFormatWriter(this,service);
        writer.generateOutputFormat(feed,this.response);

    
public voidsendResponse(com.google.gdata.data.BaseEntry entry, org.apache.lucene.gdata.server.registry.ProvidedService service)
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.

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

        if (entry == null)
            throw new IllegalArgumentException("entry must not be null");
        if (service == null)
            throw new IllegalArgumentException(
                    "service must not be null");
        DateTime time = entry.getUpdated();
        if (time != null)
            setLastModifiedHeader(time.getValue());
        FormatWriter writer = FormatWriter.getFormatWriter(this,service);
        writer.generateOutputFormat(entry,this.response);

        
    
public voidsetEncoding(java.lang.String encoding)
This encoding will be used to encode the xml representation of feed or entry written to the {@link HttpServletResponse} output stream. UTF-8 ISO-8859-1

param
encoding - string represents the encoding

        this.encoding = encoding;
    
public voidsetError(int errorCode)
Sets an error code to this FeedResponse.

param
errorCode - {@link HttpServletResponse} error code

        this.isError = true;
        this.error = errorCode;
    
protected voidsetLastModifiedHeader(long lastModified)

        String lastMod = DateFormater.formatDate(new Date(lastModified),
                DateFormater.HTTP_HEADER_DATE_FORMAT);
        this.response.setHeader(HEADER_LASTMODIFIED, lastMod);
    
public voidsetOutputFormat(org.apache.lucene.gdata.server.GDataRequest.OutputFormat outputFormat)

param
outputFormat - the response {@link org.apache.lucene.gdata.server.GDataRequest.OutputFormat}

        this.outputFormat = outputFormat;
    
public voidsetResponseCode(int responseCode)
Sets the status of the underlying response

see
HttpServletResponse
param
responseCode - the status of the response

        this.response.setStatus(responseCode);
    
public voidsetStatus(int status)

see
HttpServletResponse#setStatus(int)
param
status - the request status code

        this.response.setStatus(status);
    
public java.lang.StringtoString()

see
Object#toString()

        StringBuilder builder = new StringBuilder(" GDataResponse: ");
        builder.append("Error: ").append(this.error);
        builder.append(" outputFormat: ").append(getOutputFormat());
        builder.append(" encoding: ").append(this.encoding);

        return builder.toString();