Skip to content

Commit b5c7147

Browse files
BAEL-80 - spring integration
1 parent ce66553 commit b5c7147

4 files changed

Lines changed: 127 additions & 16 deletions

File tree

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xmlns:int="http://www.springframework.org/schema/integration"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
54
xmlns:file="http://www.springframework.org/schema/integration/file"
65
xmlns:ftp="http://www.springframework.org/schema/integration/ftp"
76
xmlns:mail="http://www.springframework.org/schema/integration/mail"
@@ -14,30 +13,68 @@
1413
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
1514
http://www.springframework.org/schema/integration/ftp
1615
http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd
17-
http://www.springframework.org/schema/integration/mail
16+
http://www.springframework.org/schema/integration/mail
1817
http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
19-
http://www.springframework.org/schema/integration/twitter
18+
http://www.springframework.org/schema/integration/twitter
2019
http://www.springframework.org/schema/integration/twitter/spring-integration-twitter.xsd">
2120

21+
<int:publish-subscribe-channel id="videoChannel" />
22+
23+
<int:bridge input-channel="videoChannel" output-channel="ftpOutbound" />
24+
<int:channel id="ftpOutbound" />
25+
<int:bridge input-channel="videoChannel" output-channel="emailOutbound" />
26+
<int:channel id="emailOutbound" />
27+
28+
29+
<int:bridge output-channel="twitterOutbound" input-channel="videoChannel" />
30+
31+
<int:channel id="twitterOutbound" />
32+
33+
<twitter:outbound-channel-adapter
34+
twitter-template="twitterTemplate" channel="twitterOutbound" />
35+
36+
<bean name="twitterTemplate"
37+
class="org.springframework.social.twitter.api.impl.TwitterTemplate">
38+
<constructor-arg index="0" value="${consumer-key}" />
39+
<constructor-arg index="1" value="${consumer-secret}" />
40+
<constructor-arg index="2" value="${access-token}" />
41+
<constructor-arg index="3" value="${access-token-secret}" />
42+
</bean>
43+
2244
<file:inbound-channel-adapter id="videoFolder"
23-
directory="C:\projects\baeldung\clean-start-tutorials\tutorials\spring-integration\src\main\resources\source"
24-
channel="videoChannel"
45+
directory="/studio/edits/video" channel="videoChannel"
2546
prevent-duplicates="true">
26-
<int:poller fixed-rate="1000"/>
47+
<int:poller fixed-rate="1000" />
2748
</file:inbound-channel-adapter>
2849

29-
<file:outbound-channel-adapter id="destFileFolder"
30-
directory="C:\projects\baeldung\clean-start-tutorials\tutorials\spring-integration\src\main\resources\destination"
31-
channel="videoChannel"
32-
>
33-
</file:outbound-channel-adapter>
50+
<mail:outbound-channel-adapter channel="emailOutbound"
51+
mail-sender="mailSender" />
52+
53+
<bean name="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
54+
<property name="host" value="smtp.gmail.com" />
55+
<property name="port" value="587" />
56+
<property name="username" value="yourUsername" />
57+
<property name="password" value="yourPassword" />
58+
</bean>
59+
60+
<ftp:outbound-channel-adapter channel="ftpOutbound"
61+
remote-directory="/news/archive/video/" session-factory="sessionFactory" />
62+
63+
3464

35-
<int:channel id="videoChannel"/>
65+
<bean name="sessionFactory"
66+
class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
67+
<property name="host" value="localhost" />
68+
<property name="port" value="587" />
69+
<property name="username" value="yourUsername" />
70+
<property name="password" value="yourPassword" />
71+
</bean>
3672

37-
<!-- <int:service-activator input-channel="videoChannel" output-channel="destFileFolder" method="handleMessage"
38-
ref="customActivator"/>
73+
<int:bridge input-channel="videoChannel" output-channel="activatorChannel"/>
74+
<int:channel id="activatorChannel"/>
3975

40-
<bean name="customActivator" class="com.baeldung.samples.endpoints.ActivatorImpl"/>-->
76+
<int:service-activator input-channel="activatorChannel" method="handleMessage" ref="customActivator"/>
4177

78+
<bean name="customActivator" class="com.baeldung.samples.endpoints.ActivatorImpl"/>
4279

4380
</beans>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
xmlns:int="http://www.springframework.org/schema/integration"
5+
xmlns:file="http://www.springframework.org/schema/integration/file"
6+
xmlns:ftp="http://www.springframework.org/schema/integration/ftp"
7+
xmlns:mail="http://www.springframework.org/schema/integration/mail"
8+
xmlns:twitter="http://www.springframework.org/schema/integration/twitter"
9+
xsi:schemaLocation="http://www.springframework.org/schema/beans
10+
http://www.springframework.org/schema/beans/spring-beans.xsd
11+
http://www.springframework.org/schema/integration
12+
http://www.springframework.org/schema/integration/spring-integration.xsd
13+
http://www.springframework.org/schema/integration/file
14+
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
15+
http://www.springframework.org/schema/integration/ftp
16+
http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd
17+
http://www.springframework.org/schema/integration/mail
18+
http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
19+
http://www.springframework.org/schema/integration/twitter
20+
http://www.springframework.org/schema/integration/twitter/spring-integration-twitter.xsd">
21+
22+
<file:inbound-channel-adapter id="videoFolder"
23+
directory="C:\projects\baeldung\clean-start-tutorials\tutorials\spring-integration\src\main\resources\source"
24+
channel="videoChannel"
25+
prevent-duplicates="true">
26+
<int:poller fixed-rate="1000"/>
27+
</file:inbound-channel-adapter>
28+
29+
<file:outbound-channel-adapter id="destFileFolder"
30+
directory="C:\projects\baeldung\clean-start-tutorials\tutorials\spring-integration\src\main\resources\destination"
31+
32+
>
33+
</file:outbound-channel-adapter>
34+
35+
<int:publish-subscribe-channel id="videoChannel" />
36+
37+
<int:channel id="emailOutbound" />
38+
39+
<mail:outbound-channel-adapter channel="emailOutbound"
40+
mail-sender="mailSender" />
41+
42+
<file:file-to-bytes-transformer
43+
input-channel="videoChannel"
44+
output-channel="emailOutbound"
45+
delete-files="false"/>
46+
47+
<mail:header-enricher input-channel="videoChannel" output-channel="emailOutbound">
48+
<mail:attachment-filename value="test"/>
49+
</mail:header-enricher>
50+
51+
<bean name="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
52+
<property name="host" value="smtp.gmail.com" />
53+
<property name="port" value="587" />
54+
<property name="username" value="${username}" />
55+
<property name="password" value="${password}" />
56+
</bean>
57+
58+
<int:bridge input-channel="videoChannel" output-channel="destFileFolder" />
59+
<int:bridge input-channel="videoChannel" output-channel="emailOutbound" />
60+
61+
62+
</beans>
760 KB
Loading

‎spring-integration/src/test/java/com/baeldung/samples/FileCopyTest.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,17 @@ public void test() throws InterruptedException {
4444
Thread.sleep(5000);
4545

4646

47+
}
48+
49+
@Test
50+
public void publish() throws InterruptedException {
51+
52+
53+
final AbstractApplicationContext context =
54+
new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/spring-integration-file-publish-context.xml");
55+
56+
Thread.sleep(15000);
57+
58+
4759
}
4860
}

0 commit comments

Comments
 (0)