List of usage examples for org.springframework.util ObjectUtils isEmpty
@SuppressWarnings("rawtypes") public static boolean isEmpty(@Nullable Object obj)
From source file:org.springframework.integration.config.MessagingGatewayRegistrar.java
public BeanDefinitionHolder parse(Map<String, Object> gatewayAttributes) { String defaultPayloadExpression = (String) gatewayAttributes.get("defaultPayloadExpression"); @SuppressWarnings("unchecked") Map<String, Object>[] defaultHeaders = (Map<String, Object>[]) gatewayAttributes.get("defaultHeaders"); String defaultRequestChannel = (String) gatewayAttributes.get("defaultRequestChannel"); String defaultReplyChannel = (String) gatewayAttributes.get("defaultReplyChannel"); String errorChannel = (String) gatewayAttributes.get("errorChannel"); String asyncExecutor = (String) gatewayAttributes.get("asyncExecutor"); String mapper = (String) gatewayAttributes.get("mapper"); boolean hasMapper = StringUtils.hasText(mapper); boolean hasDefaultPayloadExpression = StringUtils.hasText(defaultPayloadExpression); Assert.state(!hasMapper || !hasDefaultPayloadExpression, "'defaultPayloadExpression' is not allowed when a 'mapper' is provided"); boolean hasDefaultHeaders = !ObjectUtils.isEmpty(defaultHeaders); Assert.state(!hasMapper || !hasDefaultHeaders, "'defaultHeaders' are not allowed when a 'mapper' is provided"); BeanDefinitionBuilder gatewayProxyBuilder = BeanDefinitionBuilder .genericBeanDefinition(GatewayProxyFactoryBean.class); if (hasDefaultHeaders || hasDefaultPayloadExpression) { BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder .genericBeanDefinition(GatewayMethodMetadata.class); if (hasDefaultPayloadExpression) { methodMetadataBuilder.addPropertyValue("payloadExpression", defaultPayloadExpression); }/*from w w w. ja v a 2 s. c om*/ Map<String, Object> headerExpressions = new ManagedMap<String, Object>(); for (Map<String, Object> header : defaultHeaders) { String headerValue = (String) header.get("value"); String headerExpression = (String) header.get("expression"); boolean hasValue = StringUtils.hasText(headerValue); if (!(hasValue ^ StringUtils.hasText(headerExpression))) { throw new BeanDefinitionStoreException( "exactly one of 'value' or 'expression' " + "is required on a gateway's header."); } BeanDefinition expressionDef = new RootBeanDefinition( hasValue ? LiteralExpression.class : ExpressionFactoryBean.class); expressionDef.getConstructorArgumentValues() .addGenericArgumentValue(hasValue ? headerValue : headerExpression); headerExpressions.put((String) header.get("name"), expressionDef); } methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions); gatewayProxyBuilder.addPropertyValue("globalMethodMetadata", methodMetadataBuilder.getBeanDefinition()); } if (StringUtils.hasText(defaultRequestChannel)) { gatewayProxyBuilder.addPropertyReference("defaultRequestChannel", defaultRequestChannel); } if (StringUtils.hasText(defaultReplyChannel)) { gatewayProxyBuilder.addPropertyReference("defaultReplyChannel", defaultReplyChannel); } if (StringUtils.hasText(errorChannel)) { gatewayProxyBuilder.addPropertyReference("errorChannel", errorChannel); } if (StringUtils.hasText(asyncExecutor)) { gatewayProxyBuilder.addPropertyReference("asyncExecutor", asyncExecutor); } if (StringUtils.hasText(mapper)) { gatewayProxyBuilder.addPropertyReference("mapper", mapper); } gatewayProxyBuilder.addPropertyValue("defaultRequestTimeout", gatewayAttributes.get("defaultRequestTimeout")); gatewayProxyBuilder.addPropertyValue("defaultReplyTimeout", gatewayAttributes.get("defaultReplyTimeout")); gatewayProxyBuilder.addPropertyValue("methodMetadataMap", gatewayAttributes.get("methods")); String serviceInterface = (String) gatewayAttributes.get("serviceInterface"); if (!StringUtils.hasText(serviceInterface)) { serviceInterface = "org.springframework.integration.gateway.RequestReplyExchanger"; } String id = (String) gatewayAttributes.get("name"); if (!StringUtils.hasText(id)) { id = Introspector.decapitalize(serviceInterface.substring(serviceInterface.lastIndexOf(".") + 1)); } gatewayProxyBuilder.addConstructorArgValue(serviceInterface); return new BeanDefinitionHolder(gatewayProxyBuilder.getBeanDefinition(), id); }
From source file:org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.java
public void synchronizeToLocalDirectory(File localDirectory) { Session<F> session = null;//from w ww .j a va 2 s .c o m try { session = this.sessionFactory.getSession(); Assert.state(session != null, "failed to acquire a Session"); F[] files = session.list(this.remoteDirectory); if (!ObjectUtils.isEmpty(files)) { Collection<F> filteredFiles = this.filterFiles(files); for (F file : filteredFiles) { if (file != null) { this.copyFileToLocalDirectory(this.remoteDirectory, file, localDirectory, session); } } } } catch (IOException e) { throw new MessagingException("Problem occurred while synchronizing remote to local directory", e); } finally { if (session != null) { try { session.close(); } catch (Exception ignored) { if (logger.isDebugEnabled()) { logger.debug("failed to close Session", ignored); } } } } }
From source file:org.springframework.integration.ftp.session.FtpRemoteFileTemplate.java
/** * This particular FTP implementation is based on the {@link FTPClient#getStatus(String)} * by default, but since not all FTP servers properly implement the {@code STAT} command, * the framework internal {@link FtpRemoteFileTemplate} instances are switched to the * {@link FTPClient#listNames(String)} for only files operations. * <p> The mode can be switched with the {@link #setExistsMode(ExistsMode)} property. * <p> Any custom implementation can be done in an extension of the {@link FtpRemoteFileTemplate}. * @param path the remote file path to check. * @return true or false if remote file exists or not. *//*from w ww . jav a2 s .co m*/ @Override public boolean exists(final String path) { return doExecuteWithClient(client -> { try { switch (FtpRemoteFileTemplate.this.existsMode) { case STAT: return client.getStatus(path) != null; case NLST: String[] names = client.listNames(path); return !ObjectUtils.isEmpty(names); case NLST_AND_DIRS: return getSession().exists(path); default: throw new IllegalStateException( "Unsupported 'existsMode': " + FtpRemoteFileTemplate.this.existsMode); } } catch (IOException e) { throw new MessagingException("Failed to check the remote path for " + path, e); } }); }
From source file:org.springframework.integration.jmx.NotificationListeningMessageProducer.java
/** * Specify the JMX ObjectNames (or patterns) * of the notification publisher/*from www. j a v a2s . c o m*/ * to which this notification listener should be subscribed. */ public void setObjectName(ObjectName... objectNames) { Assert.isTrue(!ObjectUtils.isEmpty(objectNames), "'objectNames' must contain at least one ObjectName"); this.objectNames = objectNames; }
From source file:org.springframework.integration.support.MessageBuilder.java
private boolean containsReadOnly(MessageHeaders headers) { if (!ObjectUtils.isEmpty(this.readOnlyHeaders)) { for (String readOnly : this.readOnlyHeaders) { if (headers.containsKey(readOnly)) { return true; }//w ww . j av a 2s . co m } } return false; }
From source file:org.springframework.integration.test.rule.Log4j2LevelAdjuster.java
private Log4j2LevelAdjuster(Level level, Class<?>[] classes, String[] categories) { Assert.notNull(level, "'level' must be null"); this.level = level; this.classes = classes != null ? classes : new Class<?>[0]; Stream<String> categoryStream = Stream.of(getClass().getPackage().getName()); if (!ObjectUtils.isEmpty(categories)) { categoryStream = Stream.concat(Arrays.stream(categories), categoryStream); }//from w ww .j av a 2 s. co m this.categories = categoryStream.toArray(String[]::new); }
From source file:org.springframework.integration.xml.selector.XmlValidatingMessageSelector.java
@SuppressWarnings("unchecked") public boolean accept(Message<?> message) { SAXParseException[] validationExceptions = null; try {/*from w ww .java2 s. c o m*/ validationExceptions = this.xmlValidator.validate(this.converter.convertToSource(message.getPayload())); } catch (Exception e) { throw new MessageHandlingException(message, e); } boolean validationSuccess = ObjectUtils.isEmpty(validationExceptions); if (!validationSuccess) { if (this.throwExceptionOnRejection) { throw new MessageRejectedException(message, "Message was rejected due to XML Validation errors", new AggregatedXmlMessageValidationException( CollectionUtils.arrayToList(validationExceptions))); } if (logger.isDebugEnabled()) { logger.debug("Message was rejected due to XML Validation errors"); } } return validationSuccess; }
From source file:org.springframework.integration.xml.transformer.XsltPayloadTransformer.java
private Transformer buildTransformer(Message<?> message) throws TransformerException { // process individual mappings Transformer transformer = this.templates.newTransformer(); if (this.xslParameterMappings != null) { for (String parameterName : this.xslParameterMappings.keySet()) { Expression expression = this.xslParameterMappings.get(parameterName); try { Object value = expression.getValue(this.evaluationContext, message); transformer.setParameter(parameterName, value); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn("Evaluation of header expression '" + expression.getExpressionString() + "' failed. The XSLT parameter '" + parameterName + "' will be skipped."); }/* www . j a v a 2s . c o m*/ } } } // process xslt-parameter-headers MessageHeaders headers = message.getHeaders(); if (!ObjectUtils.isEmpty(this.xsltParamHeaders)) { for (String headerName : headers.keySet()) { if (PatternMatchUtils.simpleMatch(this.xsltParamHeaders, headerName)) { transformer.setParameter(headerName, headers.get(headerName)); } } } return transformer; }
From source file:org.springframework.jmx.export.MBeanExporter.java
/** * Gets the <code>ModelMBeanInfo</code> for the bean with the supplied key * and of the supplied type.//from www. j a va 2s. c o m */ private ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException { ModelMBeanInfo info = this.assembler.getMBeanInfo(managedBean, beanKey); if (logger.isWarnEnabled() && ObjectUtils.isEmpty(info.getAttributes()) && ObjectUtils.isEmpty(info.getOperations())) { logger.warn("Bean with key [" + beanKey + "] has been registed as an MBean but has no exposed attributes or operations"); } return info; }
From source file:org.springframework.messaging.handler.annotation.reactive.PayloadMethodArgumentResolver.java
@Nullable private Consumer<Object> getValidator(Message<?> message, MethodParameter parameter) { if (this.validator == null) { return null; }/* www. jav a2s.c o m*/ for (Annotation ann : parameter.getParameterAnnotations()) { Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class); if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) { Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann)); Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] { hints }); String name = Conventions.getVariableNameForParameter(parameter); return target -> { BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(target, name); if (!ObjectUtils.isEmpty(validationHints) && this.validator instanceof SmartValidator) { ((SmartValidator) this.validator).validate(target, bindingResult, validationHints); } else { this.validator.validate(target, bindingResult); } if (bindingResult.hasErrors()) { throw new MethodArgumentNotValidException(message, parameter, bindingResult); } }; } } return null; }