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

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

Introduction

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

Prototype

void warn(Object message, Throwable t);

Source Link

Document

Logs an error with warn log level.

Usage

From source file:org.acmsl.queryj.tools.handlers.DatabaseMetaDataCacheReadingHandler.java

/**
 * Handles given parameters./*  w ww  .j a  v  a2  s  . co m*/
 * @param parameters the parameters to handle.
 * @param metadataManager the {@link MetadataManager} instance.
 * @return <code>true</code> if the chain should be stopped.
 */
@Override
protected boolean handle(@NotNull final QueryJCommand parameters,
        @Nullable final MetadataManager metadataManager) throws QueryJBuildException {
    boolean result = false;

    // We only need the table names, if they're not extracted already.
    if (metadataManager != null) {
        @NotNull
        final List<Table<String, Attribute<String>, List<Attribute<String>>>> t_lTables = metadataManager
                .getTableDAO().findAllTables();

        if ((t_lTables.size() == 0)) {
            try {
                metadataManager.eagerlyFetchMetadata();
            } catch (@NotNull final SQLException cannotExtractTableMetadata) {
                result = true;

                @Nullable
                final Log t_Log = UniqueLogFactory.getLog(DatabaseMetaDataCacheReadingHandler.class);

                if (t_Log != null) {
                    t_Log.warn(CANNOT_EXTRACT_TABLE_METADATA_LITERAL, cannotExtractTableMetadata);
                }
            } catch (@NotNull final QueryJException otherError) {
                @Nullable
                final Log t_Log = UniqueLogFactory.getLog(DatabaseMetaDataCacheReadingHandler.class);

                if (t_Log != null) {
                    t_Log.warn(CANNOT_EXTRACT_TABLE_METADATA_LITERAL, otherError);
                }

                result = true;
            }
        }
    }

    return result;
}

From source file:org.acmsl.queryj.tools.handlers.ParameterValidationHandler.java

/**
 * Validates the parameters.// w  ww.j a va  2  s. c  o  m
 * @param driver the JDBC driver.
 * @param url the url.
 * @param username the username.
 * @param schema the schema.
 * @param repository the repository.
 * @param packageName the package name.
 * @param outputDir the output folder.
 * @param header the header.
 * @param jndiDataSources the JNDI location for data sources.
 * @param sqlXmlFile the sql.xml file.
 * @param grammarFolder the grammar folder.
 * @param grammarBundleName the grammar bundle name.
 * @param grammarSuffix the grammar suffix.
 * @param encoding the file encoding.
 * @param threadCount the number of threads.
 * @param command the command, to store processed information.
 * such as the header contents.
 * @throws QueryJBuildException if any parameter fails to validate.
 */
