List of usage examples for org.apache.commons.logging Log error
void error(Object message, Throwable t);
From source file:org.alfresco.util.LogUtil.java
/** * Log an I18Nized message to ERROR with a given source error. * /*from w ww . j ava 2 s . c o m*/ * @param logger the logger to use * @param e the exception cause of the issue * @param messageKey the message key * @param args the required message arguments */ public static final void error(Log logger, Throwable e, String messageKey, Object... args) { logger.error(I18NUtil.getMessage(messageKey, args), e); }
From source file:org.amplafi.flow.impl.FlowStateLoggerImpl.java
public void error(Log logger, Object message, Throwable throwable) { if (logger == null) { logger = getLog();//from w ww . j av a 2s. c o m } StringBuilder stringBuilder = getFlowStatesString(message); logger.error(stringBuilder, throwable); }
From source file:org.anyframe.iam.admin.common.aspect.ExceptionTransfer.java
/** * catch and transfer exception through aspect service ( setting : * [src/main/resources/spring/common/context-aspect.xml] ) * //from w w w .java 2s. co m * @param thisJoinPoint aspect service JoinPoint * @param exception aspect service exception */ public void transfer(JoinPoint thisJoinPoint, Exception exception) throws IAMException { Object target = thisJoinPoint.getTarget(); while (target instanceof Advised) { try { target = ((Advised) target).getTargetSource().getTarget(); } catch (Exception e) { LogFactory.getLog(this.getClass()).error("Fail to get target object from JointPoint.", e); break; } } String className = target.getClass().getSimpleName().toLowerCase(); String opName = (thisJoinPoint.getSignature().getName()).toLowerCase(); Log logger = LogFactory.getLog(target.getClass()); if (exception instanceof IAMException) { IAMException iamEx = (IAMException) exception; logger.error(iamEx.getMessage(), iamEx); throw iamEx; } logger.error(messageSource.getMessage("error." + className + "." + opName, new String[] {}, "no messages", Locale.getDefault()), exception); throw new IAMException(messageSource.getMessage("error." + className + "." + opName, new String[] {}, exception.getMessage(), Locale.getDefault()), exception); }
From source file:org.anyframe.oden.admin.aspect.ExceptionTransfer.java
@AfterThrowing(pointcut = "execution(* org.anyframe.oden..*Impl.*(..))", throwing = "exception") public void transfer(JoinPoint thisJoinPoint, Exception exception) throws BrokerException { Object target = thisJoinPoint.getTarget(); while (target instanceof Advised) { try {/*from w w w . j av a 2 s.co m*/ target = ((Advised) target).getTargetSource().getTarget(); } catch (Exception e) { LogFactory.getLog(this.getClass()).error("Fail to get target object from JointPoint.", e); break; } } String className = target.getClass().getSimpleName().toLowerCase(); String opName = thisJoinPoint.getSignature().getName().toLowerCase(); Log logger = LogFactory.getLog(target.getClass()); // Oden Server Interface Exception if (exception instanceof BrokerException) { BrokerException odenEx = (BrokerException) exception; String msg = messageSource.getMessage(odenEx.getMessage(), new String[] {}, Locale.getDefault()); if (!odenEx.getMessage().contains("broker.info")) { logger.error(msg, odenEx); } throw new BrokerException(msg, odenEx); } // Processing serviceImpl Exception if (exception instanceof BaseException) { BaseException baseEx = (BaseException) exception; logger.error(baseEx.getMessage(), baseEx); throw new BrokerException(messageSource, "error." + className + "." + opName, new String[] {}, exception); } logger.error(messageSource.getMessage("error." + className + "." + opName, new String[] {}, "no messages", Locale.getDefault()), exception); throw new BrokerException(messageSource, "error." + className + "." + opName, new String[] {}, exception); }
From source file:org.apache.cocoon.transformation.helpers.FormValidatorHelper.java
/** * Set up the complementary configuration file. Please note that * multiple Actions can share the same configurations. By using * this approach, we can limit the number of config files. * Also note that the configuration file does not have to be a file. * * This is based on the similar named functions in * org.apache.cocoon.acting.AbstractComplimentaryConfigurableAction * with the addition of reloadable configuration files, reloadable * flagg, manager, and logger parameter. * * @param descriptor URL of descriptor.xml file @see org.apache.cocoon.acting.AbstractComplimentaryConfigurableAction * @param resolver/*from w ww .j av a 2s . c o m*/ * @param reloadable set to <code>true</code> if changes of * <code>descriptor</code> should trigger a reload. Note that this * only works if <code>Source</code> is able to determine the * modification time @see org.apache.cocoon.environment.Source * @param logger used to send debug and error messages to * @return up-to-date configuration, either (re)loaded or cached. */ protected static Configuration getConfiguration(String descriptor, SourceResolver resolver, boolean reloadable, Log logger) throws ConfigurationException { if (descriptor == null) { throw new ConfigurationException("The form descriptor is not set!"); } ConfigurationHelper conf = null; synchronized (FormValidatorHelper.configurations) { Source source = null; try { source = resolver.resolveURI(descriptor); conf = (ConfigurationHelper) FormValidatorHelper.configurations.get(source.getURI()); if (conf == null || (reloadable && conf.lastModified != source.getLastModified())) { logger.debug("(Re)Loading " + descriptor); if (conf == null) { conf = new ConfigurationHelper(); } SAXConfigurationHandler builder = new SAXConfigurationHandler(); SourceUtil.toSAX(source, builder); conf.lastModified = source.getLastModified(); conf.configuration = builder.getConfiguration(); FormValidatorHelper.cacheConfiguration(source.getURI(), conf); } else { logger.debug("Using cached configuration for " + descriptor); } } catch (Exception e) { logger.error("Could not configure Database mapping environment", e); throw new ConfigurationException( "Error trying to load configurations for resource: " + source.getURI()); } finally { resolver.release(source); } } return conf.configuration; }
From source file:org.apache.hadoop.corona.Utilities.java
/** * Sets an uncaught exception handler. This will make the process exit with * exit code 1 if a thread exits due to an uncaught exception. *///from w ww . j a va 2 s . co m public static void makeProcessExitOnUncaughtException(final Log log) { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { log.error("UNCAUGHT: Thread " + t.getName() + " got an uncaught exception", e); System.exit(1); } }); }
From source file:org.apache.hadoop.hbase.rest.Main.java
/** * The main method for the HBase rest server. * @param args command-line arguments/*from w w w. j av a 2 s.c o m*/ * @throws Exception exception */ public static void main(String[] args) throws Exception { Log LOG = LogFactory.getLog("RESTServer"); VersionInfo.logVersion(); Configuration conf = HBaseConfiguration.create(); RESTServlet servlet = RESTServlet.getInstance(conf); Options options = new Options(); options.addOption("p", "port", true, "Port to bind to [default: 8080]"); options.addOption("ro", "readonly", false, "Respond only to GET HTTP " + "method requests [default: false]"); CommandLine commandLine = null; try { commandLine = new PosixParser().parse(options, args); } catch (ParseException e) { LOG.error("Could not parse: ", e); printUsageAndExit(options, -1); } // check for user-defined port setting, if so override the conf if (commandLine != null && commandLine.hasOption("port")) { String val = commandLine.getOptionValue("port"); servlet.getConfiguration().setInt("hbase.rest.port", Integer.valueOf(val)); LOG.debug("port set to " + val); } // check if server should only process GET requests, if so override the conf if (commandLine != null && commandLine.hasOption("readonly")) { servlet.getConfiguration().setBoolean("hbase.rest.readonly", true); LOG.debug("readonly set to true"); } @SuppressWarnings("unchecked") List<String> remainingArgs = commandLine != null ? commandLine.getArgList() : new ArrayList<String>(); if (remainingArgs.size() != 1) { printUsageAndExit(options, 1); } String command = remainingArgs.get(0); if ("start".equals(command)) { // continue and start container } else if ("stop".equals(command)) { System.exit(1); } else { printUsageAndExit(options, 1); } // set up the Jersey servlet container for Jetty ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", ResourceConfig.class.getCanonicalName()); sh.setInitParameter("com.sun.jersey.config.property.packages", "jetty"); // set up Jetty and run the embedded server Server server = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(servlet.getConfiguration().getInt("hbase.rest.port", 8080)); connector.setHost(servlet.getConfiguration().get("hbase.rest.host", "0.0.0.0")); server.addConnector(connector); // Set the default max thread number to 100 to limit // the number of concurrent requests so that REST server doesn't OOM easily. // Jetty set the default max thread number to 250, if we don't set it. // // Our default min thread number 2 is the same as that used by Jetty. int maxThreads = servlet.getConfiguration().getInt("hbase.rest.threads.max", 100); int minThreads = servlet.getConfiguration().getInt("hbase.rest.threads.min", 2); QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads); threadPool.setMinThreads(minThreads); server.setThreadPool(threadPool); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // set up context Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(sh, "/*"); context.addFilter(GzipFilter.class, "/*", 0); // login the server principal (if using secure Hadoop) if (User.isSecurityEnabled() && User.isHBaseSecurityEnabled(conf)) { String machineName = Strings .domainNamePointerToHostName(DNS.getDefaultHost(conf.get("hbase.rest.dns.interface", "default"), conf.get("hbase.rest.dns.nameserver", "default"))); User.login(conf, "hbase.rest.keytab.file", "hbase.rest.kerberos.principal", machineName); } // start server server.start(); server.join(); }
From source file:org.apache.hadoop.hbase.rest.RESTServer.java
/** * The main method for the HBase rest server. * @param args command-line arguments//w w w. j ava 2s . c om * @throws Exception exception */ public static void main(String[] args) throws Exception { Log LOG = LogFactory.getLog("RESTServer"); VersionInfo.logVersion(); FilterHolder authFilter = null; Configuration conf = HBaseConfiguration.create(); Class<? extends ServletContainer> containerClass = ServletContainer.class; UserProvider userProvider = UserProvider.instantiate(conf); // login the server principal (if using secure Hadoop) if (userProvider.isHadoopSecurityEnabled() && userProvider.isHBaseSecurityEnabled()) { String machineName = Strings.domainNamePointerToHostName(DNS.getDefaultHost( conf.get(REST_DNS_INTERFACE, "default"), conf.get(REST_DNS_NAMESERVER, "default"))); String keytabFilename = conf.get(REST_KEYTAB_FILE); Preconditions.checkArgument(keytabFilename != null && !keytabFilename.isEmpty(), REST_KEYTAB_FILE + " should be set if security is enabled"); String principalConfig = conf.get(REST_KERBEROS_PRINCIPAL); Preconditions.checkArgument(principalConfig != null && !principalConfig.isEmpty(), REST_KERBEROS_PRINCIPAL + " should be set if security is enabled"); userProvider.login(REST_KEYTAB_FILE, REST_KERBEROS_PRINCIPAL, machineName); if (conf.get(REST_AUTHENTICATION_TYPE) != null) { containerClass = RESTServletContainer.class; authFilter = new FilterHolder(); authFilter.setClassName(AuthFilter.class.getName()); authFilter.setName("AuthenticationFilter"); } } UserGroupInformation realUser = userProvider.getCurrent().getUGI(); RESTServlet servlet = RESTServlet.getInstance(conf, realUser); Options options = new Options(); options.addOption("p", "port", true, "Port to bind to [default: 8080]"); options.addOption("ro", "readonly", false, "Respond only to GET HTTP " + "method requests [default: false]"); options.addOption(null, "infoport", true, "Port for web UI"); CommandLine commandLine = null; try { commandLine = new PosixParser().parse(options, args); } catch (ParseException e) { LOG.error("Could not parse: ", e); printUsageAndExit(options, -1); } // check for user-defined port setting, if so override the conf if (commandLine != null && commandLine.hasOption("port")) { String val = commandLine.getOptionValue("port"); servlet.getConfiguration().setInt("hbase.rest.port", Integer.valueOf(val)); LOG.debug("port set to " + val); } // check if server should only process GET requests, if so override the conf if (commandLine != null && commandLine.hasOption("readonly")) { servlet.getConfiguration().setBoolean("hbase.rest.readonly", true); LOG.debug("readonly set to true"); } // check for user-defined info server port setting, if so override the conf if (commandLine != null && commandLine.hasOption("infoport")) { String val = commandLine.getOptionValue("infoport"); servlet.getConfiguration().setInt("hbase.rest.info.port", Integer.valueOf(val)); LOG.debug("Web UI port set to " + val); } @SuppressWarnings("unchecked") List<String> remainingArgs = commandLine != null ? commandLine.getArgList() : new ArrayList<String>(); if (remainingArgs.size() != 1) { printUsageAndExit(options, 1); } String command = remainingArgs.get(0); if ("start".equals(command)) { // continue and start container } else if ("stop".equals(command)) { System.exit(1); } else { printUsageAndExit(options, 1); } // set up the Jersey servlet container for Jetty ServletHolder sh = new ServletHolder(containerClass); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", ResourceConfig.class.getCanonicalName()); sh.setInitParameter("com.sun.jersey.config.property.packages", "jetty"); // The servlet holder below is instantiated to only handle the case // of the /status/cluster returning arrays of nodes (live/dead). Without // this servlet holder, the problem is that the node arrays in the response // are collapsed to single nodes. We want to be able to treat the // node lists as POJO in the response to /status/cluster servlet call, // but not change the behavior for any of the other servlets // Hence we don't use the servlet holder for all servlets / paths ServletHolder shPojoMap = new ServletHolder(containerClass); @SuppressWarnings("unchecked") Map<String, String> shInitMap = sh.getInitParameters(); for (Entry<String, String> e : shInitMap.entrySet()) { shPojoMap.setInitParameter(e.getKey(), e.getValue()); } shPojoMap.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true"); // set up Jetty and run the embedded server Server server = new Server(); Connector connector = new SelectChannelConnector(); if (conf.getBoolean(REST_SSL_ENABLED, false)) { SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(); String keystore = conf.get(REST_SSL_KEYSTORE_STORE); String password = conf.get(REST_SSL_KEYSTORE_PASSWORD); String keyPassword = conf.get(REST_SSL_KEYSTORE_KEYPASSWORD, password); sslConnector.setKeystore(keystore); sslConnector.setPassword(password); sslConnector.setKeyPassword(keyPassword); connector = sslConnector; } connector.setPort(servlet.getConfiguration().getInt("hbase.rest.port", 8080)); connector.setHost(servlet.getConfiguration().get("hbase.rest.host", "0.0.0.0")); server.addConnector(connector); // Set the default max thread number to 100 to limit // the number of concurrent requests so that REST server doesn't OOM easily. // Jetty set the default max thread number to 250, if we don't set it. // // Our default min thread number 2 is the same as that used by Jetty. int maxThreads = servlet.getConfiguration().getInt("hbase.rest.threads.max", 100); int minThreads = servlet.getConfiguration().getInt("hbase.rest.threads.min", 2); QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads); threadPool.setMinThreads(minThreads); server.setThreadPool(threadPool); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // set up context Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(shPojoMap, "/status/cluster"); context.addServlet(sh, "/*"); if (authFilter != null) { context.addFilter(authFilter, "/*", 1); } // Load filters from configuration. String[] filterClasses = servlet.getConfiguration().getStrings(FILTER_CLASSES, ArrayUtils.EMPTY_STRING_ARRAY); for (String filter : filterClasses) { filter = filter.trim(); context.addFilter(Class.forName(filter), "/*", 0); } HttpServerUtil.constrainHttpMethods(context); // Put up info server. int port = conf.getInt("hbase.rest.info.port", 8085); if (port >= 0) { conf.setLong("startcode", System.currentTimeMillis()); String a = conf.get("hbase.rest.info.bindAddress", "0.0.0.0"); InfoServer infoServer = new InfoServer("rest", a, port, false, conf); infoServer.setAttribute("hbase.conf", conf); infoServer.start(); } // start server server.start(); server.join(); }
From source file:org.apache.james.transport.mailets.jsieve.delivery.SieveExecutor.java
protected boolean sieveMessage(MailAddress recipient, Mail aMail, Log log) throws MessagingException { try {//w w w .ja v a2s. co m ResourceLocator.UserSieveInformation userSieveInformation = resourceLocator.get(recipient); sieveMessageEvaluate(recipient, aMail, userSieveInformation, log); return true; } catch (ScriptNotFoundException e) { log.info("Can not locate SIEVE script for user " + recipient.asPrettyString()); return false; } catch (Exception ex) { log.error("Cannot evaluate Sieve script for user " + recipient.asPrettyString(), ex); return false; } }
From source file:org.apache.myfaces.custom.dojo.DojoUtils.java
/** * creates a dojoed attribute map upon the given array of attribute names * * @param facesContext// w w w. jav a2s . c om * standard faces context used internally * @param attributeNames * string array of traversable attribute names * @param component * the source component with the values set * @return a map which resembles the attribute map for further processing */ public static Map getAttributeMap(FacesContext facesContext, String[] attributeNames, UIComponent component) { Log log = null; Class componentClass = component.getClass(); Map returnMap = new HashMap(); for (int cnt = 0; cnt < attributeNames.length; cnt++) { try { String attributeName = attributeNames[cnt]; //the dojo attributes deal with different ids than the rest if (attributeName.equals("id") || attributeName.equals("widgetId")) { String calculatedId = DojoUtils.calculateWidgetId(facesContext, component); returnMap.put("id", calculatedId); } else { String attributeCasedName = attributeName.substring(0, 1).toUpperCase() + attributeName.substring(1); String getForm = "get" + attributeCasedName; // to prevent multiple creating in finding String isForm = "is" + attributeCasedName; // to prevent multiple creating in finding Method m = null; // finding getter in hiearchy: try current class for "get" and "is" form, if NOT found, try superclass // doesn't use getMethod() to avoid walking whole hiearchy for wrong form in case of "is" // and getMethod() uses getSuperClass() anyway, so no performance hit this way + ability to invoke protected methods while ((componentClass != null) && (m == null)) { m = componentClass.getDeclaredMethod(getForm, null); if (m == null) { // try alternative method name for dealing with Booleans m = componentClass.getDeclaredMethod(isForm, null); } if (m == null) { // load superclass componentClass = componentClass.getSuperclass(); // null in case of componentClass == Object } } if (m != null) { Object execRetval = m.invoke(component, null); if (execRetval != null) returnMap.put(attributeName, execRetval); } } } catch (Exception e) { if (log == null) log = LogFactory.getLog(DojoUtils.class); // this should not happen but can log.error("getAttributeMap", e); } } return returnMap; }