diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/Invitation.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/Invitation.java new file mode 100644 index 0000000000..79b97b5604 --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/Invitation.java @@ -0,0 +1,29 @@ +/* Copyright 2002-2008 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.samples.errorhandling; + +public class Invitation { + + private final int number; + + public Invitation(int number) { + this.number = number; + } + + @Override + public String toString() { + return "Invitation number " + number; + } +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/PartyDemo.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/PartyDemo.java new file mode 100644 index 0000000000..6f1919653c --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/PartyDemo.java @@ -0,0 +1,29 @@ +/* Copyright 2002-2008 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.samples.errorhandling; + +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class PartyDemo { + + /** + * @param args + */ + public static void main(String[] args) { + new ClassPathXmlApplicationContext("errorHandlingDemo.xml", PartyDemo.class).start(); + + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/PartyGuest.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/PartyGuest.java new file mode 100644 index 0000000000..7b6e2aced0 --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/PartyGuest.java @@ -0,0 +1,32 @@ +/* Copyright 2002-2008 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.samples.errorhandling; + +import org.springframework.integration.annotation.MessageEndpoint; + +/** + * This guest receives invitations, but returns them to sender with a wrong + * address exception message. + * + * @author Iwein Fuld + * + */ +@MessageEndpoint +public class PartyGuest { + public void onInvitation(Invitation invitation) { + System.out.println("Guest is throwing exception"); + throw new RuntimeException("Wrong address"); + } +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/PartyHost.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/PartyHost.java new file mode 100644 index 0000000000..92e7661d9a --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/PartyHost.java @@ -0,0 +1,41 @@ +/* Copyright 2002-2008 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.samples.errorhandling; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.springframework.integration.annotation.MessageEndpoint; + +/** + * Sends invitations to Guests and likes to be notified of delivery + * failures of course. + * + * @author Iwein Fuld + * + */ +@MessageEndpoint +public class PartyHost { + + private final AtomicInteger counter = new AtomicInteger(1); + + public Invitation nextInvitation() { + return new Invitation(counter.getAndIncrement()); + } + + public void onInvitationFailed(Invitation inv) { + System.out.println("Host received failure notification for: " + inv); + } + +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/UnwrappingErrorMessageTransformer.java b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/UnwrappingErrorMessageTransformer.java new file mode 100644 index 0000000000..dca3b33d45 --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/UnwrappingErrorMessageTransformer.java @@ -0,0 +1,29 @@ +/* Copyright 2002-2008 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.samples.errorhandling; + +import org.springframework.integration.core.Message; +import org.springframework.integration.core.MessagingException; +import org.springframework.integration.message.ErrorMessage; +import org.springframework.integration.transformer.Transformer; +import org.springframework.util.Assert; + +public class UnwrappingErrorMessageTransformer implements Transformer { + + public Message transform(Message message) { + Assert.isAssignable(ErrorMessage.class, message.getClass()); + return ((MessagingException) ((ErrorMessage) message).getPayload()).getFailedMessage(); + } +} diff --git a/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/errorHandlingDemo.xml b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/errorHandlingDemo.xml new file mode 100644 index 0000000000..f9963032a7 --- /dev/null +++ b/org.springframework.integration.samples/src/main/java/org/springframework/integration/samples/errorhandling/errorHandlingDemo.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file