/** * Log a task that has been rejected by {@link #doRescheduleTask}. * <p>The default implementation simply logs a corresponding message * at debug level. * @param task the rejected task object * @param ex the exception thrown from {@link #doRescheduleTask} */ protected void logRejectedTask(Object task, RuntimeException ex) { if (logger.isDebugEnabled()) { logger.debug("Listener container task [" + task + "] has been rejected and paused: " + ex); } }
/** * Add an attribute for a cacheable method. * <p>Method names can be exact matches, or of the pattern "xxx*", * "*xxx" or "*xxx*" for matching multiple methods. * @param methodName the name of the method * @param ops operation associated with the method */ public void addCacheMethod(String methodName, Collection<CacheOperation> ops) { if (logger.isDebugEnabled()) { logger.debug("Adding method [" + methodName + "] with cache operations [" + ops + "]"); } this.nameMap.put(methodName, ops); }
/** * Check the UserTransaction as well as the TransactionManager handle, * assuming standard JTA requirements. * @throws IllegalStateException if no sufficient handles are available */ protected void checkUserTransactionAndTransactionManager() throws IllegalStateException { // We at least need the JTA UserTransaction. if (this.userTransaction != null) { if (logger.isDebugEnabled()) { logger.debug("Using JTA UserTransaction: " + this.userTransaction); } } else { throw new IllegalStateException("No JTA UserTransaction available - specify either " + "'userTransaction' or 'userTransactionName' or 'transactionManager' or 'transactionManagerName'"); } // For transaction suspension, the JTA TransactionManager is necessary too. if (this.transactionManager != null) { if (logger.isDebugEnabled()) { logger.debug("Using JTA TransactionManager: " + this.transactionManager); } } else { logger.warn("No JTA TransactionManager found: transaction suspension not available"); } }
private MessageProducer getCachedProducer(@Nullable Destination dest) throws JMSException { DestinationCacheKey cacheKey = (dest != null ? new DestinationCacheKey(dest) : null); MessageProducer producer = this.cachedProducers.get(cacheKey); if (producer != null) { if (logger.isTraceEnabled()) { logger.trace("Found cached JMS MessageProducer for destination [" + dest + "]: " + producer); } } else { producer = this.target.createProducer(dest); if (logger.isDebugEnabled()) { logger.debug("Registering cached JMS MessageProducer for destination [" + dest + "]: " + producer); } this.cachedProducers.put(cacheKey, producer); } return new CachedMessageProducer(producer); }
@Override public void onWriteInactivity(final Runnable runnable, final long duration) { Assert.state(getTaskScheduler() != null, "No TaskScheduler configured"); this.lastWriteTime = System.currentTimeMillis(); this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> { if (System.currentTimeMillis() - this.lastWriteTime > duration) { try { runnable.run(); } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("WriteInactivityTask failure", ex); } } } }, duration / 2)); }
/** * Return the header value, or {@code null} if it does not exist * or does not match the requested {@code type}. */ @Nullable protected <V> V getHeaderIfAvailable(Map<String, Object> headers, String name, Class<V> type) { Object value = headers.get(name); if (value == null) { return null; } if (!type.isAssignableFrom(value.getClass())) { if (logger.isDebugEnabled()) { logger.debug("Skipping header '" + name + "': expected type [" + type + "], but got [" + value.getClass() + "]"); } return null; } else { return type.cast(value); } }
if (sessionId == null) { if (logger.isErrorEnabled()) { logger.error("Could not find session id in " + message); WebSocketSessionHolder holder = this.sessions.get(sessionId); if (holder == null) { if (logger.isDebugEnabled()) { logger.debug("No session for " + message); if (logger.isDebugEnabled()) { logger.debug("Terminating '" + session + "'", ex); logger.debug("Failure while closing session " + sessionId + ".", secondException); if (logger.isDebugEnabled()) { logger.debug("Failed to send message to client in " + session + ": " + message, ex);
if (logger.isDebugEnabled()) { logger.debug("Looking up default SQLErrorCodes for DataSource [" + identify(dataSource) + "]"); SQLErrorCodes sec = this.dataSourceCache.get(dataSource); if (sec == null) { synchronized (this.dataSourceCache) { sec = this.dataSourceCache.get(dataSource); if (sec == null) { logger.warn("Error while extracting database name - falling back to empty error codes", ex); if (logger.isDebugEnabled()) { logger.debug("SQLErrorCodes found in cache for DataSource [" + identify(dataSource) + "]");
/** * Determine whether to log the given exception coming from a * {@link ObjectMapper#canDeserialize} / {@link ObjectMapper#canSerialize} check. * @param type the class that Jackson tested for (de-)serializability * @param cause the Jackson-thrown exception to evaluate * (typically a {@link JsonMappingException}) * @since 4.3 */ protected void logWarningIfNecessary(Type type, @Nullable Throwable cause) { if (cause == null) { return; } // Do not log warning for serializer not found (note: different message wording on Jackson 2.9) boolean debugLevel = (cause instanceof JsonMappingException && cause.getMessage().startsWith("Cannot find")); if (debugLevel ? logger.isDebugEnabled() : logger.isWarnEnabled()) { String msg = "Failed to evaluate Jackson " + (type instanceof JavaType ? "de" : "") + "serialization for type [" + type + "]"; if (debugLevel) { logger.debug(msg, cause); } else if (logger.isDebugEnabled()) { logger.warn(msg, cause); } else { logger.warn(msg + ": " + cause); } } }
public void afterTransportClosed(@Nullable CloseStatus closeStatus) { CloseStatus cs = this.closeStatus; if (cs == null) { cs = closeStatus; this.closeStatus = closeStatus; } Assert.state(cs != null, "CloseStatus not available"); if (logger.isDebugEnabled()) { logger.debug("Transport closed with " + cs + " in " + this); } this.state = State.CLOSED; try { this.webSocketHandler.afterConnectionClosed(this, cs); } catch (Throwable ex) { logger.error("WebSocketHandler.afterConnectionClosed threw an exception", ex); } }
/** * Refresh the stub and retry the remote invocation if necessary. * <p>If not configured to refresh on connect failure, this method * simply rethrows the original exception. * @param invocation the invocation that failed * @param ex the exception raised on remote invocation * @return the result value of the new invocation, if succeeded * @throws Throwable an exception raised by the new invocation, * if it failed as well * @see #setRefreshStubOnConnectFailure * @see #doInvoke */ @Nullable private Object handleRemoteConnectFailure(MethodInvocation invocation, Exception ex) throws Throwable { if (this.refreshStubOnConnectFailure) { String msg = "Could not connect to RMI service [" + getServiceUrl() + "] - retrying"; if (logger.isDebugEnabled()) { logger.warn(msg, ex); } else if (logger.isWarnEnabled()) { logger.warn(msg); } return refreshAndRetry(invocation); } else { throw ex; } }
@Override public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException { LifecycleMetadata metadata = findLifecycleMetadata(bean.getClass()); try { metadata.invokeDestroyMethods(bean, beanName); } catch (InvocationTargetException ex) { String msg = "Destroy method on bean with name '" + beanName + "' threw an exception"; if (logger.isDebugEnabled()) { logger.warn(msg, ex.getTargetException()); } else { logger.warn(msg + ": " + ex.getTargetException()); } } catch (Throwable ex) { logger.warn("Failed to invoke destroy method on bean with name '" + beanName + "'", ex); } }
@Override public JCacheOperation<?> getCacheOperation(Method method, @Nullable Class<?> targetClass) { MethodClassKey cacheKey = new MethodClassKey(method, targetClass); Object cached = this.cache.get(cacheKey); if (cached != null) { return (cached != NULL_CACHING_ATTRIBUTE ? (JCacheOperation<?>) cached : null); } else { JCacheOperation<?> operation = computeCacheOperation(method, targetClass); if (operation != null) { if (logger.isDebugEnabled()) { logger.debug("Adding cacheable method '" + method.getName() + "' with operation: " + operation); } this.cache.put(cacheKey, operation); } else { this.cache.put(cacheKey, NULL_CACHING_ATTRIBUTE); } return operation; } }
@Override public void onReadInactivity(final Runnable runnable, final long duration) { Assert.state(getTaskScheduler() != null, "No TaskScheduler configured"); this.lastReadTime = System.currentTimeMillis(); this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> { if (System.currentTimeMillis() - this.lastReadTime > duration) { try { runnable.run(); } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("ReadInactivityTask failure", ex); } } } }, duration / 2)); }
/** * Add an attribute for a transactional method. * <p>Method names can be exact matches, or of the pattern "xxx*", * "*xxx" or "*xxx*" for matching multiple methods. * @param methodName the name of the method * @param attr attribute associated with the method */ public void addTransactionalMethod(String methodName, TransactionAttribute attr) { if (logger.isDebugEnabled()) { logger.debug("Adding transactional method [" + methodName + "] with attribute [" + attr + "]"); } this.nameMap.put(methodName, attr); }
@Override @Nullable public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public id [" + publicId + "] and system id [" + systemId + "]"); } if (systemId != null) { String resourceLocation = getSchemaMappings().get(systemId); if (resourceLocation != null) { Resource resource = new ClassPathResource(resourceLocation, this.classLoader); try { InputSource source = new InputSource(resource.getInputStream()); source.setPublicId(publicId); source.setSystemId(systemId); if (logger.isTraceEnabled()) { logger.trace("Found XML schema [" + systemId + "] in classpath: " + resourceLocation); } return source; } catch (FileNotFoundException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not find XML schema [" + systemId + "]: " + resource, ex); } } } } return null; }
protected void sendMessageToSubscribers(@Nullable String destination, Message<?> message) { MultiValueMap<String,String> subscriptions = this.subscriptionRegistry.findSubscriptions(message); if (!subscriptions.isEmpty() && logger.isDebugEnabled()) { logger.debug("Broadcasting to " + subscriptions.size() + " sessions."); Object payload = message.getPayload(); Message<?> reply = MessageBuilder.createMessage(payload, headerAccessor.getMessageHeaders()); SessionInfo info = this.sessions.get(sessionId); if (info != null) { try { logger.error("Failed to send " + message, ex);
/** * Determine whether to log the given exception coming from a * {@link ObjectMapper#canDeserialize} / {@link ObjectMapper#canSerialize} check. * @param type the class that Jackson tested for (de-)serializability * @param cause the Jackson-thrown exception to evaluate * (typically a {@link JsonMappingException}) * @since 4.3 */ protected void logWarningIfNecessary(Type type, @Nullable Throwable cause) { if (cause == null) { return; } // Do not log warning for serializer not found (note: different message wording on Jackson 2.9) boolean debugLevel = (cause instanceof JsonMappingException && cause.getMessage().startsWith("Cannot find")); if (debugLevel ? logger.isDebugEnabled() : logger.isWarnEnabled()) { String msg = "Failed to evaluate Jackson " + (type instanceof JavaType ? "de" : "") + "serialization for type [" + type + "]"; if (debugLevel) { logger.debug(msg, cause); } else if (logger.isDebugEnabled()) { logger.warn(msg, cause); } else { logger.warn(msg + ": " + cause); } } }
@Override public String executeInfoRequest(URI infoUrl, @Nullable HttpHeaders headers) { if (logger.isDebugEnabled()) { logger.debug("Executing SockJS Info request, url=" + infoUrl); } HttpHeaders infoRequestHeaders = new HttpHeaders(); if (headers != null) { infoRequestHeaders.putAll(headers); } ResponseEntity<String> response = executeInfoRequestInternal(infoUrl, infoRequestHeaders); if (response.getStatusCode() != HttpStatus.OK) { if (logger.isErrorEnabled()) { logger.error("SockJS Info request (url=" + infoUrl + ") failed: " + response); } throw new HttpServerErrorException(response.getStatusCode()); } if (logger.isTraceEnabled()) { logger.trace("SockJS Info request (url=" + infoUrl + ") response: " + response); } String result = response.getBody(); return (result != null ? result : ""); }
private void log(String message, HttpMethod httpMethod, URI uri) { if (logger.isDebugEnabled()) { logger.debug(String.format("%s %s \"%s\"", message, httpMethod, uri)); } }