Skip to content

Commit d727a32

Browse files
ante003pivovarit
authored andcommitted
-added new files for integrations patterns with apache camel article (eugenp#887)
1 parent 2dc0cf6 commit d727a32

16 files changed

Lines changed: 423 additions & 0 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.camel.file;
2+
3+
import org.apache.camel.builder.RouteBuilder;
4+
5+
public class ContentBasedFileRouter extends RouteBuilder {
6+
7+
private static final String SOURCE_FOLDER = "src/test/source-folder";
8+
private static final String DESTINATION_FOLDER_TXT = "src/test/destination-folder-txt";
9+
private static final String DESTINATION_FOLDER_OTHER = "src/test/destination-folder-other";
10+
11+
@Override
12+
public void configure() throws Exception {
13+
from("file://" + SOURCE_FOLDER + "?delete=true").choice().when(simple("${file:ext} == 'txt'")).to("file://" + DESTINATION_FOLDER_TXT).otherwise().to("file://" + DESTINATION_FOLDER_OTHER);
14+
}
15+
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.camel.file;
2+
3+
import org.apache.camel.Exchange;
4+
import org.apache.camel.LoggingLevel;
5+
import org.apache.camel.Processor;
6+
import org.apache.camel.builder.RouteBuilder;
7+
8+
public class DeadLetterChannelFileRouter extends RouteBuilder {
9+
private static final String SOURCE_FOLDER = "src/test/source-folder";
10+
11+
@Override
12+
public void configure() throws Exception {
13+
errorHandler(deadLetterChannel("log:dead?level=ERROR").maximumRedeliveries(3).redeliveryDelay(1000).retryAttemptedLogLevel(LoggingLevel.ERROR));
14+
15+
from("file://" + SOURCE_FOLDER + "?delete=true").process(new Processor() {
16+
@Override
17+
public void process(Exchange exchange) throws Exception {
18+
throw new IllegalArgumentException("Exception thrown!");
19+
}
20+
});
21+
}
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.camel.file;
2+
3+
import org.apache.camel.Exchange;
4+
import org.apache.camel.builder.RouteBuilder;
5+
6+
public class MessageTranslatorFileRouter extends RouteBuilder {
7+
private static final String SOURCE_FOLDER = "src/test/source-folder";
8+
private static final String DESTINATION_FOLDER = "src/test/destination-folder";
9+
10+
@Override
11+
public void configure() throws Exception {
12+
from("file://" + SOURCE_FOLDER + "?delete=true").transform(body().append(header(Exchange.FILE_NAME))).to("file://" + DESTINATION_FOLDER);
13+
}
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.camel.file;
2+
3+
import org.apache.camel.builder.RouteBuilder;
4+
5+
public class MulticastFileRouter extends RouteBuilder {
6+
private static final String SOURCE_FOLDER = "src/test/source-folder";
7+
private static final String DESTINATION_FOLDER_WORLD = "src/test/destination-folder-world";
8+
private static final String DESTINATION_FOLDER_HELLO = "src/test/destination-folder-hello";
9+
10+
@Override
11+
public void configure() throws Exception {
12+
from("file://" + SOURCE_FOLDER + "?delete=true").multicast().to("direct:append", "direct:prepend").end();
13+
14+
from("direct:append").transform(body().append("World")).to("file://" + DESTINATION_FOLDER_WORLD);
15+
16+
from("direct:prepend").transform(body().prepend("Hello")).to("file://" + DESTINATION_FOLDER_HELLO);
17+
}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.camel.file;
2+
3+
import org.apache.camel.Exchange;
4+
import org.apache.camel.builder.RouteBuilder;
5+
6+
public class SplitterFileRouter extends RouteBuilder {
7+
private static final String SOURCE_FOLDER = "src/test/source-folder";
8+
private static final String DESTINATION_FOLDER = "src/test/destination-folder";
9+
10+
@Override
11+
public void configure() throws Exception {
12+
13+
from("file://" + SOURCE_FOLDER + "?delete=true").split(body().convertToString().tokenize("\n")).setHeader(Exchange.FILE_NAME, body()).to("file://" + DESTINATION_FOLDER);
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
5+
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
6+
7+
<bean id="contentBasedFileRouter" class="org.baeldung.camel.file.ContentBasedFileRouter" />
8+
9+
<camelContext xmlns="http://camel.apache.org/schema/spring">
10+
<routeBuilder ref="contentBasedFileRouter" />
11+
</camelContext>
12+
13+
</beans>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
5+
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
6+
7+
<bean id="deadLetterChannelFileRouter" class="org.baeldung.camel.file.DeadLetterChannelFileRouter" />
8+
9+
<camelContext xmlns="http://camel.apache.org/schema/spring">
10+
<routeBuilder ref="deadLetterChannelFileRouter" />
11+
</camelContext>
12+
13+
</beans>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
5+
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
6+
7+
<bean id="messageTranslatorFileRouter" class="org.baeldung.camel.file.MessageTranslatorFileRouter" />
8+
9+
<camelContext xmlns="http://camel.apache.org/schema/spring">
10+
<routeBuilder ref="messageTranslatorFileRouter" />
11+
</camelContext>
12+
13+
</beans>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
5+
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
6+
7+
<bean id="multicastFileRouter" class="org.baeldung.camel.file.MulticastFileRouter" />
8+
9+
<camelContext xmlns="http://camel.apache.org/schema/spring">
10+
<routeBuilder ref="multicastFileRouter" />
11+
</camelContext>
12+
13+
</beans>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
5+
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
6+
7+
<bean id="splitterFileRouter" class="org.baeldung.camel.file.SplitterFileRouter" />
8+
9+
<camelContext xmlns="http://camel.apache.org/schema/spring">
10+
<routeBuilder ref="splitterFileRouter" />
11+
</camelContext>
12+
13+
</beans>

0 commit comments

Comments
 (0)