Example usage for org.apache.commons.logging Log info

List of usage examples for org.apache.commons.logging Log info

Introduction

In this page you can find the example usage for org.apache.commons.logging Log info.

Prototype

void info(Object message);

Source Link

Document

Logs a message with info log level.

Usage

From source file:org.apache.ftpserver.command.PASS.java

/**
 * Execute command.//w w w .  j a  v  a  2  s  . com
 */
public void execute(RequestHandler handler, FtpRequestImpl request, FtpWriter out)
        throws IOException, FtpException {

    boolean bSuccess = false;
    IFtpConfig fconfig = handler.getConfig();
    Log log = fconfig.getLogFactory().getInstance(getClass());
    IConnectionManager conManager = fconfig.getConnectionManager();
    IFtpStatistics stat = (IFtpStatistics) fconfig.getFtpStatistics();
    try {

        // reset state variables
        request.resetState();

        // argument check
        String password = request.getArgument();
        if (password == null) {
            out.send(501, "PASS", null);
            return;
        }

        // check user name
        User user = request.getUser();
        String userName = user.getName();
        if (userName == null) {
            out.send(503, "PASS", null);
            return;
        }

        // already logged-in
        if (request.isLoggedIn()) {
            out.send(202, "PASS", null);
            bSuccess = true;
            return;
        }

        // anonymous login limit check
        boolean bAnonymous = userName.equals("anonymous");
        int currAnonLogin = stat.getCurrentAnonymousLoginNumber();
        int maxAnonLogin = conManager.getMaxAnonymousLogins();
        if (bAnonymous && (currAnonLogin >= maxAnonLogin)) {
            out.send(421, "PASS.anonymous", null);
            return;
        }

        // login limit check
        int currLogin = stat.getCurrentLoginNumber();
        int maxLogin = conManager.getMaxLogins();
        if (currLogin >= maxLogin) {
            out.send(421, "PASS.login", null);
            return;
        }

        // authenticate user
        UserManager userManager = fconfig.getUserManager();
        try {
            if (bAnonymous) {
                bSuccess = userManager.doesExist("anonymous");
            } else {
                bSuccess = userManager.authenticate(userName, password);
            }
        } catch (Exception ex) {
            bSuccess = false;
            log.warn("PASS.execute()", ex);
        }
        if (!bSuccess) {
            log.warn("Login failure - " + userName);
            out.send(530, "PASS", userName);
            return;
        }

        // populate user information
        try {
            populateUser(handler, userName);
        } catch (FtpException ex) {
            bSuccess = false;
        }
        if (!bSuccess) {
            out.send(530, "PASS", userName);
            return;
        }

        // everything is fine - send login ok message
        out.send(230, "PASS", userName);
        if (bAnonymous) {
            log.info("Anonymous login success - " + password);
        } else {
            log.info("Login success - " + userName);
        }

        // update different objects
        FileSystemManager fmanager = fconfig.getFileSystemManager();
        FileSystemView fsview = fmanager.createFileSystemView(user);
        handler.setDirectoryLister(new DirectoryLister(fsview));
        request.setLogin(fsview);
        stat.setLogin(handler);

        // call Ftplet.onLogin() method
        Ftplet ftpletContainer = fconfig.getFtpletContainer();
        FtpletEnum ftpletRet = ftpletContainer.onLogin(request, out);
        if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
            fconfig.getConnectionManager().closeConnection(handler);
            return;
        }
    } finally {

        // if login failed - close connection
        if (!bSuccess) {
            conManager.closeConnection(handler);
        }
    }
}

From source file:org.apache.ftpserver.command.RETR.java

/**
 * Execute command.//w  w  w .  j  a v a2s . co m
 */
