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>
|
||||
Reference in New Issue
Block a user