INT-1380 added errorhandling sample
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="src" path="src/test/resources"/>
|
||||
<classpathentry kind="src" path="src/test/java"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
|
||||
1
cook-books/errorhandling/.gitignore
vendored
Normal file
1
cook-books/errorhandling/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
@@ -2,38 +2,51 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.integration.samples</groupId>
|
||||
<artifactId>spring-integration-samples</artifactId>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>org.springframework.integration.samples</groupId>
|
||||
<artifactId>errorhandling</artifactId>
|
||||
<name>Spring Integration Error Handling Sample</name>
|
||||
<version>2.0.0</version>
|
||||
<properties>
|
||||
<spring.integration.version>2.0.0.M7</spring.integration.version>
|
||||
<log4j.version>1.2.15</log4j.version>
|
||||
<junit.version>4.7</junit.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-core</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-stream</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<!-- test-scoped dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repository.springframework.maven.release</id>
|
||||
<name>Spring Framework Maven Release Repository</name>
|
||||
<url>http://maven.springframework.org/release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>repository.springframework.maven.milestone</id>
|
||||
<name>Spring Framework Maven Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>repository.springframework.maven.snapshot</id>
|
||||
<name>Spring Framework Maven Snapshot Repository</name>
|
||||
<url>http://maven.springframework.org/snapshot</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
<compilerArgument>-Xlint:all</compilerArgument>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>false</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
package org.springframework.integration.samples.errorhandling;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
|
||||
/**
|
||||
@@ -25,9 +26,10 @@ import org.springframework.integration.annotation.MessageEndpoint;
|
||||
*/
|
||||
@MessageEndpoint
|
||||
public class PartyGuest {
|
||||
|
||||
private Logger logger = Logger.getLogger(PartyGuest.class);
|
||||
|
||||
public void onInvitation(Invitation invitation) {
|
||||
System.out.println("Guest is throwing exception");
|
||||
logger.info("Guest is throwing exception");
|
||||
throw new RuntimeException("Wrong address");
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.integration.samples.errorhandling;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
|
||||
/**
|
||||
@@ -27,7 +28,7 @@ import org.springframework.integration.annotation.MessageEndpoint;
|
||||
*/
|
||||
@MessageEndpoint
|
||||
public class PartyHost {
|
||||
|
||||
private Logger logger = Logger.getLogger(PartyHost.class);
|
||||
private final AtomicInteger counter = new AtomicInteger(0);
|
||||
|
||||
public Invitation nextInvitation() {
|
||||
@@ -35,7 +36,6 @@ public class PartyHost {
|
||||
}
|
||||
|
||||
public void onInvitationFailed(Invitation inv) {
|
||||
System.out.println("Host received failure notification for: " + inv);
|
||||
logger.info("Host received failure notification for: " + inv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.samples.errorhandling;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
@@ -29,18 +28,10 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class PartyDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ClassPathXmlApplicationContext("errorHandlingDemo.xml", PartyDemo.class);
|
||||
System.out.println("### Hit ENTER to stop ###");
|
||||
try {
|
||||
System.in.read();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.exit(0);
|
||||
public class PartyDemoTest {
|
||||
@Test
|
||||
public void runPartyDemoTest() throws Exception{
|
||||
new ClassPathXmlApplicationContext("/META-INF/spring/integration/errorHandlingDemo.xml", PartyDemoTest.class);
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,8 +15,8 @@
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration">
|
||||
<level value="warn" />
|
||||
<logger name="org.springframework.integration.samples">
|
||||
<level value="debug" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Loggers -->
|
||||
<logger name="org.springframework">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,48 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:stream="http://www.springframework.org/schema/integration/stream"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/stream
|
||||
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
|
||||
|
||||
<context:component-scan base-package="org.springframework.integration.samples.errorhandling" />
|
||||
|
||||
<poller default="true" fixed-delay="1000" max-messages-per-poll="1"/>
|
||||
|
||||
<inbound-channel-adapter ref="partyHost"
|
||||
method="nextInvitation" channel="invitations" />
|
||||
|
||||
<channel id="invitations">
|
||||
<queue capacity="100" />
|
||||
</channel>
|
||||
|
||||
<chain input-channel="invitations">
|
||||
<header-enricher>
|
||||
<error-channel ref="failed-invitations" />
|
||||
</header-enricher>
|
||||
<service-activator ref="partyGuest" method="onInvitation" />
|
||||
</chain>
|
||||
|
||||
<channel id="failed-invitations" />
|
||||
|
||||
<chain input-channel="failed-invitations">
|
||||
<transformer ref="errorUnwrapper" />
|
||||
<service-activator ref="partyHost" method="onInvitationFailed" />
|
||||
</chain>
|
||||
|
||||
<!--
|
||||
If you don't listen to the default error channel you risk losing track
|
||||
of exceptions, as they cannot be passed back to the sender in band. It
|
||||
is recommended to have a generic error handler in your configuration
|
||||
to prevent this.
|
||||
-->
|
||||
<stream:stderr-channel-adapter channel="errorChannel" append-newline="true" />
|
||||
|
||||
</beans:beans>
|
||||
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
#Generated by Maven
|
||||
#Sat Sep 04 08:22:04 EDT 2010
|
||||
version=2.0.0.BUILD-SNAPSHOT
|
||||
groupId=org.springframework.integration.samples
|
||||
artifactId=errorhandling
|
||||
Reference in New Issue
Block a user