List of usage examples for org.springframework.util ObjectUtils nullSafeToString
public static String nullSafeToString(@Nullable short[] array)
From source file:org.springframework.integration.kafka.support.LoggingProducerListener.java
@Override public void onError(String topic, Integer partition, Object key, Object payload, Exception exception) { if (log.isErrorEnabled()) { StringBuffer logOutput = new StringBuffer(); logOutput.append("Exception thrown when sending a message"); if (includeContents) { logOutput.append(//w ww. ja v a 2 s.co m " with key='" + toDisplayString(ObjectUtils.nullSafeToString(key), maxContentLogged) + "'"); logOutput.append(" and payload='" + toDisplayString(ObjectUtils.nullSafeToString(payload), maxContentLogged) + "'"); } logOutput.append(" to topic " + topic); if (partition != null) { logOutput.append(" and partition " + partition); } logOutput.append(":"); log.error(logOutput, exception); } }
From source file:org.springframework.jms.listener.adapter.MessageListenerAdapter.java
/** * Invoke the specified listener method. * @param methodName the name of the listener method * @param arguments the message arguments to be passed in * @return the result returned from the listener method * @throws JMSException if thrown by JMS API methods * @see #getListenerMethodName/*from w w w. j a v a 2s .com*/ * @see #buildListenerArguments */ protected Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException { try { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetObject(getDelegate()); methodInvoker.setTargetMethod(methodName); methodInvoker.setArguments(arguments); methodInvoker.prepare(); return methodInvoker.invoke(); } catch (InvocationTargetException ex) { Throwable targetEx = ex.getTargetException(); if (targetEx instanceof JMSException) { throw (JMSException) targetEx; } else { throw new ListenerExecutionFailedException("Listener method '" + methodName + "' threw exception", targetEx); } } catch (Throwable ex) { throw new ListenerExecutionFailedException("Failed to invoke target method '" + methodName + "' with arguments " + ObjectUtils.nullSafeToString(arguments), ex); } }
From source file:org.springframework.kafka.listener.LoggingErrorHandler.java
@Override public void handle(Exception thrownException, ConsumerRecord<?, ?> record) { log.error("Error while processing: " + ObjectUtils.nullSafeToString(record), thrownException); }
From source file:org.springframework.kafka.support.LoggingProducerListener.java
@Override public void onError(String topic, Integer partition, K key, V value, Exception exception) { if (log.isErrorEnabled()) { StringBuffer logOutput = new StringBuffer(); logOutput.append("Exception thrown when sending a message"); if (this.includeContents) { logOutput.append(" with key='" + toDisplayString(ObjectUtils.nullSafeToString(key), this.maxContentLogged) + "'"); logOutput.append(" and payload='" + toDisplayString(ObjectUtils.nullSafeToString(value), this.maxContentLogged) + "'"); }// w ww . j a v a 2 s .c om logOutput.append(" to topic " + topic); if (partition != null) { logOutput.append(" and partition " + partition); } logOutput.append(":"); log.error(logOutput, exception); } }
From source file:org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.java
@Override public PersistenceUnitInfo obtainDefaultPersistenceUnitInfo() { if (this.persistenceUnitInfoNames.isEmpty()) { throw new IllegalStateException("No persistence units parsed from " + ObjectUtils.nullSafeToString(this.persistenceXmlLocations)); }/*from w w w . j a v a2 s . co m*/ if (this.persistenceUnitInfos.isEmpty()) { throw new IllegalStateException("All persistence units from " + ObjectUtils.nullSafeToString(this.persistenceXmlLocations) + " already obtained"); } if (this.persistenceUnitInfos.size() > 1 && this.defaultPersistenceUnitName != null) { return obtainPersistenceUnitInfo(this.defaultPersistenceUnitName); } PersistenceUnitInfo pui = this.persistenceUnitInfos.values().iterator().next(); this.persistenceUnitInfos.clear(); return pui; }
From source file:org.springframework.osgi.extender.internal.support.ExtenderConfiguration.java
/** * Constructs a new <code>ExtenderConfiguration</code> instance. Locates the extender configuration, creates an * application context which will returned the extender items. * /*ww w . j a v a2 s . c o m*/ * @param bundleContext extender OSGi bundle context */ public ExtenderConfiguration(BundleContext bundleContext, Log log) { this.log = log; Bundle bundle = bundleContext.getBundle(); Properties properties = new Properties(createDefaultProperties()); Enumeration<?> enm = bundle.findEntries(EXTENDER_CFG_LOCATION, XML_PATTERN, false); if (enm == null) { log.info("No custom extender configuration detected; using defaults..."); synchronized (lock) { taskExecutor = createDefaultTaskExecutor(); shutdownTaskExecutor = createDefaultShutdownTaskExecutor(); eventMulticaster = createDefaultEventMulticaster(); contextCreator = createDefaultApplicationContextCreator(); contextEventListener = createDefaultApplicationContextListener(); } classLoader = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle); } else { String[] configs = copyEnumerationToList(enm); log.info("Detected extender custom configurations at " + ObjectUtils.nullSafeToString(configs)); // create OSGi specific XML context ConfigurableOsgiBundleApplicationContext extenderAppCtx = new OsgiBundleXmlApplicationContext(configs); extenderAppCtx.setBundleContext(bundleContext); extenderAppCtx.refresh(); synchronized (lock) { extenderConfiguration = extenderAppCtx; // initialize beans taskExecutor = extenderConfiguration.containsBean(TASK_EXECUTOR_NAME) ? (TaskExecutor) extenderConfiguration.getBean(TASK_EXECUTOR_NAME, TaskExecutor.class) : createDefaultTaskExecutor(); shutdownTaskExecutor = extenderConfiguration.containsBean(SHUTDOWN_TASK_EXECUTOR_NAME) ? (TaskExecutor) extenderConfiguration.getBean(SHUTDOWN_TASK_EXECUTOR_NAME, TaskExecutor.class) : createDefaultShutdownTaskExecutor(); eventMulticaster = extenderConfiguration.containsBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME) ? (OsgiBundleApplicationContextEventMulticaster) extenderConfiguration.getBean( APPLICATION_EVENT_MULTICASTER_BEAN_NAME, OsgiBundleApplicationContextEventMulticaster.class) : createDefaultEventMulticaster(); contextCreator = extenderConfiguration.containsBean(CONTEXT_CREATOR_NAME) ? (OsgiApplicationContextCreator) extenderConfiguration.getBean(CONTEXT_CREATOR_NAME, OsgiApplicationContextCreator.class) : createDefaultApplicationContextCreator(); contextEventListener = extenderConfiguration.containsBean(CONTEXT_LISTENER_NAME) ? (OsgiBundleApplicationContextListener) extenderConfiguration .getBean(CONTEXT_LISTENER_NAME, OsgiBundleApplicationContextListener.class) : createDefaultApplicationContextListener(); } // get post processors postProcessors .addAll(extenderConfiguration.getBeansOfType(OsgiBeanFactoryPostProcessor.class).values()); // get dependency factories dependencyFactories .addAll(extenderConfiguration.getBeansOfType(OsgiServiceDependencyFactory.class).values()); classLoader = extenderConfiguration.getClassLoader(); // extender properties using the defaults as backup if (extenderConfiguration.containsBean(PROPERTIES_NAME)) { Properties customProperties = (Properties) extenderConfiguration.getBean(PROPERTIES_NAME, Properties.class); Enumeration<?> propertyKey = customProperties.propertyNames(); while (propertyKey.hasMoreElements()) { String property = (String) propertyKey.nextElement(); properties.setProperty(property, customProperties.getProperty(property)); } } } synchronized (lock) { shutdownWaitTime = getShutdownWaitTime(properties); dependencyWaitTime = getDependencyWaitTime(properties); processAnnotation = getProcessAnnotations(properties); } // load default dependency factories addDefaultDependencyFactories(); // allow post processing contextCreator = postProcess(contextCreator); }
From source file:org.springframework.osgi.extender.support.internal.ConfigUtils.java
public static boolean matchExtenderVersionRange(Bundle bundle, String header, Version versionToMatch) { Assert.notNull(bundle);// www. j av a 2 s .c o m // get version range String range = (String) bundle.getHeaders().get(header); boolean trace = log.isTraceEnabled(); // empty value = empty version = * if (!StringUtils.hasText(range)) return true; if (trace) log.trace("discovered " + header + " header w/ value=" + range); // do we have a range or not ? range = StringUtils.trimWhitespace(range); // a range means one comma int commaNr = StringUtils.countOccurrencesOf(range, COMMA); // no comma, no intervals if (commaNr == 0) { Version version = Version.parseVersion(range); return versionToMatch.equals(version); } if (commaNr == 1) { // sanity check if (!((range.startsWith(LEFT_CLOSED_INTERVAL) || range.startsWith(LEFT_OPEN_INTERVAL)) && (range.endsWith(RIGHT_CLOSED_INTERVAL) || range.endsWith(RIGHT_OPEN_INTERVAL)))) { throw new IllegalArgumentException("range [" + range + "] is invalid"); } boolean equalMin = range.startsWith(LEFT_CLOSED_INTERVAL); boolean equalMax = range.endsWith(RIGHT_CLOSED_INTERVAL); // remove interval brackets range = range.substring(1, range.length() - 1); // split the remaining string in two pieces String[] pieces = StringUtils.split(range, COMMA); if (trace) log.trace("discovered low/high versions : " + ObjectUtils.nullSafeToString(pieces)); Version minVer = Version.parseVersion(pieces[0]); Version maxVer = Version.parseVersion(pieces[1]); if (trace) log.trace("comparing version " + versionToMatch + " w/ min=" + minVer + " and max=" + maxVer); boolean result = true; int compareMin = versionToMatch.compareTo(minVer); if (equalMin) result = (result && (compareMin >= 0)); else result = (result && (compareMin > 0)); int compareMax = versionToMatch.compareTo(maxVer); if (equalMax) result = (result && (compareMax <= 0)); else result = (result && (compareMax < 0)); return result; } // more then one comma means incorrect range throw new IllegalArgumentException("range [" + range + "] is invalid"); }
From source file:org.springframework.osgi.service.importer.support.AbstractOsgiServiceImportFactoryBean.java
/** * Assembles the configuration properties into one unified OSGi filter. Note that this implementation creates the * filter on the first call and caches it afterwards. * /* w w w.ja va 2 s . com*/ * @return unified filter based on this factory bean configuration */ public Filter getUnifiedFilter() { if (unifiedFilter != null) { return unifiedFilter; } String filterWithClasses = (!ObjectUtils.isEmpty(interfaces) ? OsgiFilterUtils.unifyFilter(interfaces, filter) : filter); boolean trace = log.isTraceEnabled(); if (trace) log.trace("Unified classes=" + ObjectUtils.nullSafeToString(interfaces) + " and filter=[" + filter + "] in=[" + filterWithClasses + "]"); // add the serviceBeanName/Blueprint component name constraint String nameFilter; if (StringUtils.hasText(serviceBeanName)) { StringBuilder nsFilter = new StringBuilder("(|("); nsFilter.append(OsgiServicePropertiesResolver.BEAN_NAME_PROPERTY_KEY); nsFilter.append("="); nsFilter.append(serviceBeanName); nsFilter.append(")("); nsFilter.append(OsgiServicePropertiesResolver.BLUEPRINT_COMP_NAME); nsFilter.append("="); nsFilter.append(serviceBeanName); nsFilter.append("))"); nameFilter = nsFilter.toString(); } else { nameFilter = null; } String filterWithServiceBeanName = filterWithClasses; if (nameFilter != null) { StringBuilder finalFilter = new StringBuilder(); finalFilter.append("(&"); finalFilter.append(filterWithClasses); finalFilter.append(nameFilter); finalFilter.append(")"); filterWithServiceBeanName = finalFilter.toString(); } if (trace) log.trace("Unified serviceBeanName [" + ObjectUtils.nullSafeToString(serviceBeanName) + "] and filter=[" + filterWithClasses + "] in=[" + filterWithServiceBeanName + "]"); // create (which implies validation) the actual filter unifiedFilter = OsgiFilterUtils.createFilter(filterWithServiceBeanName); return unifiedFilter; }
From source file:org.springframework.osgi.web.deployer.internal.util.JasperUtils.java
public static URL[] createTaglibClasspathJars(Bundle bundle) { List urls = new ArrayList(2); boolean trace = log.isTraceEnabled(); try {//from w ww . j a v a 2 s.co m // create taglib jar for tlds inside the bundle classpath Resource[] res = getBundleTagLibs(bundle); if (!ObjectUtils.isEmpty(res)) { urls.add(createTaglibJar(res, null)); } if (trace) log.trace("Bundle " + OsgiStringUtils.nullSafeNameAndSymName(bundle) + " has the following tlds in its classpath " + ObjectUtils.nullSafeToString(res)); // create taglib jar for tlds from imported bundles BundleContext ctx = OsgiBundleUtils.getBundleContext(bundle); Resource[] importedTLDs = getImportedBundlesTagLibs(ctx, bundle); if (!ObjectUtils.isEmpty(importedTLDs)) { urls.add(createTaglibJar(importedTLDs, null)); } if (trace) log.trace("Bundle " + OsgiStringUtils.nullSafeNameAndSymName(bundle) + " has the following tlds in its imported bundles " + ObjectUtils.nullSafeToString(importedTLDs)); return (URL[]) urls.toArray(new URL[urls.size()]); } catch (IOException ex) { throw (RuntimeException) new IllegalStateException("Cannot create taglib jars").initCause(ex); } }
From source file:org.springframework.osgi.web.extender.internal.activator.WarListenerConfiguration.java
/** * Constructs a new <code>WarListenerConfiguration</code> instance. * Locates the extender configuration, creates an application context which * will returned the extender items./*from w ww .jav a 2 s.c o m*/ * * @param bundleContext extender OSGi bundle context */ public WarListenerConfiguration(BundleContext bundleContext) { Bundle bundle = bundleContext.getBundle(); Properties properties = new Properties(createDefaultProperties()); Enumeration enm = bundle.findEntries(EXTENDER_CFG_LOCATION, XML_PATTERN, false); if (enm == null) { log.info("No custom extender configuration detected; using defaults..."); warScanner = createDefaultWarScanner(); warDeployer = createDefaultWarDeployer(bundleContext); contextPathStrategy = createDefaultContextPathStrategy(); } else { String[] configs = copyEnumerationToList(enm); log.info("Detected extender custom configurations at " + ObjectUtils.nullSafeToString(configs)); // create OSGi specific XML context ConfigurableOsgiBundleApplicationContext context = new OsgiBundleXmlApplicationContext(configs); context.setBundleContext(bundleContext); context.refresh(); synchronized (lock) { extenderConfiguration = context; } warScanner = context.containsBean(WAR_SCANNER_NAME) ? (WarScanner) context.getBean(WAR_SCANNER_NAME, WarScanner.class) : createDefaultWarScanner(); warDeployer = context.containsBean(WAR_DEPLOYER_NAME) ? (WarDeployer) context.getBean(WAR_DEPLOYER_NAME, WarDeployer.class) : createDefaultWarDeployer(bundleContext); contextPathStrategy = context.containsBean(CONTEXT_PATH_STRATEGY_NAME) ? (ContextPathStrategy) context.getBean(CONTEXT_PATH_STRATEGY_NAME, ContextPathStrategy.class) : createDefaultContextPathStrategy(); // extender properties using the defaults as backup if (context.containsBean(PROPERTIES_NAME)) { Properties customProperties = (Properties) context.getBean(PROPERTIES_NAME, Properties.class); Enumeration propertyKey = customProperties.propertyNames(); while (propertyKey.hasMoreElements()) { String property = (String) propertyKey.nextElement(); properties.setProperty(property, customProperties.getProperty(property)); } } } undeployWarsAtShutdown = getUndeployWarsAtShutdown(properties); }