public void execute(RequestHandler handler, FtpRequestImpl request, FtpWriter out)
        throws IOException, FtpException {

    try {

        // get state variable
        long skipLen = request.getFileOffset();
        IFtpConfig fconfig = handler.getConfig();

        // argument check
        String fileName = request.getArgument();
        if (fileName == null) {
            out.send(501, "RETR", null);
            return;
        }

        // call Ftplet.onDownloadStart() method
        Ftplet ftpletContainer = fconfig.getFtpletContainer();
        FtpletEnum ftpletRet = ftpletContainer.onDownloadStart(request, out);
        if (ftpletRet == FtpletEnum.RET_SKIP) {
            return;
        } else if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
            fconfig.getConnectionManager().closeConnection(handler);
            return;
        }

        // get file object
        FileObject file = null;
        try {
            file = request.getFileSystemView().getFileObject(fileName);
        } catch (Exception ex) {
        }
        if (file == null) {
            out.send(550, "RETR.missing", fileName);
            return;
        }
        fileName = file.getFullName();

        // check file existance
        if (!file.doesExist()) {
            out.send(550, "RETR.missing", fileName);
            return;
        }

        // check valid file
        if (!file.isFile()) {
            out.send(550, "RETR.invalid", fileName);
            return;
        }

        // check permission
        if (!file.hasReadPermission()) {
            out.send(550, "RETR.permission", fileName);
            return;
        }

        // get data connection
        out.send(150, "RETR", null);
        OutputStream os = null;
        try {
            os = request.getDataOutputStream();
        } catch (IOException ex) {
            out.send(425, "RETR", null);
            return;
        }

        // send file data to client
        boolean failure = false;
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {

            // open streams
            bis = IoUtils.getBufferedInputStream(openInputStream(handler, file, skipLen));
            bos = IoUtils.getBufferedOutputStream(os);

            // transfer data
            int maxRate = handler.getRequest().getUser().getMaxDownloadRate();
            long transSz = handler.transfer(bis, bos, maxRate);

            // log message
            String userName = request.getUser().getName();
            Log log = fconfig.getLogFactory().getInstance(getClass());
            log.info("File download : " + userName + " - " + fileName);

            // notify the statistics component
            IFtpStatistics ftpStat = (IFtpStatistics) fconfig.getFtpStatistics();
            ftpStat.setDownload(handler, file, transSz);
        } catch (SocketException ex) {
            failure = true;
            out.send(426, "RETR", fileName);
        } catch (IOException ex) {
            failure = true;
            out.send(551, "RETR", fileName);
        } finally {
            IoUtils.close(bis);
            IoUtils.close(bos);
        }

        // if data transfer ok - send transfer complete message
        if (!failure) {
            out.send(226, "RETR", fileName);

            // call Ftplet.onDownloadEnd() method
            ftpletRet = ftpletContainer.onDownloadEnd(request, out);
            if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
                fconfig.getConnectionManager().closeConnection(handler);
                return;
            }
        }
    } finally {
        request.resetState();
        request.getFtpDataConnection().closeDataSocket();
    }
}

From source file:org.apache.ftpserver.command.RMD.java

/**
 * Execute command./*from   w w  w .ja v a  2s.  c  o m*/
 */
public void execute(RequestHandler handler, FtpRequestImpl request, FtpWriter out)
        throws IOException, FtpException {

    // reset state variables
    request.resetState();
    IFtpConfig fconfig = handler.getConfig();

    // argument check
    String fileName = request.getArgument();
    if (fileName == null) {
        out.send(501, "RMD", null);
        return;
    }

    // call Ftplet.onRmdirStart() method
    Ftplet ftpletContainer = fconfig.getFtpletContainer();
    FtpletEnum ftpletRet = ftpletContainer.onRmdirStart(request, out);
    if (ftpletRet == FtpletEnum.RET_SKIP) {
        return;
    } else if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
        fconfig.getConnectionManager().closeConnection(handler);
        return;
    }

    // get file object
    FileObject file = null;
    try {
        file = request.getFileSystemView().getFileObject(fileName);
    } catch (Exception ex) {
    }
    if (file == null) {
        out.send(550, "RMD.permission", fileName);
        return;
    }

    // check permission
    fileName = file.getFullName();
    if (!file.hasDeletePermission()) {
        out.send(550, "RMD.permission", fileName);
        return;
    }

    // check file
    if (!file.isDirectory()) {
        out.send(550, "RMD.invalid", fileName);
        return;
    }

    // now delete directory
    if (file.delete()) {
        out.send(250, "RMD", fileName);

        // write log message
        String userName = request.getUser().getName();
        Log log = fconfig.getLogFactory().getInstance(getClass());
        log.info("Directory remove : " + userName + " - " + fileName);

        // notify statistics object
        IFtpStatistics ftpStat = (IFtpStatistics) fconfig.getFtpStatistics();
        ftpStat.setRmdir(handler, file);

        // call Ftplet.onRmdirEnd() method
        ftpletRet = ftpletContainer.onRmdirEnd(request, out);
        if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
            fconfig.getConnectionManager().closeConnection(handler);
            return;
        }
    } else {
        out.send(450, "RMD", fileName);
    }
}

