INT-1477 restructuring samples repo to have basic, intermediate, advancedand applications directories
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/* 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.Message;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.Transformer;
|
||||
import org.springframework.integration.message.ErrorMessage;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
@MessageEndpoint
|
||||
public class ErrorUnwrapper {
|
||||
|
||||
@Transformer
|
||||
public Message<?> transform(ErrorMessage errorMessage) {
|
||||
return ((MessagingException) errorMessage.getPayload()).getFailedMessage();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/* 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;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class Invitation {
|
||||
|
||||
private final int number;
|
||||
|
||||
public Invitation(int number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Invitation number " + number;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* 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.apache.log4j.Logger;
|
||||
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 {
|
||||
private Logger logger = Logger.getLogger(PartyGuest.class);
|
||||
|
||||
public void onInvitation(Invitation invitation) {
|
||||
logger.info("Guest is throwing exception");
|
||||
throw new RuntimeException("Wrong address");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.apache.log4j.Logger;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
|
||||
/**
|
||||
* Sends invitations to <code>PartyGuest</code>s and likes to be notified of
|
||||
* delivery failures of course.
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
@MessageEndpoint
|
||||
public class PartyHost {
|
||||
private Logger logger = Logger.getLogger(PartyHost.class);
|
||||
private final AtomicInteger counter = new AtomicInteger(0);
|
||||
|
||||
public Invitation nextInvitation() {
|
||||
return new Invitation(counter.incrementAndGet());
|
||||
}
|
||||
|
||||
public void onInvitationFailed(Invitation inv) {
|
||||
logger.info("Host received failure notification for: " + inv);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* Demonstrates the handling of Exceptions in an asynchronous messaging
|
||||
* environment. View the 'errorHandlingDemo.xml' configuration file within
|
||||
* this same package. Notice the use of a <header-enricher/> element
|
||||
* within a <chain/> that establishes an 'error-channel' reference
|
||||
* prior to passing the message to a <service-activator/>.
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class PartyDemoTest {
|
||||
@Test
|
||||
public void runPartyDemoTest() throws Exception{
|
||||
new ClassPathXmlApplicationContext("/META-INF/spring/integration/errorHandlingDemo.xml", PartyDemoTest.class);
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
}
|
||||
28
intermediate/errorhandling/src/test/resources/log4j.xml
Normal file
28
intermediate/errorhandling/src/test/resources/log4j.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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.samples">
|
||||
<level value="debug" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
Reference in New Issue
Block a user