protected void validateParameters(@Nullable final String driver, @Nullable final String url,
        @Nullable final String username, @Nullable final String schema, @Nullable final String repository,
        @Nullable final String packageName, @Nullable final File outputDir, @Nullable final File header,
        @Nullable final String jndiDataSources, @Nullable final File sqlXmlFile,
        @Nullable final File grammarFolder, @Nullable final String grammarBundleName,
        @Nullable final String grammarSuffix, @Nullable final String encoding, final int threadCount,
        @NotNull final QueryJCommand command) throws QueryJBuildException {
    @Nullable
    final Log t_Log = UniqueLogFactory.getLog(ParameterValidationHandler.class);

    if (driver == null) {
        throw new MissingJdbcDriverException();
    }

    if (url == null) {
        throw new MissingJdbcUrlException();
    }

    if (username == null) {
        throw new MissingJdbcUsernameException();
    }

    /* Not mandatory.
    if  (password == null)
    {
    throw new QueryJBuildException(PASSWORD_MISSING);
    }
    */

    /* Not mandatory.
    if  (catalog == null) 
    {
    throw new QueryJBuildException(CATALOG_MISSING);
    }
    */

    if (schema == null) {
        throw new MissingJdbcSchemaException();
    }

    if (repository == null) {
        throw new MissingRepositoryException();
    }

    if (packageName == null) {
        throw new MissingPackageException();
    }

    if (outputDir == null) {
        throw new MissingOutputFolderException();
    }

    if (header == null) {
        if (t_Log != null) {
            t_Log.info("No header specified. Using " + "GPLed QueryJ's instead.");
        }
    } else {
        try {
            command.setSetting(HEADER, readFile(header, Charset.forName(encoding)));
        } catch (@NotNull final FileNotFoundException fileNotFoundException) {
            if (t_Log != null) {
                t_Log.warn("Header file not found.", fileNotFoundException);
            }
            throw new CannotReadHeaderFileException(header, fileNotFoundException);
        } catch (@NotNull final SecurityException securityException) {
            if (t_Log != null) {
                t_Log.warn("No permission to read header file.", securityException);
            }
            throw new CannotReadHeaderFileException(header, securityException);
        } catch (@NotNull final IOException ioException) {
            if (t_Log != null) {
                t_Log.warn("Could not read header file.", ioException);
            }
            throw new CannotReadHeaderFileException(header, ioException);
        }
    }

    if (!outputDir.isDirectory()) {
        throw new OutputDirIsNotAFolderException(outputDir);
    }

    if (jndiDataSources == null) {
        throw new MissingJndiLocationException();
    }

    if ((jndiDataSources.contains("\"")) || (jndiDataSources.contains("\n"))) {
        throw new InvalidJndiLocationException(jndiDataSources);
    }

    if (sqlXmlFile == null) {
        throw new MissingCustomSqlXmlFileException();
    }

    if (!sqlXmlFile.exists()) {
        throw new CannotReadCustomSqlXmlFileException(sqlXmlFile);
    }

    if (!sqlXmlFile.canRead()) {
        throw new MissingCustomSqlXmlFileException();
    }

    // Not mandatory
    if (grammarFolder != null) {
        if (!grammarFolder.exists()) {
            throw new GrammarFolderDoesNotExistException(grammarFolder);
        }

        String suffix = grammarSuffix;

        if (grammarSuffix == null) {
            suffix = "";
        }

        File file = new File(grammarFolder + File.separator + grammarBundleName + "_"
                + Locale.US.getLanguage().toLowerCase(Locale.US) + suffix);

        if (!file.exists()) {
            file = new File(grammarFolder + File.separator + grammarBundleName + suffix);
        }

        if (!file.exists()) {
            throw new GrammarBundleDoesNotExistException(grammarBundleName, grammarFolder);
        }
    }

    if (encoding != null) {
        if (!Charset.isSupported(encoding)) {
            throw new UnsupportedCharsetQueryjException(encoding);
        } else {
            try {
                Charset.forName(encoding);
            } catch (@NotNull final IllegalCharsetNameException illegalCharset) {
                throw new UnsupportedCharsetQueryjException(encoding, illegalCharset);
            } catch (@NotNull final IllegalArgumentException nullCharset) {
                // should not happen since encoding is optional anyway.
                throw new NullCharsetException(nullCharset);
            }
            // catch (final UnsupportedCharsetException unsupportedCharset)
            // {
            //     // Should not happen since this has been checked beforehand.
            //     throw new QueryJBuildException(UNSUPPORTED_ENCODING);
            // }
        }
    }

    if (threadCount <= 0) {
        throw new IllegalThreadCountException(threadCount);
    }
}

From source file:org.alfresco.extension.bulkimport.util.LogUtils.java

public final static void warn(final Log log, final String message, final Throwable cause) {
    log.warn(PREFIX + message, cause);
}

From source file:org.alfresco.extension.bulkimport.util.LogUtils.java

public final static void warn(final Log log, final Throwable cause) {
    log.warn(RAW_EXCEPTION, cause);
}

From source file:org.amplafi.flow.impl.FlowStateLoggerImpl.java

public void warn(Log logger, Object message, Throwable throwable) {
    if (logger == null) {
        logger = getLog();//from w  ww .  j  a  v a2s  . com
    }
    StringBuilder stringBuilder = getFlowStatesString(message);
    logger.warn(stringBuilder, throwable);
}

From source file:org.apache.camel.util.IOHelper.java

/**
 * Closes the given resource if it is available, logging any closing
 * exceptions to the given log/*from  w ww  . ja va 2 s  . c  o  m*/
 *
 * @param closeable the object to close
 * @param name the name of the resource
 * @param log the log to use when reporting closure warnings
 */