From source file:org.apache.ftpserver.command.RNTO.java

/**
 * Execute command./*from w w  w .  j  a v a  2 s.c o  m*/
 */
public void execute(RequestHandler handler, FtpRequestImpl request, FtpWriter out)
        throws IOException, FtpException {
    try {

        // argument check
        String toFileStr = request.getArgument();
        if (toFileStr == null) {
            out.send(501, "RNTO", null);
            return;
        }

        // call Ftplet.onRenameStart() method
        IFtpConfig fconfig = handler.getConfig();
        Ftplet ftpletContainer = fconfig.getFtpletContainer();
        FtpletEnum ftpletRet = ftpletContainer.onRenameStart(request, out);
        if (ftpletRet == FtpletEnum.RET_SKIP) {
            return;
        } else if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
            fconfig.getConnectionManager().closeConnection(handler);
            return;
        }

        // get the "rename from" file object
        FileObject frFile = request.getRenameFrom();
        if (frFile == null) {
            out.send(503, "RNTO", null);
            return;
        }

        // get target file
        FileObject toFile = null;
        try {
            toFile = request.getFileSystemView().getFileObject(toFileStr);
        } catch (Exception ex) {
        }
        if (toFile == null) {
            out.send(553, "RNTO.invalid", null);
            return;
        }
        toFileStr = toFile.getFullName();

        // check permission
        if (!toFile.hasWritePermission()) {
            out.send(553, "RNTO.permission", null);
            return;
        }

        // check file existance
        if (!frFile.doesExist()) {
            out.send(553, "RNTO.missing", null);
            return;
        }

        // now rename
        if (frFile.move(toFile)) {
            Log log = fconfig.getLogFactory().getInstance(getClass());
            log.info("File rename (" + request.getUser().getName() + ") " + frFile.getFullName() + " -> "
                    + toFile.getFullName());
            out.send(250, "RNTO", toFileStr);

            // call Ftplet.onRenameEnd() method
            ftpletRet = ftpletContainer.onRenameEnd(request, out);
            if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
                fconfig.getConnectionManager().closeConnection(handler);
                return;
            }
        } else {
            out.send(553, "RNTO", toFileStr);
        }

    } finally {
        request.resetState();
    }
}

From source file:org.apache.ftpserver.command.STOR.java

/**
 * Execute command.//from   w ww  .j  a  v a 2  s .c o  m
 */
