Browse files

Updated

  • Loading branch information...
1 parent 33f6ba3 commit 609692cde9efa442f07a149398d8aec2e2002d06 @mminella committed Feb 15, 2012
Showing with 273 additions and 224 deletions.
  1. BIN Deck.pptx
  2. +5 −2 examples/adminJob/.classpath
  3. +2 −1 examples/adminJob/.settings/com.springsource.sts.config.flow.prefs
  4. +1 −1 examples/adminJob/pom.xml
  5. +0 −42 examples/adminJob/src/main/java/com/apress/springbatch/chapter6/HelloWorld.java
  6. BIN examples/adminJob/src/main/java/com/michaelminella/springbatch/.DS_Store
  7. BIN examples/adminJob/src/main/java/com/michaelminella/springbatch/domain/.DS_Store
  8. +1 −1 ...b/src/main/java/com/{apress/springbatch/chapter6 → michaelminella/springbatch/domain}/Person.java
  9. BIN examples/adminJob/src/main/java/com/michaelminella/springbatch/tasklet/.DS_Store
  10. +1 −1 ...va/com/{apress/springbatch/chapter6 → michaelminella/springbatch/tasklet}/DeleteFilesTasklet.java
  11. +1 −1 ...ain/java/com/{apress/springbatch/chapter6 → michaelminella/springbatch/tasklet}/JMXJobRunner.java
  12. +1 −1 ...java/com/{apress/springbatch/chapter6 → michaelminella/springbatch/tasklet}/JMXJobRunnerImpl.java
  13. +1 −1 ...ress/springbatch/chapter6 → michaelminella/springbatch/tasklet}/SpringBatchQuartzJobLauncher.java
  14. +1 −3 examples/adminJob/src/main/resources/META-INF/spring/batch/override/launch-context.xml
  15. BIN examples/adminJob/src/main/resources/jobs/.DS_Store
  16. +0 −59 examples/adminJob/src/main/resources/jobs/copyJob.xml
  17. +1 −1 examples/adminJob/src/main/resources/jobs/deleteFilesJob.xml
  18. +0 −20 examples/adminJob/src/main/resources/jobs/helloWorld.xml
  19. +0 −79 examples/copyJob/src/main/java/com/michaelminella/springbatch/domain/Customer.hibernate
  20. +32 −11 examples/copyJob/src/main/java/com/michaelminella/springbatch/domain/Customer.java
  21. +52 −0 examples/copyJob/src/main/java/com/michaelminella/springbatch/domain/Target.java
  22. +38 −0 ...ples/copyJob/src/main/java/com/michaelminella/springbatch/processors/TargetScanItemProcessor.java
  23. +38 −0 examples/copyJob/src/main/java/com/michaelminella/springbatch/tasklet/LoadPortsTasklet.java
  24. +13 −0 examples/copyJob/src/main/resources/META-INF/business.sql
  25. +1 −0 examples/copyJob/src/main/resources/hibernate.cfg.xml
  26. +84 −0 examples/copyJob/src/main/resources/jobs/vulnScannerJob.xml
