SPR40 Polishing
- Copyright - White space
This commit is contained in:
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -6,62 +21,71 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageHeaderAccessor;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
*
|
||||
* Adds standard SI Headers.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
public class EiMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
|
||||
public static final String CORRELATION_ID = "correlationId";
|
||||
public static final String CORRELATION_ID = "correlationId";
|
||||
|
||||
public static final String EXPIRATION_DATE = "expirationDate";
|
||||
public static final String EXPIRATION_DATE = "expirationDate";
|
||||
|
||||
public static final String PRIORITY = "priority";
|
||||
public static final String PRIORITY = "priority";
|
||||
|
||||
public static final String SEQUENCE_NUMBER = "sequenceNumber";
|
||||
public static final String SEQUENCE_NUMBER = "sequenceNumber";
|
||||
|
||||
public static final String SEQUENCE_SIZE = "sequenceSize";
|
||||
public static final String SEQUENCE_SIZE = "sequenceSize";
|
||||
|
||||
public static final String SEQUENCE_DETAILS = "sequenceDetails";
|
||||
public static final String SEQUENCE_DETAILS = "sequenceDetails";
|
||||
|
||||
public static final String POSTPROCESS_RESULT = "postProcessResult";
|
||||
public static final String POSTPROCESS_RESULT = "postProcessResult";
|
||||
|
||||
public EiMessageHeaderAccessor(Message<?> message) {
|
||||
super(message);
|
||||
}
|
||||
public EiMessageHeaderAccessor(Message<?> message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public Long getExpirationDate() {
|
||||
return this.getHeader(EXPIRATION_DATE, Long.class);
|
||||
}
|
||||
public Long getExpirationDate() {
|
||||
return this.getHeader(EXPIRATION_DATE, Long.class);
|
||||
}
|
||||
|
||||
public Object getCorrelationId() {
|
||||
return this.getHeader(CORRELATION_ID);
|
||||
}
|
||||
public Object getCorrelationId() {
|
||||
return this.getHeader(CORRELATION_ID);
|
||||
}
|
||||
|
||||
public Integer getSequenceNumber() {
|
||||
Integer sequenceNumber = this.getHeader(SEQUENCE_NUMBER, Integer.class);
|
||||
return (sequenceNumber != null ? sequenceNumber : 0);
|
||||
}
|
||||
public Integer getSequenceNumber() {
|
||||
Integer sequenceNumber = this.getHeader(SEQUENCE_NUMBER, Integer.class);
|
||||
return (sequenceNumber != null ? sequenceNumber : 0);
|
||||
}
|
||||
|
||||
public Integer getSequenceSize() {
|
||||
Integer sequenceSize = this.getHeader(SEQUENCE_SIZE, Integer.class);
|
||||
return (sequenceSize != null ? sequenceSize : 0);
|
||||
}
|
||||
public Integer getSequenceSize() {
|
||||
Integer sequenceSize = this.getHeader(SEQUENCE_SIZE, Integer.class);
|
||||
return (sequenceSize != null ? sequenceSize : 0);
|
||||
}
|
||||
|
||||
public Integer getPriority() {
|
||||
return this.getHeader(PRIORITY, Integer.class);
|
||||
}
|
||||
public Integer getPriority() {
|
||||
return this.getHeader(PRIORITY, Integer.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getHeader(String key, Class<T> type) {
|
||||
Object value = getHeader(key);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (!type.isAssignableFrom(value.getClass())) {
|
||||
throw new IllegalArgumentException("Incorrect type specified for header '" + key + "'. Expected [" + type
|
||||
+ "] but actual type is [" + value.getClass() + "]");
|
||||
}
|
||||
return (T) value;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getHeader(String key, Class<T> type) {
|
||||
Object value = getHeader(key);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (!type.isAssignableFrom(value.getClass())) {
|
||||
throw new IllegalArgumentException("Incorrect type specified for header '" + key + "'. Expected [" + type
|
||||
+ "] but actual type is [" + value.getClass() + "]");
|
||||
}
|
||||
return (T) value;
|
||||
}
|
||||
|
||||
protected void verifyType(String headerName, Object headerValue) {
|
||||
@Override
|
||||
protected void verifyType(String headerName, Object headerValue) {
|
||||
if (headerName != null && headerValue != null) {
|
||||
super.verifyType(headerName, headerValue);
|
||||
if (EiMessageHeaderAccessor.EXPIRATION_DATE.equals(headerName)) {
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
/*
|
||||
<<<<<<< HEAD
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
=======
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
>>>>>>> Further Spring 4 updates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
@@ -21,6 +17,7 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.router.AbstractMappingMessageRouter;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,12 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
import org.springframework.messaging.MessageHeaders.IdGenerator;
|
||||
|
||||
// TODO Discuss and agree where these should go. In SI or in Spring 4?
|
||||
/**
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
public class IdGenerators {
|
||||
|
||||
public static class JdkIdGenerator implements IdGenerator {
|
||||
|
||||
@@ -20,10 +20,7 @@ import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.integration.handler.AbstractMessageHandler;
|
||||
import org.springframework.integration.mapping.MessageMappingException;
|
||||
import org.springframework.mail.MailMessage;
|
||||
@@ -31,21 +28,24 @@ import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMailMessage;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A {@link MessageHandler} implementation for sending mail.
|
||||
*
|
||||
*
|
||||
* <p>If the Message is an instance of {@link MailMessage}, it will be passed
|
||||
* as-is. If the Message payload is a byte array, it will be passed as an
|
||||
* attachment, and in that case, the {@link MailHeaders#ATTACHMENT_FILENAME}
|
||||
* header is required. Otherwise, a String type is expected, and its content
|
||||
* will be used as the text within a {@link SimpleMailMessage}.
|
||||
*
|
||||
*
|
||||
* @see MailHeaders
|
||||
*
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -57,7 +57,7 @@ public class MailSendingMessageHandler extends AbstractMessageHandler {
|
||||
|
||||
/**
|
||||
* Create a MailSendingMessageConsumer.
|
||||
*
|
||||
*
|
||||
* @param mailSender the {@link JavaMailSender} instance to which this
|
||||
* adapter will delegate.
|
||||
*/
|
||||
@@ -67,6 +67,7 @@ public class MailSendingMessageHandler extends AbstractMessageHandler {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected final void handleMessageInternal(Message<?> message) {
|
||||
MailMessage mailMessage = this.convertMessageToMailMessage(message);
|
||||
if (mailMessage instanceof SimpleMailMessage) {
|
||||
@@ -111,15 +112,15 @@ public class MailSendingMessageHandler extends AbstractMessageHandler {
|
||||
this.applyHeadersToMailMessage(mailMessage, message.getHeaders());
|
||||
return mailMessage;
|
||||
}
|
||||
|
||||
|
||||
private MailMessage createMailMessageWithContentType(Message<String> message, String contentType){
|
||||
MimeMessage mimeMessage = this.mailSender.createMimeMessage();
|
||||
try {
|
||||
mimeMessage.setContent(message.getPayload(), contentType);
|
||||
return new MimeMailMessage(mimeMessage);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new org.springframework.messaging.MessagingException("Failed to creaet MimeMessage with contentType: " +
|
||||
throw new org.springframework.messaging.MessagingException("Failed to creaet MimeMessage with contentType: " +
|
||||
contentType, e);
|
||||
}
|
||||
}
|
||||
@@ -142,7 +143,7 @@ public class MailSendingMessageHandler extends AbstractMessageHandler {
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
throw new MessageMappingException(message, "failed to create MimeMessage", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applyHeadersToMailMessage(MailMessage mailMessage, MessageHeaders headers) {
|
||||
@@ -153,7 +154,7 @@ public class MailSendingMessageHandler extends AbstractMessageHandler {
|
||||
String[] to = this.retrieveHeaderValueAsStringArray(headers, MailHeaders.TO);
|
||||
if (to != null){
|
||||
mailMessage.setTo(to);
|
||||
}
|
||||
}
|
||||
if (mailMessage instanceof SimpleMailMessage) {
|
||||
Assert.state(!ObjectUtils.isEmpty(((SimpleMailMessage) mailMessage).getTo()),
|
||||
"No recipient has been provided on the MailMessage or the 'MailHeaders.TO' header.");
|
||||
@@ -184,7 +185,7 @@ public class MailSendingMessageHandler extends AbstractMessageHandler {
|
||||
returnedHeaders = (String[]) value;
|
||||
} else if (value instanceof String) {
|
||||
returnedHeaders = StringUtils.commaDelimitedListToStringArray((String) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (returnedHeaders == null || ObjectUtils.isEmpty(returnedHeaders)){
|
||||
returnedHeaders = null;
|
||||
|
||||
Reference in New Issue
Block a user