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

AbstractFeedHandler

public abstract class AbstractFeedHandler extends RequestAuthenticator implements GDataRequestHandler
author
Simon Willnauer

Fields Summary
private static final Log
LOG
protected static final String
PARAMETER_ACCOUNT
protected static final String
PARAMETER_SERVICE
private int
error
protected boolean
authenticated
private String
errorMessage
private boolean
isError
Constructors Summary
Methods Summary
protected org.apache.lucene.gdata.data.ServerBaseFeedcreateFeedFromRequest(javax.servlet.http.HttpServletRequest request)

        GDataServerRegistry registry = GDataServerRegistry.getRegistry();
        String providedService = request.getParameter(PARAMETER_SERVICE);
        if(!registry.isServiceRegistered(providedService)){
            setError(GDataResponse.NOT_FOUND,"no such service");
            throw new FeedHandlerException("ProvicdedService is not registered -- Name: "+providedService);
         }
        ProvidedService provServiceInstance = registry.getProvidedService(providedService);  
        if(providedService == null){
            setError(GDataResponse.BAD_REQUEST,"no such service");
            throw new FeedHandlerException("no such service registered -- "+providedService);
        }
        try{
            ServerBaseFeed retVal = new ServerBaseFeed(GDataEntityBuilder.buildFeed(request.getReader(),provServiceInstance));
            retVal.setServiceConfig(provServiceInstance);
        return retVal;
        }catch (IOException e) {
            if(LOG.isInfoEnabled())
                LOG.info("Can not read from input stream - ",e);
            setError(GDataResponse.BAD_REQUEST,"Can not read from input stream");
            throw e;
        }catch (ParseException e) {
            if(LOG.isInfoEnabled())
                LOG.info("feed can not be parsed - ",e);
            setError(GDataResponse.BAD_REQUEST,"incoming feed can not be parsed");
            throw e;
        }
        
    
protected org.apache.lucene.gdata.data.GDataAccountcreateRequestedAccount(javax.servlet.http.HttpServletRequest request)

        GDataServerRegistry registry = GDataServerRegistry.getRegistry();
           ServiceFactory serviceFactory = registry.lookup(ServiceFactory.class,ComponentType.SERVICEFACTORY);
        
        if(serviceFactory == null){
            setError(GDataResponse.SERVER_ERROR, "Required server component not available");
            throw new FeedHandlerException("Required server component not available -- "+ServiceFactory.class.getName());
        }
        AdminService service = serviceFactory.getAdminService();
        String account = request.getParameter(PARAMETER_ACCOUNT);
        try{
        return service.getAccount(account);
        }catch (ServiceException e) {
            if(LOG.isInfoEnabled())
                LOG.info("no account for requested account - "+account,e);
            setError(HttpServletResponse.SC_BAD_REQUEST,"no such account");
            throw new FeedHandlerException(e.getMessage(),e);
        }
    
protected intgetErrorCode()

        return this.error;
    
protected java.lang.StringgetErrorMessage()

        return this.errorMessage;
    
public voidprocessRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

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

            this.authenticated = authenticateAccount(request,AccountRole.FEEDAMINISTRATOR);
            if(!this.authenticated)
                setError(GDataResponse.UNAUTHORIZED,"Authorization failed");
        
    
protected voidsendResponse(javax.servlet.http.HttpServletResponse response)

        
        if(!this.isError)
            return;
        try{
        response.sendError(this.error,this.errorMessage);
        }catch (IOException e) {
            LOG.warn("can send error in RequestHandler ",e);
        }
    
protected voidsetError(int error, java.lang.String message)

        this.error = error;
        this.errorMessage = message;
        this.isError = true;