public void execute(RequestHandler handler, FtpRequestImpl request, FtpWriter out)
        throws IOException, FtpException {

    try {

        // get state variable
        long skipLen = request.getFileOffset();
        IFtpConfig fconfig = handler.getConfig();

        // argument check
        String fileName = request.getArgument();
        if (fileName == null) {
            out.send(501, "STOR", null);
            return;
        }

        // call Ftplet.onUploadStart() method
        Ftplet ftpletContainer = fconfig.getFtpletContainer();
        FtpletEnum ftpletRet = ftpletContainer.onUploadStart(request, out);
        if (ftpletRet == FtpletEnum.RET_SKIP) {
            return;
        } else if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
            fconfig.getConnectionManager().closeConnection(handler);
            return;
        }

        // get filename
        FileObject file = null;
        try {
            file = request.getFileSystemView().getFileObject(fileName);
        } catch (Exception ex) {
        }
        if (file == null) {
            out.send(550, "STOR.invalid", fileName);
            return;
        }
        fileName = file.getFullName();

        // get permission
        if (!file.hasWritePermission()) {
            out.send(550, "STOR.permission", fileName);
            return;
        }

        // get data connection
        out.send(150, "STOR", fileName);
        InputStream is = null;
        try {
            is = request.getDataInputStream();
        } catch (IOException ex) {
            out.send(425, "STOR", fileName);
            return;
        }

        // get data from client
        boolean failure = false;
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {

            // open streams
            bis = IoUtils.getBufferedInputStream(is);
            bos = IoUtils.getBufferedOutputStream(file.createOutputStream(skipLen));

            // transfer data
            int maxRate = handler.getRequest().getUser().getMaxUploadRate();
            long transSz = handler.transfer(bis, bos, maxRate);

            // log message
            String userName = request.getUser().getName();
            Log log = fconfig.getLogFactory().getInstance(getClass());
            log.info("File upload : " + userName + " - " + fileName);

            // notify the statistics component
            IFtpStatistics ftpStat = (IFtpStatistics) fconfig.getFtpStatistics();
            ftpStat.setUpload(handler, file, transSz);
        } catch (SocketException ex) {
            failure = true;
            out.send(426, "STOR", fileName);
        } catch (IOException ex) {
            failure = true;
            out.send(551, "STOR", fileName);
        } finally {
            IoUtils.close(bis);
            IoUtils.close(bos);
        }

        // if data transfer ok - send transfer complete message
        if (!failure) {
            out.send(226, "STOR", fileName);

            // call Ftplet.onUploadEnd() method
            ftpletRet = ftpletContainer.onUploadEnd(request, out);
            if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
                fconfig.getConnectionManager().closeConnection(handler);
                return;
            }
        }
    } finally {
        request.resetState();
        request.getFtpDataConnection().closeDataSocket();
    }
}

From source file:org.apache.ftpserver.command.STOU.java

/**
 * Execute command./*from w w w. ja  v  a 2  s.co  m*/
 */
public void execute(RequestHandler handler, FtpRequestImpl request, FtpWriter out)
        throws IOException, FtpException {

    try {

        // reset state variables
        request.resetState();
        IFtpConfig fconfig = handler.getConfig();

        // call Ftplet.onUploadUniqueStart() method
        Ftplet ftpletContainer = fconfig.getFtpletContainer();
        FtpletEnum ftpletRet = ftpletContainer.onUploadUniqueStart(request, out);
        if (ftpletRet == FtpletEnum.RET_SKIP) {
            return;
        } else if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
            fconfig.getConnectionManager().closeConnection(handler);
            return;
        }

        // get filenames
        FileObject file = null;
        try {
            file = request.getFileSystemView().getFileObject("ftp.dat");
            file = getUniqueFile(handler, file);
        } catch (Exception ex) {
        }
        if (file == null) {
            out.send(550, "STOU", null);
            return;
        }
        String fileName = file.getFullName();

        // check permission
        if (!file.hasWritePermission()) {
            out.send(550, "STOU.permission", fileName);
            return;
        }

        // get data connection
        out.send(150, "STOU", null);
        InputStream is = null;
        try {
            is = request.getDataInputStream();
        } catch (IOException ex) {
            out.send(425, "STOU", fileName);
            return;
        }

        // get data from client
        boolean failure = false;
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        out.send(250, "STOU", fileName);
        try {

            // open streams
            bis = IoUtils.getBufferedInputStream(is);
            bos = IoUtils.getBufferedOutputStream(file.createOutputStream(false));

            // transfer data
            int maxRate = handler.getRequest().getUser().getMaxUploadRate();
            long transSz = handler.transfer(bis, bos, maxRate);

            // log message
            String userName = request.getUser().getName();
            Log log = fconfig.getLogFactory().getInstance(getClass());
            log.info("File upload : " + userName + " - " + fileName);

            // notify the statistics component
            IFtpStatistics ftpStat = (IFtpStatistics) fconfig.getFtpStatistics();
            ftpStat.setUpload(handler, file, transSz);
        } catch (SocketException ex) {
            failure = true;
            out.send(426, "STOU", fileName);
        } catch (IOException ex) {
            failure = true;
            out.send(551, "STOU", fileName);
        } finally {
            IoUtils.close(bis);
            IoUtils.close(bos);
        }

        // if data transfer ok - send transfer complete message
        if (!failure) {
            out.send(226, "STOU", fileName);

            // call Ftplet.onUploadUniqueEnd() method
            ftpletRet = ftpletContainer.onUploadUniqueEnd(request, out);
            if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
                fconfig.getConnectionManager().closeConnection(handler);
                return;
            }
        }
    } finally {
        request.getFtpDataConnection().closeDataSocket();
    }

}