View
BIN Deck.pptx
Binary file not shown.
View
7 examples/adminJob/.classpath
@@ -2,10 +2,13 @@
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
+ </attributes>
+ </classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="target/classes"/>
View
3 examples/adminJob/.settings/com.springsource.sts.config.flow.prefs
@@ -1,7 +1,8 @@
-#Fri Apr 29 21:23:35 CDT 2011
+#Wed Feb 15 13:33:48 CST 2012
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/batch\:/job-execution/src/main/resources/jobs/copyJob.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="JobModelElement" type\="job">\n<structure end\="2594" endstart\="2588" start\="2438" startend\="2456"/>\n<bounds height\="118" width\="104" x\="15" y\="17"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/batch\:/job-execution/src/main/resources/jobs/deleteFilesJob.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="StepModelElement" type\="step">\n<structure end\="701" endstart\="688" start\="608" startend\="641"/>\n<bounds height\="34" width\="113" x\="17" y\="19"/>\n</element>\n<element clazz\="JobModelElement" type\="job">\n<structure end\="933" endstart\="921" start\="807" startend\="866"/>\n<bounds height\="128" width\="136" x\="148" y\="19"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/batch\:/job-execution/src/main/resources/jobs/helloWorld.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="StepModelElement" type\="step">\n<structure end\="732" endstart\="719" start\="648" startend\="680"/>\n<bounds height\="34" width\="113" x\="17" y\="19"/>\n</element>\n<element clazz\="JobModelElement" type\="job">\n<structure end\="832" endstart\="820" start\="735" startend\="766"/>\n<bounds height\="128" width\="143" x\="148" y\="19"/>\n</element>\n</graph>
+//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/batch\:/job-execution/src/main/resources/jobs/vulnScannerJob.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="StepModelElement" type\="step">\n<structure end\="1405" endstart\="1392" start\="1320" startend\="1347"/>\n<bounds height\="34" width\="84" x\="174" y\="19"/>\n</element>\n<element clazz\="StepModelElement" type\="step">\n<structure end\="1581" endstart\="1568" start\="1409" startend\="1438"/>\n<bounds height\="34" width\="86" x\="278" y\="19"/>\n</element>\n<element clazz\="JobModelElement" type\="job">\n<structure end\="1975" endstart\="1963" start\="1757" startend\="1788"/>\n<bounds height\="178" width\="145" x\="15" y\="19"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/batch\:/job-execution/src/main/resources/launch-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph/>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/batch\:/simple-cli-archetype/src/main/resources/jobs/helloWorld.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="StepModelElement" type\="step">\n<structure end\="846" endstart\="833" start\="752" startend\="784"/>\n<bounds height\="34" width\="113" x\="17" y\="19"/>\n</element>\n<element clazz\="JobModelElement" type\="job">\n<structure end\="960" endstart\="948" start\="853" startend\="884"/>\n<bounds height\="128" width\="143" x\="148" y\="19"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/batch\:/simple-cli-archetype/src/main/resources/launch-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph/>
View
2 examples/adminJob/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>com.apress.springbatch.chapter6</groupId>
+ <groupId>com.michaelminella.springbatch.</groupId>
<artifactId>job-execution</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
View
42 examples/adminJob/src/main/java/com/apress/springbatch/chapter6/HelloWorld.java
@@ -1,42 +0,0 @@
-package com.apress.springbatch.chapter6;
-
-import java.util.List;
-
-import org.springframework.batch.core.JobInstance;
-import org.springframework.batch.core.StepContribution;
-import org.springframework.batch.core.explore.JobExplorer;
-import org.springframework.batch.core.scope.context.ChunkContext;
-import org.springframework.batch.core.step.tasklet.Tasklet;
-import org.springframework.batch.repeat.RepeatStatus;
-
-public class HelloWorld implements Tasklet {
-
- private static final String HELLO = "Hello, %s!";
- private static final String WELCOME = "Welcome back %s!";
- private static final String JOB_NAME = "helloWorldJob";
-
- private JobExplorer explorer;
-
- public RepeatStatus execute(StepContribution stepContribution,
- ChunkContext chunkContext) throws Exception {
- List<JobInstance> executions = explorer
- .getJobInstances(JOB_NAME, 0, Integer.MAX_VALUE);
- String name = (String) chunkContext.getStepContext().getJobParameters()
- .get("name");
-
- if (executions.size() > 1) {
- System.out.println(String.format(WELCOME, name));
- } else {
- System.out.println(String.format(HELLO, name));
- }
- return RepeatStatus.FINISHED;
- }
-
- public JobExplorer getExplorer() {
- return explorer;
- }
-
- public void setExplorer(JobExplorer explorer) {
- this.explorer = explorer;
- }
-}
View
BIN examples/adminJob/src/main/java/com/michaelminella/springbatch/.DS_Store
Binary file not shown.
View
BIN examples/adminJob/src/main/java/com/michaelminella/springbatch/domain/.DS_Store
Binary file not shown.
View
2 ...m/apress/springbatch/chapter6/Person.java → ...aelminella/springbatch/domain/Person.java
@@ -1,4 +1,4 @@
-package com.apress.springbatch.chapter6;
+package com.michaelminella.springbatch.domain;
public class Person {
View
BIN examples/adminJob/src/main/java/com/michaelminella/springbatch/tasklet/.DS_Store
Binary file not shown.
View
2 ...ingbatch/chapter6/DeleteFilesTasklet.java → ...ringbatch/tasklet/DeleteFilesTasklet.java
@@ -1,4 +1,4 @@
-package com.apress.springbatch.chapter6;
+package com.michaelminella.springbatch.tasklet;
import java.io.File;
import java.util.Date;
View
2 ...ss/springbatch/chapter6/JMXJobRunner.java → ...lla/springbatch/tasklet/JMXJobRunner.java
@@ -1,4 +1,4 @@
-package com.apress.springbatch.chapter6;
+package com.michaelminella.springbatch.tasklet;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.launch.JobInstanceAlreadyExistsException;
View
2 ...pringbatch/chapter6/JMXJobRunnerImpl.java → ...springbatch/tasklet/JMXJobRunnerImpl.java
@@ -1,4 +1,4 @@
-package com.apress.springbatch.chapter6;
+package com.michaelminella.springbatch.tasklet;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.launch.JobInstanceAlreadyExistsException;
View
2 ...hapter6/SpringBatchQuartzJobLauncher.java → ...tasklet/SpringBatchQuartzJobLauncher.java
@@ -1,4 +1,4 @@
-package com.apress.springbatch.chapter6;
+package com.michaelminella.springbatch.tasklet;
import java.util.List;
import java.util.Map;
View
4 examples/adminJob/src/main/resources/META-INF/spring/batch/override/launch-context.xml
@@ -36,7 +36,7 @@
<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass"
- value="com.apress.springbatch.chapter6.SpringBatchQuartzJobLauncher" />
+ value="com.michaelminella.springbatch.tasklet.SpringBatchQuartzJobLauncher" />
<property name="group" value="file-maintenence" />
<property name="jobDataAsMap">
<util:map>
@@ -81,8 +81,6 @@
<property name="password" value="${batch.jdbc.password}" />
</bean>
- <!-- bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/ -->
-
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
lazy-init="true">
View
BIN examples/adminJob/src/main/resources/jobs/.DS_Store
Binary file not shown.
View
59 examples/adminJob/src/main/resources/jobs/copyJob.xml
@@ -1,59 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans:beans xmlns="http://www.springframework.org/schema/batch"
- xmlns:beans="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/batch
- http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
-
- <beans:bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
- <beans:property name="lineMapper">
- <beans:bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
- <beans:property name="lineTokenizer">
- <beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
- <beans:property name="delimiter" value=","/>
- <beans:property name="names" value="id,name,value" />
- </beans:bean>
- </beans:property>
- <beans:property name="fieldSetMapper">
- <beans:bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
- <beans:property name="targetType" value="com.apress.springbatch.chapter5.Person" />
- </beans:bean>
- </beans:property>
- </beans:bean>
- </beans:property>
- <beans:property name="resource" ref="inputFile" />
- </beans:bean>
-
- <beans:bean id="inputFile" class="org.springframework.core.io.FileSystemResource" scope="step">
- <beans:constructor-arg value="#{jobParameters[inputFile]}"/>
- </beans:bean>
-
- <beans:bean id="outputFile" class="org.springframework.core.io.FileSystemResource" scope="step">
- <beans:constructor-arg value="#{jobParameters[outputFile]}"/>
- </beans:bean>
-
- <beans:bean id="itemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
- <beans:property name="resource" ref="outputFile" />
- <beans:property name="lineAggregator">
- <beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
- <beans:property name="delimiter" value=";"/>
- <beans:property name="fieldExtractor">
- <beans:bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
- <beans:property name="names" value="value,name,id"/>
- </beans:bean>
- </beans:property>
- </beans:bean>
- </beans:property>
- </beans:bean>
-
- <job id="copyJob">
- <step id="step1">
- <tasklet>
- <chunk reader="itemReader" writer="itemWriter" commit-interval="1"/>
- </tasklet>
- </step>
- </job>
-
-</beans:beans>
View
2 examples/adminJob/src/main/resources/jobs/deleteFilesJob.xml
@@ -6,7 +6,7 @@
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
- <bean id="deleteFilesTasklet" class="com.apress.springbatch.chapter6.DeleteFilesTasklet" />
+ <bean id="deleteFilesTasklet" class="com.michaelminella.springbatch.tasklet.DeleteFilesTasklet" />
<batch:step id="deleteFilesStep">
<batch:tasklet ref="deleteFilesTasklet" />
View
20 examples/adminJob/src/main/resources/jobs/helloWorld.xml
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns:batch="http://www.springframework.org/schema/batch"
- xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/batch
- http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
-
- <bean id="helloWorld" class="com.apress.springbatch.chapter6.HelloWorld">
- <property name="explorer" ref="jobExplorer" />
- </bean>
-
- <batch:step id="helloWorldStep">
- <batch:tasklet ref="helloWorld" />
- </batch:step>
-
- <batch:job id="helloWorldJob6">
- <batch:step id="step1" parent="helloWorldStep" />
- </batch:job>
-</beans>
View
79 examples/copyJob/src/main/java/com/michaelminella/springbatch/domain/Customer.hibernate
@@ -1,79 +0,0 @@
-package com.michaelminella.springbatch.domain;
-
-import java.io.Serializable;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-@Entity
-@Table(name="customer")
-public class Customer implements Serializable {
- private static final long serialVersionUID = 1L;
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private long id;
- private String firstName;
- private String lastName;
- private String address;
- private String city;
- private String state;
- private String zip;
-
- public String getFirstName() {
- return firstName;
- }
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- public String getLastName() {
- return lastName;
- }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- public String getAddress() {
- return address;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public String getCity() {
- return city;
- }
- public void setCity(String city) {
- this.city = city;
- }
- public String getState() {
- return state;
- }
- public void setState(String state) {
- this.state = state;
- }
- public String getZip() {
- return zip;
- }
- public void setZip(String zip) {
- this.zip = zip;
- }
- public long getId() {
- return id;
- }
- public void setId(long id) {
- this.id = id;
- }
- @Override
- public String toString() {
- StringBuilder output = new StringBuilder();
-
- output.append(firstName + " " + lastName + "\n");
- output.append(address + "\n");
- output.append(city + ", " + state + "\n");
- output.append(zip);
-
- return output.toString();
- }
-}
View
43 examples/copyJob/src/main/java/com/michaelminella/springbatch/domain/Customer.java
@@ -1,13 +1,28 @@
package com.michaelminella.springbatch.domain;
-public class Customer {
- private String firstName;
- private String lastName;
- private String address;
- private String city;
- private String state;
- private String zip;
-
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="customer")
+public class Customer implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private long id;
+ private String firstName;
+ private String lastName;
+ private String address;
+ private String city;
+ private String state;
+ private String zip;
+
public String getFirstName() {
return firstName;
}
@@ -44,15 +59,21 @@ public String getZip() {
public void setZip(String zip) {
this.zip = zip;
}
+ public long getId() {
+ return id;
+ }
+ public void setId(long id) {
+ this.id = id;
+ }
@Override
public String toString() {
StringBuilder output = new StringBuilder();
-
+
output.append(firstName + " " + lastName + "\n");
output.append(address + "\n");
output.append(city + ", " + state + "\n");
output.append(zip);
-
+
return output.toString();
}
-}
+}
View
52 examples/copyJob/src/main/java/com/michaelminella/springbatch/domain/Target.java
@@ -0,0 +1,52 @@
+package com.michaelminella.springbatch.domain;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="target")
+public class Target {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private long id;
+ // in a real environment this should be stored as a long
+ private String ip;
+ private int port;
+ private boolean connected;
+ private String banner;
+
+ public long getId() {
+ return id;
+ }
+ public void setId(long id) {
+ this.id = id;
+ }
+ public String getIp() {
+ return ip;
+ }
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+ public int getPort() {
+ return port;
+ }
+ public void setPort(int port) {
+ this.port = port;
+ }
+ public String getBanner() {
+ return banner;
+ }
+ public void setBanner(String banner) {
+ this.banner = banner;
+ }
+ public boolean isConnected() {
+ return this.connected;
+ }
+ public void setConnected(boolean con) {
+ this.connected = con;
+ }
+}
View
38 ...yJob/src/main/java/com/michaelminella/springbatch/processors/TargetScanItemProcessor.java
@@ -0,0 +1,38 @@
+package com.michaelminella.springbatch.processors;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.net.Socket;
+
+import org.springframework.batch.item.ItemProcessor;
+
+import com.michaelminella.springbatch.domain.Target;
+
+public class TargetScanItemProcessor implements ItemProcessor<Target, Target> {
+
+ public Target process(Target curTarget) throws Exception {
+ try {
+ System.out.println("About to check: " + curTarget.getIp() + ":" + curTarget.getPort());
+ Socket socket = new Socket(curTarget.getIp(), curTarget.getPort());
+ socket.setSoTimeout(2000);
+ curTarget.setConnected(true);
+ BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+
+ StringBuilder bannerBuffer = new StringBuilder();
+ String banner;
+
+ while ((banner = input.readLine()) != null) {
+ bannerBuffer.append(banner);
+ }
+
+ curTarget.setBanner(bannerBuffer.toString());
+
+ input.close();
+ socket.close();
+ } catch (Throwable ignore) {
+ }
+
+ return curTarget;
+ }
+}
View
38 examples/copyJob/src/main/java/com/michaelminella/springbatch/tasklet/LoadPortsTasklet.java
@@ -0,0 +1,38 @@
+package com.michaelminella.springbatch.tasklet;
+
+import org.springframework.batch.core.StepContribution;
+import org.springframework.batch.core.scope.context.ChunkContext;
+import org.springframework.batch.core.step.tasklet.Tasklet;
+import org.springframework.batch.repeat.RepeatStatus;
+import org.springframework.orm.hibernate3.HibernateTemplate;
+
+import com.michaelminella.springbatch.domain.Target;
+
+public class LoadPortsTasklet extends HibernateTemplate implements Tasklet {
+
+ private String ipAddress;
+ private boolean fullPortScan;
+
+ public RepeatStatus execute(StepContribution arg0, ChunkContext arg1)
+ throws Exception {
+
+ if(fullPortScan) {
+ for(int i = 1; i < 1025; i++) {
+ Target target = new Target();
+ target.setIp(ipAddress);
+ target.setPort(i);
+ save(target);
+ }
+ }
+
+ return RepeatStatus.FINISHED;
+ }
+
+ public void setIpAddress(String address) {
+ ipAddress = address;
+ }
+
+ public void setFullPortScan(boolean scan) {
+ fullPortScan = scan;
+ }
+}
View
13 examples/copyJob/src/main/resources/META-INF/business.sql
@@ -1,4 +1,17 @@
use spring_batch;
+-- -----------------------------------------------------
+-- Table Target
+-- -----------------------------------------------------
+DROP TABLE IF EXISTS target ;
+
+CREATE TABLE target (
+ id INT NOT NULL AUTO_INCREMENT ,
+ ip VARCHAR(45) NOT NULL ,
+ port INT NOT NULL ,
+ connected INT,
+ banner VARCHAR(255),
+ PRIMARY KEY (id) )
+ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table Customer
View
1 examples/copyJob/src/main/resources/hibernate.cfg.xml
@@ -5,5 +5,6 @@
<hibernate-configuration>
<session-factory>
<mapping class="com.michaelminella.springbatch.domain.Customer"/>
+ <mapping class="com.michaelminella.springbatch.domain.Target"/>
</session-factory>
</hibernate-configuration>
View
84 examples/copyJob/src/main/resources/jobs/vulnScannerJob.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:batch="http://www.springframework.org/schema/batch"
+ xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/batch
+ http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
+
+ <!-- Command to execute this job. From the target directory of this project:
+ java -jar copy-file-0.0.1-SNAPSHOT.jar jobs/vulnScannerJob.xml vulnScannerJob ipAddress=<IPADDRESS_OR_DOMAIN> outputFile=<LOCATION_OF_OUTPUT>
+ -->
+
+ <import resource="../launch-context-with-hibernate.xml" />
+
+ <bean id="loadPortsTasklet" class="com.michaelminella.springbatch.tasklet.LoadPortsTasklet" scope="step">
+ <property name="fullPortScan" value="true"/>
+ <property name="ipAddress" value="#{jobParameters[ipAddress]}"/>
+ <property name="sessionFactory" ref="sessionFactory"/>
+ </bean>
+
+ <bean id="targetItemReader"
+ class="org.springframework.batch.item.database.HibernateCursorItemReader" scope="step">
+ <property name="sessionFactory" ref="sessionFactory"/>
+ <property name="queryString" value="from Target where ip = :ipAddress"/>
+ <property name="parameterValues">
+ <map>
+ <entry key="ipAddress" value="#{jobParameters[ipAddress]}"/>
+ </map>
+ </property>
+ </bean>
+
+ <bean id="exportItemReader"
+ class="org.springframework.batch.item.database.HibernateCursorItemReader" scope="step">
+ <property name="sessionFactory" ref="sessionFactory"/>
+ <property name="queryString" value="from Target where connected is true"/>
+ </bean>
+
+ <bean id="targetWriter" class="org.springframework.batch.item.database.HibernateItemWriter">
+ <property name="sessionFactory" ref="sessionFactory"/>
+ </bean>
+
+ <bean id="targetProcessor" class="com.michaelminella.springbatch.processors.TargetScanItemProcessor"/>
+
+
+ <bean id="outputFile" class="org.springframework.core.io.FileSystemResource" scope="step">
+ <constructor-arg value="#{jobParameters[outputFile]}"/>
+ </bean>
+
+ <bean id="xmlOutputWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
+ <property name="resource" ref="outputFile" />
+ <property name="marshaller" ref="targetMashaller" />
+ <property name="rootTagName" value="openTargets" />
+ </bean>
+
+ <bean id="targetMashaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
+ <property name="aliases">
+ <map>
+ <entry key="target" value="com.michaelminella.springbatch.domain.Target" />
+ </map>
+ </property>
+ </bean>
+
+ <batch:step id="loadPorts">
+ <batch:tasklet ref="loadPortsTasklet" />
+ </batch:step>
+
+ <batch:step id="scanPorts">
+ <batch:tasklet>
+ <batch:chunk reader="targetItemReader" processor="targetProcessor" writer="targetWriter" commit-interval="10"/>
+ </batch:tasklet>
+ </batch:step>
+
+ <batch:step id="generateResults">
+ <batch:tasklet>
+ <batch:chunk reader="exportItemReader" writer="xmlOutputWriter" commit-interval="10"/>
+ </batch:tasklet>
+ </batch:step>
+
+ <batch:job id="vulnScannerJob">
+ <batch:step id="step1" parent="loadPorts" next="step2"/>
+ <batch:step id="step2" parent="scanPorts" next="step3"/>
+ <batch:step id="step3" parent="generateResults"/>
+ </batch:job>
+</beans>

0 comments on commit 609692c

Please sign in to comment.