FileDocCategorySizeDatePackage
DefaultGetHandler.javaAPI DocApache Lucene 2.1.05761Wed Feb 14 10:46:04 GMT 2007org.apache.lucene.gdata.servlet.handler

DefaultGetHandler

public class DefaultGetHandler extends AbstractGdataRequestHandler
Default Handler implementation. This handler processes the incoming {@link org.apache.lucene.gdata.server.GDataRequest} and retrieves the requested feed from the underlying storage.

This hander also processes search queries and retrieves the search hits from the underlying search component. The user query will be accessed via the {@link org.apache.lucene.gdata.server.GDataRequest} instance passed to the {@link Service} class.

The DefaultGetHandler supports HTTP Conditional GET. It set the Last-Modified response header based upon the value of the element in the returned feed or entry. A client can send this value back as the value of the 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
private static final Log
LOG
Constructors Summary
Methods Summary
protected booleancheckIsModified(java.lang.String lastModified)
returns true if the resource has been modified since the specified request header value

        if (lastModified == null)
            return true;
        try {
            Date clientDate = DateFormater.parseDate(lastModified,DateFormater.HTTP_HEADER_DATE_FORMAT,DateFormater.HTTP_HEADER_DATE_FORMAT_TIME_OFFSET);
            Date entityDate;
            if (this.feedRequest.isFeedRequested())
                entityDate = this.service.getFeedLastModified(this.feedRequest
                        .getFeedId());
            else
                entityDate = this.service.getEntryLastModified(this.feedRequest
                        .getEntryId(),this.feedRequest.getFeedId());
            if(LOG.isInfoEnabled())
                LOG.info("comparing date clientDate: "+clientDate+"; last modified: "+entityDate);
            return (entityDate.getTime()-clientDate.getTime() > 1000);
        } catch (java.text.ParseException e) {
            LOG.info("Couldn't parse Last-Modified header -- "+lastModified,e);

        }
        return true;
    
public voidprocessRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

see
org.apache.lucene.gdata.servlet.handler.AbstractGdataRequestHandler#processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)


                 
    
       
                 
        try {
            initializeRequestHandler(request, response, GDataRequestType.GET);
        } catch (GDataRequestException e) {
            sendError();
            return;
        }

        try {
            String modifiedSince = this.feedRequest.getModifiedSince();
            if (!checkIsModified(modifiedSince)) {
                this.feedResponse
                        .setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            }
            if (LOG.isInfoEnabled())
                LOG.info("Requested output formate: "
                        + this.feedRequest.getRequestedResponseFormat());
            this.feedResponse.setOutputFormat(this.feedRequest
                    .getRequestedResponseFormat());
            if (this.feedRequest.isFeedRequested()) {
                BaseFeed feed = this.service.getFeed(this.feedRequest,
                        this.feedResponse);

                this.feedResponse.sendResponse(feed, this.feedRequest
                        .getConfigurator());
            } else {
                BaseEntry entry = this.service.getSingleEntry(this.feedRequest,
                        this.feedResponse);
                this.feedResponse.sendResponse(entry, this.feedRequest
                        .getConfigurator());
            }

        } catch (ServiceException e) {
            LOG.error("Could not process GetFeed request - " + e.getMessage(),
                    e);
            setError(e.getErrorCode());
            sendError();
        }finally{
        closeService();
        }