INT-1477 restructuring samples repo to have basic, intermediate, advancedand applications directories

This commit is contained in:
Oleg Zhurakousky
2010-09-28 16:58:48 -04:00
parent f44812b7a9
commit 59081a2df8
362 changed files with 0 additions and 0 deletions

View File

@@ -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();
}
}

View File

@@ -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;
}
}

View File

@@ -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");
}
}

View File

@@ -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);
}
}

View File

@@ -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>

View File

@@ -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 &lt;header-enricher/&gt; element
* within a &lt;chain/&gt; that establishes an 'error-channel' reference
* prior to passing the message to a &lt;service-activator/&gt;.
*
* @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);
}
}

View 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>