INT-4257-2: Document ErrorMessagePublisher

JIRA: https://jira.spring.io/browse/INT-4257

* Remove deprecated `EnhancedErrorMessage`
* Document `ErrorMessagePublisher` and `ErrorMessageStrategy`
* Fix Reactor version to `3.1` in Doc
* Fix sample about Reactive Streams in the `router.adoc`
This commit is contained in:
Artem Bilan
2017-04-19 19:11:58 -04:00
committed by Gary Russell
parent f7f7bdd067
commit 71b93987d7
7 changed files with 22 additions and 84 deletions

View File

@@ -1,64 +0,0 @@
/*
* Copyright 2017 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.message;
import java.util.Map;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.ErrorMessage;
/**
* An error message that is enhanced with a message that is available at the
* stack frame where the error message is generated. Typically this will be a
* message that begins a subflow, whereas if the {@link Throwable} payload is
* a {@link org.springframework.messaging.MessagingException}, its failedMessage
* property will contain the message at the point where the exception occurred.
*
* @author Gary Russell
*
* @since 4.3.10
*
* @deprecated since 4.3.10 in favor of direct {@link ErrorMessage} usage since 5.0.
*/
@Deprecated
public class EnhancedErrorMessage extends ErrorMessage {
private static final long serialVersionUID = 5857673472822628678L;
private final Message<?> originalMessage;
public EnhancedErrorMessage(Message<?> originalMessage, Throwable payload) {
super(payload);
this.originalMessage = originalMessage;
}
public EnhancedErrorMessage(Message<?> originalMessage, Throwable payload, MessageHeaders headers) {
super(payload, headers);
this.originalMessage = originalMessage;
}
public EnhancedErrorMessage(Message<?> originalMessage, Throwable payload, Map<String, Object> headers) {
super(payload, headers);
this.originalMessage = originalMessage;
}
public Message<?> getOriginalMessage() {
return this.originalMessage;
}
}

View File

@@ -36,12 +36,9 @@ import org.springframework.messaging.support.ErrorMessage;
public class DefaultErrorMessageStrategy implements ErrorMessageStrategy {
@Override
@SuppressWarnings("deprecation")
public ErrorMessage buildErrorMessage(Throwable throwable, AttributeAccessor attributes) {
Object inputMessage = attributes.getAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY);
return inputMessage instanceof Message
? new org.springframework.integration.message.EnhancedErrorMessage((Message<?>) inputMessage, throwable)
: new ErrorMessage(throwable);
return new ErrorMessage(throwable, inputMessage instanceof Message ? (Message<?>) inputMessage : null);
}
}

View File

@@ -35,6 +35,7 @@ import org.springframework.messaging.support.ErrorMessage;
*
* @since 4.3.10
*/
@FunctionalInterface
public interface ErrorMessageStrategy {
/**

View File

@@ -1034,24 +1034,21 @@ public class AdvisedMessageHandlerTests {
}
assertEquals(expected, counter.get());
}
@Test
@SuppressWarnings("deprecation")
public void enhancedRecoverer() throws Exception {
QueueChannel channel = new QueueChannel();
ErrorMessageSendingRecoverer recoverer = new ErrorMessageSendingRecoverer(channel);
recoverer.publish(new GenericMessage<>("foo"), new GenericMessage<>("bar"), new RuntimeException("baz"));
Message<?> error = channel.receive(0);
assertThat(error, instanceOf(org.springframework.integration.message.EnhancedErrorMessage.class));
assertThat(error, instanceOf(ErrorMessage.class));
assertThat(error.getPayload(), instanceOf(MessagingException.class));
MessagingException payload = (MessagingException) error.getPayload();
assertThat(payload.getCause(), instanceOf(RuntimeException.class));
assertThat(payload.getCause().getMessage(), equalTo("baz"));
assertThat(payload.getFailedMessage().getPayload(), equalTo("bar"));
assertThat(((org.springframework.integration.message.EnhancedErrorMessage) error).getOriginalMessage()
.getPayload(), equalTo("foo"));
assertThat(((ErrorMessage) error).getOriginalMessage().getPayload(), equalTo("foo"));
}
private interface Bar {