public static void close(Closeable closeable, String name, Log log) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (IOException e) {
            if (log != null) {
                if (name != null) {
                    log.warn("Cannot close: " + name + ". Reason: " + e.getMessage(), e);
                } else {
                    log.warn("Cannot close. Reason: " + e.getMessage(), e);
                }
            }
        }
    }
}

From source file:org.apache.camel.util.UnitOfWorkHelper.java

@SuppressWarnings("unchecked")
public static void doneSynchronizations(Exchange exchange, List<Synchronization> synchronizations, Log log) {
    boolean failed = exchange.isFailed();

    if (synchronizations != null && !synchronizations.isEmpty()) {
        // work on a copy of the list to avoid any modification which may cause ConcurrentModificationException
        List<Synchronization> copy = new ArrayList<Synchronization>(synchronizations);

        // reverse so we invoke it FILO style instead of FIFO
        Collections.reverse(copy);
        // and honor if any was ordered by sorting it accordingly
        Collections.sort(copy, new OrderedComparator());

        // invoke synchronization callbacks
        for (Synchronization synchronization : copy) {
            try {
                if (failed) {
                    if (log.isTraceEnabled()) {
                        log.trace(//from  www.  j  a  va2 s . c  om
                                "Invoking synchronization.onFailure: " + synchronization + " with " + exchange);
                    }
                    synchronization.onFailure(exchange);
                } else {
                    if (log.isTraceEnabled()) {
                        log.trace("Invoking synchronization.onComplete: " + synchronization + " with "
                                + exchange);
                    }
                    synchronization.onComplete(exchange);
                }
            } catch (Throwable e) {
                // must catch exceptions to ensure all synchronizations have a chance to run
                log.warn("Exception occurred during onCompletion. This exception will be ignored.", e);
            }
        }
    }
}

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

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

    // reset state variables
    request.resetState();

    // argument check
    if (!request.hasArgument()) {
        out.send(501, "AUTH", null);
        return;
    }

    // check SSL configuration
    IFtpConfig fconfig = handler.getConfig();
    Log log = fconfig.getLogFactory().getInstance(getClass());
    if (fconfig.getSocketFactory().getSSL() == null) {
        out.send(431, "AUTH", null);
    }

    // check parameter
    String authType = request.getArgument().toUpperCase();
    if (authType.equals("SSL")) {
        out.send(234, "AUTH.SSL", null);
        try {
            handler.createSecureSocket("SSL");
        } catch (FtpException ex) {
            throw ex;
        } catch (Exception ex) {
            log.warn("AUTH.execute()", ex);
            throw new FtpException("AUTH.execute()", ex);
        }
    } else if (authType.equals("TLS")) {
        out.send(234, "AUTH.TLS", null);
        try {
            handler.createSecureSocket("TLS");
        } catch (FtpException ex) {
            throw ex;
        } catch (Exception ex) {
            log.warn("AUTH.execute()", ex);
            throw new FtpException("AUTH.execute()", ex);
        }
    } else {
        out.send(502, "AUTH", null);
    }
}

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

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

    // reset state
    request.resetState();

    // no params
    String argument = request.getArgument();
    if (argument == null) {
        out.send(501, "OPTS", null);
        return;
    }

    // get request name
    int spaceIndex = argument.indexOf(' ');
    if (spaceIndex != -1) {
        argument = argument.substring(0, spaceIndex);
    }
    argument = argument.toUpperCase();

    // call appropriate command method
    String optsRequest = "OPTS_" + argument;
    Command command = (Command) COMMAND_MAP.get(optsRequest);
    try {
        if (command != null) {
            command.execute(handler, request, out);
        } else {
            request.resetState();
            out.send(502, "OPTS.not.implemented", argument);
        }
    } catch (Exception ex) {
        Log log = handler.getConfig().getLogFactory().getInstance(getClass());
        log.warn("OPTS.execute()", ex);
        request.resetState();
        out.send(500, "OPTS", null);
    }
}

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

/**
 * Execute command./*from ww w . j  ava  2  s  .c  o m*/
 */
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);
        }
    }
}