From source file:org.apache.hadoop.hbase.avro.AvroServer.java

protected static void doMain(final String[] args) throws Exception {
    if (args.length < 1) {
        printUsageAndExit();//  w  w  w  . j  a  va2 s .  com
    }
    int port = 9090;
    final String portArgKey = "--port=";
    for (String cmd : args) {
        if (cmd.startsWith(portArgKey)) {
            port = Integer.parseInt(cmd.substring(portArgKey.length()));
            continue;
        } else if (cmd.equals("--help") || cmd.equals("-h")) {
            printUsageAndExit();
        } else if (cmd.equals("start")) {
            continue;
        } else if (cmd.equals("stop")) {
            printUsageAndExit("To shutdown the Avro server run "
                    + "bin/hbase-daemon.sh stop avro or send a kill signal to " + "the Avro server pid");
        }

        // Print out usage if we get to here.
        printUsageAndExit();
    }
    Log LOG = LogFactory.getLog("AvroServer");
    LOG.info("starting HBase Avro server on port " + Integer.toString(port));
    SpecificResponder r = new SpecificResponder(HBase.class, new HBaseImpl());
    HttpServer server = new HttpServer(r, port);
    server.start();
    server.join();
}

From source file:org.apache.hadoop.hbase.client.ConnectionUtils.java

/**
 * Changes the configuration to set the number of retries needed when using HConnection
 * internally, e.g. for  updating catalog tables, etc.
 * Call this method before we create any Connections.
 * @param c The Configuration instance to set the retries into.
 * @param log Used to log what we set in here.
 *///from w  w  w .j  av a  2s .  c  o m
public static void setServerSideHConnectionRetriesConfig(final Configuration c, final String sn,
        final Log log) {
    int hcRetries = c.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
            HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
    // Go big.  Multiply by 10.  If we can't get to meta after this many retries
    // then something seriously wrong.
    int serversideMultiplier = c.getInt("hbase.client.serverside.retries.multiplier", 10);
    int retries = hcRetries * serversideMultiplier;
    c.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, retries);
    log.info(sn + " server-side HConnection retries=" + retries);
}

From source file:org.apache.hadoop.hbase.util.ReflectionUtils.java

/**
 * Log the current thread stacks at INFO level.
 * @param log the logger that logs the stack trace
 * @param title a descriptive title for the call stacks
 * @param minInterval the minimum time from the last
 *//*www  .j av a2s  .  c  om*/
public static void logThreadInfo(Log log, String title, long minInterval) {
    boolean dumpStack = false;
    if (log.isInfoEnabled()) {
        synchronized (ReflectionUtils.class) {
            long now = System.currentTimeMillis();
            if (now - previousLogTime >= minInterval * 1000) {
                previousLogTime = now;
                dumpStack = true;
            }
        }
        if (dumpStack) {
            try {
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title);
                log.info(buffer.toString(Charset.defaultCharset().name()));
            } catch (UnsupportedEncodingException ignored) {
                log.warn("Could not write thread info about '" + title + "' due to a string encoding issue.");
            }
        }
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil.java

public static void logStorageContents(Log LOG, NNStorage storage) {
    LOG.info("current storages and corresponding sizes:");
    for (StorageDirectory sd : storage.dirIterable(null)) {
        File curDir = sd.getCurrentDir();
        LOG.info("In directory " + curDir);
        File[] files = curDir.listFiles();
        Arrays.sort(files);//ww w . j  a  v a 2  s.com
        for (File f : files) {
            LOG.info("  file " + f.getAbsolutePath() + "; len = " + f.length());
        }
    }
}