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

AbstractAccountHandler

public abstract class AbstractAccountHandler extends RequestAuthenticator implements GDataRequestHandler
author
Simon Willnauer

Fields Summary
private static final Log
LOG
private boolean
authenticated
private int
error
private String
errorMessage
private boolean
isError
protected org.apache.lucene.gdata.server.administration.AdminService
service
Constructors Summary
Methods Summary
protected org.apache.lucene.gdata.data.GDataAccountgetAccountFromRequest(javax.servlet.http.HttpServletRequest request)

        try {
            GDataAccount account = AccountBuilder.buildAccount(request
                    .getReader());
            if (account == null) {
                setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "");
                throw new AccountHandlerException(
                        "unexpected value -- parsed account is null");
            }
            return account;
        } catch (IOException e) {
            setError(HttpServletResponse.SC_BAD_REQUEST, "can not read input");
            throw new AccountHandlerException("Can't read from request reader",
                    e);
        } catch (SAXException e) {
            setError(HttpServletResponse.SC_BAD_REQUEST,
                    "can not parse gdata account");
            throw new AccountHandlerException(
                    "Can not parse incoming gdata account", 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)

      try{  
            this.authenticated = authenticateAccount(request,
                AccountRole.USERADMINISTRATOR);
        
        if (this.authenticated) {
            GDataServerRegistry registry = GDataServerRegistry.getRegistry();
            ServiceFactory factory = registry.lookup(ServiceFactory.class,
                    ComponentType.SERVICEFACTORY);
            try {

                GDataAccount account = getAccountFromRequest(request);
                if (!account.requiredValuesSet()) {
                    setError(GDataResponse.SERVER_ERROR,
                            "Required server component not available");
                    throw new AccountHandlerException(
                            "Required values are not set -- account can not be saved -- "
                                    + account);
                }
                this.service = factory.getAdminService();
                processServiceAction(account);
            } catch (ServiceException e) {
                LOG.error("Can't process account action -- " + e.getMessage(),
                        e);
                setError(e.getErrorCode(), "");
            } 
            catch (AccountHandlerException e) {
                LOG.error("Can't process account action -- " + e.getMessage(),
                        e);
            }
        }else{
            setError(GDataResponse.UNAUTHORIZED,"Authorization failed");
        }
        sendResponse(response);
      }finally{
          if(this.service!=null)
              this.service.close();
      }

    
protected abstract voidprocessServiceAction(org.apache.lucene.gdata.data.GDataAccount account)

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;