Skip to content

Commit

Permalink
105 added integration example
Browse files Browse the repository at this point in the history
  • Loading branch information
iuliana committed Jul 30, 2017
1 parent b2707f5 commit 6a7bcd2
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 179 deletions.
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ext {
springAmqpVersion = '2.0.0.M4'
springSecurityVersion = '5.0.0.M2'
springBatchVersion = '4.0.0.M3'
springIntegrationVersion = '5.0.0.M6'
springBatchIntegrationVersion = '4.0.0.M3'

//logging libs
slf4jVersion = '1.7.25'
Expand Down Expand Up @@ -70,8 +72,9 @@ ext {
springSecurityTest: "org.springframework.security:spring-security-test:$springSecurityVersion",
webSocket : "org.springframework:spring-websocket:$springVersion",
messaging : "org.springframework:spring-messaging:$springVersion",
batchCore : "org.springframework.batch:spring-batch-core:$springBatchVersion"

batchCore : "org.springframework.batch:spring-batch-core:$springBatchVersion",
batchIntegration : "org.springframework.batch:spring-batch-integration:$springBatchIntegrationVersion",
integrationFile : "org.springframework.integration:spring-integration-file:$springIntegrationVersion"

]

Expand Down Expand Up @@ -101,7 +104,7 @@ ext {
starterRabbitmq : "org.springframework.boot:spring-boot-starter-amqp:$bootVersion",
starterThyme : "org.springframework.boot:spring-boot-starter-thymeleaf:$bootVersion",
starterSecurity : "org.springframework.boot:spring-boot-starter-security:$bootVersion",
starterBatch : "org.springframework.boot:spring-boot-starter-batch:$bootVersion"
starterBatch : "org.springframework.boot:spring-boot-starter-batch:$bootVersion"

]

Expand Down Expand Up @@ -159,7 +162,7 @@ ext {
db = [
mysql : "mysql:mysql-connector-java:$mysqlVersion",
derby : "org.apache.derby:derby:$derbyVersion",
dbcp2 : "org.apache.commons:commons-dbcp2:$dbcpVersion",
dbcp2 : "org.apache.commons:commons-dbcp2:$dbcpVersion",
dbcp : "commons-dbcp:commons-dbcp:1.4",
h2 : "com.h2database:h2:$h2Version",
hsqldb: "org.hsqldb:hsqldb:2.4.0"
Expand Down
11 changes: 11 additions & 0 deletions chapter18/integration/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dependencies {
compile db.h2, db.dbcp2, spring.batchIntegration, spring.integrationFile
}
jar {
manifest {
attributes("Created-By" : "Iuliana Cosmina",
"Specification-Title": "Pro Spring 5",
"Main-Class" : "com.apress.prospring5.ch18.FileWatcherDemo",
"Class-Path" : configurations.compile.collect { it.getName() }.join(' '))
}
}
93 changes: 0 additions & 93 deletions chapter18/integration/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.apress.prospring5.ch18;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.GenericXmlApplicationContext;

public class FileWatcherDemo {

private static Logger logger = LoggerFactory.getLogger(FileWatcherDemo.class);

public static void main(String... args) throws Exception {
GenericXmlApplicationContext ctx
= new GenericXmlApplicationContext("/spring/singerJob.xml");
assert (ctx != null);
logger.info("Application started...");
System.in.read();
ctx.close();
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.apress.prospring4.ch18;
package com.apress.prospring5.ch18;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParametersBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.apress.prospring4.ch18;
package com.apress.prospring5.ch18;

public class Person {

public class Singer {
private String firstName;
private String lastName;
//best song :D
private String song;

public void setFirstName(String firstName) {
this.firstName = firstName;
Expand All @@ -20,8 +23,16 @@ public String getLastName() {
return lastName;
}

public String getSong() {
return song;
}

public void setSong(String song) {
this.song = song;
}

@Override
public String toString() {
return "firstName: " + firstName + ", lastName: " + lastName;
return "firstName: " + firstName + ", lastName: " + lastName + ", song: " + song;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.apress.prospring5.ch18;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;

@Component("itemProcessor")
public class SingerItemProcessor implements ItemProcessor<Singer, Singer> {
private static Logger logger = LoggerFactory.getLogger(SingerItemProcessor.class);

@Override
public Singer process(Singer singer) throws Exception {
String firstName = singer.getFirstName().toUpperCase();
String lastName = singer.getLastName().toUpperCase();
String song = singer.getSong().toUpperCase();

Singer transformedSinger = new Singer();
transformedSinger.setFirstName(firstName);
transformedSinger.setLastName(lastName);
transformedSinger.setSong(song);

logger.info("Transformed singer: " + singer + " Into: " + transformedSinger);

return transformedSinger;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.apress.prospring5.ch18;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.stereotype.Component;

@Component
public class StepExecutionStatsListener extends StepExecutionListenerSupport {

public static Logger logger = LoggerFactory.getLogger(StepExecutionStatsListener.class);

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
logger.info("--> Wrote: " + stepExecution.getWriteCount()
+ " items in step: " + stepExecution.getStepName());
return null;
}
}
Empty file.

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions chapter18/integration/src/main/resources/log4j.properties

This file was deleted.

21 changes: 21 additions & 0 deletions chapter18/integration/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>

<logger name="com.apress.prospring5.ch18" level="debug"/>

<logger name="org.springframework" level="info"/>

<root level="info">
<appender-ref ref="console" />
</root>
</configuration>
Loading

0 comments on commit 6a7bcd2

Please sign in to comment.