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

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

Introduction

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

Prototype

void error(Object message, Throwable t);

Source Link

Document

Logs an error with error log level.

Usage

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Releases the repository lock file.//from w w w  .j  a  v a  2 s.  c o m
 */
protected void releaseRepositoryFileLock(final RepositoryFileLock repositoryFileLock) {
    Log logger = this.getLog();

    if (logger.isDebugEnabled())
        logger.debug("Releasing repository file lock.");

    try {
        if (repositoryFileLock != null)
            repositoryFileLock.release();
        else if (logger.isDebugEnabled())
            logger.debug("Cannot release repository file lock - lock is null.");
    } catch (Exception e) {
        logger.error("Error releasing repository file lock!", e);
    }
}

From source file:es.logongas.ix3.web.util.ControllerHelper.java

public void exceptionToHttpResponse(Throwable throwable, HttpServletResponse httpServletResponse) {
    try {/*from  w ww .  j  a  va  2 s.c  o  m*/
        BusinessException businessException = ExceptionUtil.getBusinessExceptionFromThrowable(throwable);

        if (businessException != null) {

            if (businessException instanceof BusinessSecurityException) {
                BusinessSecurityException businessSecurityException = (BusinessSecurityException) businessException;
                Log log = LogFactory.getLog(ControllerHelper.class);
                log.info(businessSecurityException);

                httpServletResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
                httpServletResponse.setContentType("text/plain; charset=UTF-8");
                if (businessSecurityException.getBusinessMessages().size() > 0) {
                    httpServletResponse.getWriter()
                            .println(businessSecurityException.getBusinessMessages().get(0).getMessage());
                }
            } else if (businessException instanceof BusinessException) {

                httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                httpServletResponse.setContentType("application/json; charset=UTF-8");
                httpServletResponse.getWriter()
                        .println(jsonFactory.getJsonWriter().toJson(businessException.getBusinessMessages()));
            } else {
                Log log = LogFactory.getLog(ControllerHelper.class);
                log.error("Es un tipo de businessException desconocida:", businessException);

                httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                httpServletResponse.setContentType("text/plain");
                businessException.printStackTrace(httpServletResponse.getWriter());
            }

        } else {
            Log log = LogFactory.getLog(ControllerHelper.class);
            log.error("Fall la llamada al servidor:", throwable);

            httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            httpServletResponse.setContentType("text/plain");
            throwable.printStackTrace(httpServletResponse.getWriter());
        }
    } catch (IOException ioException) {
        Log log = LogFactory.getLog(ControllerHelper.class);
        log.error("Fall al devolver la excepcin por la HttpResponse:", ioException);
        log.error("Excepcion original:", throwable);
        httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }

}

From source file:name.livitski.tools.springlet.Launcher.java

/**
 * Configures the manager using command-line arguments.
 * The arguments are checked in their command line sequence.
 * If an argument begins with {@link Command#COMMAND_PREFIX},
 * its part that follows it is treated as a (long) command's name.
 * If an argument begins with {@link Command#SWITCH_PREFIX},
 * the following character(s) are treated as a switch.
 * The name or switch extracted this way, prepended with
 * a bean name prefix for a {@link #BEAN_NAME_PREFIX_COMMAND command}
 * or a {@link #BEAN_NAME_PREFIX_SWITCH switch}, becomes the name
 * of a bean to look up in the framework's
 * {@link #MAIN_BEAN_CONFIG_FILE configuration file(s)}.
 * The bean that handles a command must extend the
 * {@link Command} class. Once a suitable bean is found,
 * it is called to act upon the command or switch and process
 * any additional arguments associated with it. 
 * If no bean can be found or the argument is not prefixed
 * properly, it is considered unclaimed. You may configure a
 * special subclass of {@link Command} to process such arguments
 * by placing a bean named {@link #BEAN_NAME_DEFAULT_HANDLER} on
 * the configuration. If there is no such bean configured, or when
 * any {@link Command} bean throws an exception while processing
 * a command, a command line error is reported and the application
 * quits./*from  w ww . ja va2 s .  c  o  m*/
 * @param args the command line
 * @return this manager object
 */
public Launcher withArguments(String[] args) {
    configureDefaultLogging();
    final Log log = log();
    ListIterator<String> iargs = Arrays.asList(args).listIterator();
    while (iargs.hasNext()) {
        String arg = iargs.next();
        String prefix = null;
        String beanPrefix = null;
        Command cmd = null;
        if (arg.startsWith(Command.COMMAND_PREFIX))
            prefix = Command.COMMAND_PREFIX;
        else if (arg.startsWith(Command.SWITCH_PREFIX))
            prefix = Command.SWITCH_PREFIX;
        if (null != prefix) {
            arg = arg.substring(prefix.length());
            beanPrefix = Command.SWITCH_PREFIX == prefix ? BEAN_NAME_PREFIX_SWITCH : BEAN_NAME_PREFIX_COMMAND;
            try {
                cmd = getBeanFactory().getBean(beanPrefix + arg, Command.class);
            } catch (NoSuchBeanDefinitionException noBean) {
                log.debug("Could not find a handler for command-line argument " + prefix + arg, noBean);
            }
        }
        if (null == cmd) {
            iargs.previous();
            try {
                cmd = getBeanFactory().getBean(BEAN_NAME_DEFAULT_HANDLER, Command.class);
            } catch (RuntimeException ex) {
                log.error("Unknown command line argument: " + (null != prefix ? prefix : "") + arg, ex);
                status = STATUS_COMMAND_PARSING_FAILURE;
                break;
            }
        }
        try {
            cmd.process(iargs);
        } catch (SkipApplicationRunRequest skip) {
            if (log.isTraceEnabled())
                log.trace("Handler for argument " + (null != prefix ? prefix : "") + arg
                        + " requested to skip the application run", skip);
            status = STATUS_RUN_SKIPPED;
            break;
        } catch (RuntimeException err) {
            log.error("Invalid command line argument(s) near " + (null != prefix ? prefix : "") + arg + ": "
                    + err.getMessage(), err);
            status = STATUS_COMMAND_PARSING_FAILURE;
            break;
        } catch (ApplicationBeanException err) {
            log.error("Error processing command line argument " + (null != prefix ? prefix : "") + arg + ": "
                    + err.getMessage(), err);
            try {
                err.updateBeanStatus();
            } catch (RuntimeException noStatus) {
                final ApplicationBean appBean = err.getApplicationBean();
                log.warn("Could not obtain status code" + (null != appBean ? " from " + appBean : ""),
                        noStatus);
                status = STATUS_INTERNAL_ERROR;
            }
            break;
        }
    }
    return this;
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Reverts an hot beans module to a previous revision (which becomes a new revision).
 *//*ww  w . j av  a 2  s .c o m*/
public HotBeanModuleInfo revertHotBeanModule(final String moduleName, final long revision) {
    Log logger = this.getLog();
    HotBeanModuleInfo hotBeanModuleInfo = null;

    if (logger.isInfoEnabled())
        logger.info("Attempting to revert module '" + moduleName + "' to revision " + revision + ".");

    synchronized (super.getLock()) {
        File moduleDirectory = new File(this.moduleRepositoryDirectory, moduleName);
        File moduleFile = new File(moduleDirectory, revision + MODULE_FILE_SUFFIX);

        if (moduleFile.exists()) {
            try {
                hotBeanModuleInfo = this.updateModuleInternal(moduleName, new FileInputStream(moduleFile),
                        false);

                if (logger.isInfoEnabled())
                    logger.info("Done reverting module - " + hotBeanModuleInfo + ".");
            } catch (Exception e) {
                logger.error("Error reverting module '" + moduleName + " - " + e + "'!", e);
                throw new HotBeansException("Error reverting module '" + moduleName + " - " + e + "'!");
            }
        } else
            throw new HotBeansException(
                    "Revision " + revision + " doesn't exist for module '" + moduleName + "!");
    }

    if (hotBeanModuleInfo != null)
        return hotBeanModuleInfo.getClone();
    else
        return hotBeanModuleInfo;
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Removes all revisions of a hot bean module.
 *///from  ww  w  .j a v a  2s  .  c om
public void removeHotBeanModule(final String moduleName) {
    Log logger = this.getLog();

    if (logger.isInfoEnabled())
        logger.info("Removing module '" + moduleName + "'.");

    synchronized (super.getLock()) {
        RepositoryFileLock fileLock = null;
        try {
            HotBeanModuleType moduleType = super.getHotBeanModuleType(moduleName);

            if (moduleType != null) {
                // Mark current module revision as as deleted to indicate that the module should be deleted
                moduleType.setRemoveType(true);

                fileLock = this.obtainRepositoryFileLock(false); // Obtain lock

                File moduleDirectory = new File(this.moduleRepositoryDirectory, moduleName);
                FileDeletor.delete(moduleDirectory);

                this.checkForObsoleteModules(moduleName); // Perform a check on the module at once, to make sure it is
                                                          // removed
            }
        } catch (Exception e) {
            logger.error("Error deleting module '" + moduleName + " - " + e + "'!", e);
            throw new HotBeansException("Error deleting module '" + moduleName + " - " + e + "'!");
        } finally {
            this.releaseRepositoryFileLock(fileLock);
            fileLock = null;
        }
    }
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Initializes this FileSystemHotBeanModuleRepository.
 */// w w  w  .  j  a  v a2 s .  c o  m
public void init() throws Exception {
    synchronized (super.getLock()) {
        if (!initialized) {
            Log logger = this.getLog();

            if (this.moduleRepositoryDirectory == null)
                this.moduleRepositoryDirectory = new File("hotModules");
            if (this.temporaryDirectory == null)
                this.temporaryDirectory = new File(this.moduleRepositoryDirectory, "temp");

            this.moduleRepositoryDirectory.mkdirs();
            this.temporaryDirectory.mkdirs();

            // Delete temporary directory on start up
            FileDeletor.delete(this.temporaryDirectory);

            if (logger.isDebugEnabled())
                logger.debug("Initializing FileSystemHotBeanModuleRepository - moduleRepositoryDirectory: "
                        + this.moduleRepositoryDirectory + ", temporaryDirectory: " + this.temporaryDirectory
                        + ".");

            RepositoryFileLock fileLock = null;
            try {
                fileLock = this.obtainRepositoryFileLock(false);
            } catch (Exception e) {
                logger.error("Error obtaining repository file lock on init!", e);
            } finally {
                this.releaseRepositoryFileLock(fileLock);
                fileLock = null;
            }

            super.init();

            initialized = true;
        }
    }
}

From source file:com.boylesoftware.web.AbstractWebApplication.java

/**
 * Initialize the web-application. Called by the framework just before the
 * application is made available in the container.
 *
 * @throws UnavailableException If application cannot be initialized.
 * Throwing the exception makes the application fail to start.
 *///from w ww.ja v  a  2  s.  c  om
void onRouterInit() throws UnavailableException {

    // get the log
    final Log log = LogFactory.getLog(AbstractWebApplication.class);
    log.debug("initializing the web-application");

    // initialize the application
    boolean success = false;
    try {

        // create configuration
        log.debug("creating configuration");
        this.configure(this.configProperties);

        // get the authenticator
        final ServletContext sc = this.servletContext;
        log.debug("creating authenticator");
        this.services.setAuthenticationService(this.getAuthenticationService(sc, this));

        // get validator factory
        log.debug("creating validator factory");
        this.services.setValidatorFactory(this.getValidatorFactory(sc, this));

        // get user locale finder
        log.debug("creating user locale finder");
        this.services.setUserLocaleFinder(this.getUserLocaleFinder(sc, this));

        // create entity manager factory
        log.debug("creating persistence manager factory");
        this.services.setEntityManagerFactory(this.getEntityManagerFactory(sc, this));

        // get JavaMail session from the JNDI
        log.debug("attempting to find JavaMail session in the JNDI");
        try {
            final InitialContext jndi = new InitialContext();
            try {
                this.services
                        .setMailSession((Session) jndi.lookup(this.getConfigProperty(MAIL_SESSION_JNDI_NAME,
                                String.class, ApplicationServices.DEFAULT_MAIL_SESSION_JNDI_NAME)));
            } catch (final NameNotFoundException e) {
                log.debug("no JavaMail session in the JNDI, JavaMail will" + " be unavailable", e);
            }
        } catch (final NamingException e) {
            log.error("Error accessing JNDI.", e);
        }

        // get the router configuration
        log.debug("creating routes configuration");
        this.routerConfiguration = this.getRouterConfiguration(sc, this, this.services);

        // initialize custom application
        log.debug("initializing custom application");
        this.init();

        // get the executor service
        log.debug("creating request processing executor service");
        this.executors = this.getExecutorService(sc, this);

        // done
        log.debug("initialized successfully");
        success = true;

    } finally {
        if (!success) {
            log.debug("initialization error");
            this.cleanup();
        }
    }
}

From source file:com.mnt.base.stream.netty.NConnectionHandler.java

@Override
public void channelRead(ChannelHandlerContext ctx, Object message) throws Exception {

    RequestHandler handler = ctx.channel().attr(NSTREAM_HANDLER_KEY).get();

    try {/*from www .j a  v a  2s. c o m*/
        handler.process((byte[]) message, null);
    } catch (Exception e) {
        Log.error("Closing connection due to error while processing message: " + message, e);
        Connection connection = (Connection) ctx.channel().attr(NSTREAM_CONNECTION_KEY).get();
        connection.close();
    }
}

From source file:hotbeans.support.FileSystemHotBeanModuleRepository.java

/**
 * Checks for module updates./*from www  .  j  ava  2 s  .c  om*/
 */
protected void checkForModuleUpdates() {
    Log logger = this.getLog();
    if (logger.isDebugEnabled())
        logger.debug("Checking for updated modules in path '" + this.moduleRepositoryDirectory + "'.");

    synchronized (super.getLock()) {
        RepositoryFileLock fileLock = null;
        try {
            fileLock = this.obtainRepositoryFileLockNoRetries(true); // Obtain lock without retries since this method
                                                                     // will be executed again in the
                                                                     // near future...

            File[] moduleDirectories = this.moduleRepositoryDirectory.listFiles();
            ArrayList activeModuleNames = new ArrayList(Arrays.asList(super.getHotBeanModuleNames()));

            if (moduleDirectories != null) {
                String moduleName;

                for (int i = 0; i < moduleDirectories.length; i++) {
                    if (moduleDirectories[i].isDirectory()) {
                        moduleName = moduleDirectories[i].getName();

                        if (moduleName != null) {
                            activeModuleNames.remove(moduleName);
                            this.checkModuleDirectory(moduleName, moduleDirectories[i]);
                        }
                    }
                }
            }

            // Check for deleted modules...
            Iterator deletedModulesIterator = activeModuleNames.iterator();
            // HotBeanModule module;
            HotBeanModuleType moduleType;

            while (deletedModulesIterator.hasNext()) {
                moduleType = super.getHotBeanModuleType((String) deletedModulesIterator.next());
                if (moduleType != null)
                    moduleType.setRemoveType(true); // Set remove flag of type
            }
        } catch (Exception e) {
            logger.error("Error checking for updated modules - " + e + "!", e);
            // TODO: Handle/log exception
        } finally {
            this.releaseRepositoryFileLock(fileLock);
            fileLock = null;
        }
    }
}

From source file:architecture.common.crypto.Blowfish.java

/**
 * Creates a new Blowfish object using the specified key (oversized password
 * will be cut).//from   w w  w .  j  a va2 s.c o m
 * 
 * @param password
 *            the password (treated as a real unicode array)
 */
public Blowfish(String password) {
    // hash down the password to a 160bit key
    MessageDigest digest = null;
    try {
        digest = MessageDigest.getInstance("SHA1");
        digest.update(password.getBytes());
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }

    // setup the encryptor (use a dummy IV)
    m_bfish = new BlowfishCBC(digest.digest(), 0);
    digest.reset();
}