-
Notifications
You must be signed in to change notification settings - Fork 53
My example! #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kingharrison
wants to merge
10
commits into
IBM:master
Choose a base branch
from
kingharrison:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
My example! #195
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
126ed39
Create pom.xml
kingharrison 07348c0
Create CSVExample.java
kingharrison 3857088
Create log42j2.properties
kingharrison 29a51ae
fixup tab-delimited example
ThePrez 7f0d27b
fileLocation readability (not to confuse with /tmp)
ThePrez 6f05276
remove unused imports
ThePrez 2cc05c7
have route only run once
ThePrez d05a754
remove jt400 from pom.xml
ThePrez b4b1fe6
pull context stop into own route
ThePrez 197b21c
rename CSVExample dir
ThePrez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| <?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>ibmi.example</groupId> | ||
| <artifactId>ibm-i-csv-example</artifactId> | ||
| <packaging>jar</packaging> | ||
| <version>1.0</version> | ||
|
|
||
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
| <camel.version>3.11.0</camel.version> | ||
| </properties> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-parent</artifactId> | ||
| <version>${camel.version}</version> | ||
| <scope>import</scope> | ||
| <type>pom</type> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-core</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-main</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-fop</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-as2</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-bindy</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-ftp</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel.springboot</groupId> | ||
| <artifactId>camel-spring-boot</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>net.sf.jt400</groupId> | ||
| <artifactId>jt400</artifactId> | ||
| <version>10.6</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-jdbc</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-jt400</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-stream</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
ThePrez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-pdf</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-componentdsl</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-csv</artifactId> | ||
| <version>${camel.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-api</artifactId> | ||
| <scope>runtime</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-core</artifactId> | ||
| <scope>runtime</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-slf4j-impl</artifactId> | ||
| <scope>runtime</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <defaultGoal>install</defaultGoal> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <version>3.8.1</version> | ||
| <configuration> | ||
| <source>1.8</source> | ||
| <target>1.8</target> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-resources-plugin</artifactId> | ||
| <version>3.2.0</version> | ||
| <configuration> | ||
| <encoding>UTF-8</encoding> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>exec-maven-plugin</artifactId> | ||
| <version>3.0.0</version> | ||
| <configuration> | ||
| <mainClass>ibmi.example.CSVExample</mainClass> | ||
| <includePluginDependencies>false</includePluginDependencies> | ||
| </configuration> | ||
| </plugin> | ||
|
|
||
| </plugins> | ||
| </build> | ||
|
|
||
| <name>CSV Creation Example</name> | ||
| </project> | ||
178 changes: 178 additions & 0 deletions
178
camel/CSVExample/src/main/java/ibmi/example/CSVExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| package ibmi.example; | ||
|
|
||
| /** | ||
| * Standard imported libraries | ||
| */ | ||
| import org.apache.camel.CamelContext; | ||
| import org.apache.camel.builder.RouteBuilder; | ||
| import org.apache.camel.impl.DefaultCamelContext; | ||
| import org.springframework.stereotype.Component; | ||
| import org.apache.camel.dataformat.csv.CsvDataFormat; | ||
|
|
||
| import java.sql.Date; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * IBM i specific imported libraries for connecting to the DB2 database | ||
| */ | ||
| import com.ibm.as400.access.AS400JDBCDataSource; | ||
|
|
||
| /** | ||
| * This is a CSV example for creating a CSV from a query and doing different operations with it as a result | ||
| */ | ||
| public class CSVExample { | ||
|
|
||
| public static void main(final String... args) throws Exception { | ||
|
|
||
| /** | ||
| * Values for configuring application. Setting constants at the top of the app for configuration | ||
| * and then using variables within the app allow you to configure your app for multiple situations | ||
| * without having to dig through code and make changes within the code. | ||
| * | ||
| * Options are: | ||
| * standardcsvexample - Just creating a standard CSV, no options | ||
| * pipedelimitedexample - Creating a pipe deliminited example and removing double quotes from strings | ||
| * displayindividualfieldoutput - Selecting just the first row from the query results, and outputting | ||
| * to the screen, no file written | ||
| * | ||
| */ | ||
| final String whatexample = "standardcsvexample"; | ||
|
|
||
| /** | ||
| * This is the location we want our file stored in after it is created. Note that you can start from | ||
| * root with a leading forward slash, or a subdirectory of where the program is called like the example | ||
| * below | ||
| */ | ||
| final String filelocation = "tmp/"; | ||
|
|
||
|
|
||
| /** | ||
| * Standard for a Camel deployment. Start by getting a CamelContext object. | ||
| */ | ||
| CamelContext context = new DefaultCamelContext(); | ||
|
|
||
| /** | ||
| * This sets up the connection for local IBM i Here is where we will store | ||
| * connection information for the application | ||
| */ | ||
| AS400JDBCDataSource localDS = new AS400JDBCDataSource("localhost", "*CURRENT", "*CURRENT"); | ||
|
|
||
| /** | ||
| * These values below exist if you are not journaling your IBM i table that you are querying | ||
| */ | ||
| //localDS.setTransactionIsolation("none"); | ||
|
|
||
| /** | ||
| * This binds the localDS we set above to the route jt400 | ||
| */ | ||
| context.getRegistry().bind("jt400", localDS); | ||
|
|
||
| /** | ||
| * Setting our Marshall options for CSV | ||
| */ | ||
|
|
||
|
|
||
| /** | ||
| * What example do we want to accomplish? Set the variable above to choose the example | ||
| */ | ||
| context.addRoutes(new RouteBuilder() { | ||
| @Override | ||
| public void configure() { | ||
| from("timer://ibmiexamplecheckinterval?period=5000") | ||
ThePrez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * This is our example query. Here we are pulling results from the system. | ||
| * You set the body of our program (which is a mutable object used to contain the results throughout). | ||
| * Here I have set it to a constant, but you can use the simple() function to set some dynamic values | ||
| * if needed in your own example. Once you have set the body, you send to JT400. The results are then | ||
| * stored in our body, replacing the query we set it to before. | ||
| */ | ||
| .setBody(constant("select * from QSYS2.NETSTAT_INFO")) | ||
| .to("jdbc:jt400") | ||
| /** | ||
| * Now we have queried some results! We want to send it to a CSV for output. | ||
| */ | ||
| .to("direct:" + whatexample); | ||
| } | ||
| }); | ||
|
|
||
| /** | ||
| * This will do a standard output of values to CSV | ||
| */ | ||
| context.addRoutes(new RouteBuilder() { | ||
| @Override | ||
| public void configure() { | ||
| // The from should match our to in the calling route. This connects our two routes | ||
| from("direct:standardcsvexample") | ||
| // Marshall is how we are going to divide up each result from the row and what to do | ||
| .marshal() | ||
| // This creates our CSV from the results that were marshalled | ||
| .csv() | ||
| // This specific header we are setting is the name of our file | ||
| .setHeader("CamelFileName", constant("CSVExample.csv")) | ||
ThePrez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // This is where we are storing the file. This is set at the top by constants | ||
| .to("file:" + filelocation); | ||
| } | ||
| }); | ||
|
|
||
| /** | ||
| * This will show how to adjust the pipe delimiter | ||
| */ | ||
| context.addRoutes(new RouteBuilder() { | ||
| @Override | ||
| public void configure() { | ||
| from("direct:pipedelimitedexample") | ||
ThePrez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .marshal() | ||
| .csv() | ||
| .setHeader("CamelFileName", simple("${header.examplefilename}")) | ||
ThePrez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .to("file:" + filelocation); | ||
| } | ||
| }); | ||
|
|
||
| /** | ||
| * This is an example of how to take individual values from the first row of our query, | ||
| * set them to a header (where we tend to store individual values throughout our app), | ||
| * and output those values to the screen. | ||
| */ | ||
| context.addRoutes(new RouteBuilder() { | ||
| @Override | ||
| public void configure() { | ||
| from("direct:displayindividualfieldoutput") | ||
| // This will take our multiple rows of results, split them up, and give us the ability to acces them one by one | ||
| // If there are no results from the query, the application will just stop | ||
| .split(body()) | ||
| // Here we set the header of two values from our results. Notice we use the simple() function | ||
| // To access values from our query ${body[COLUMN_HEADER]} | ||
| .setHeader("localportname", simple("${body[LOCAL_PORT_NAME]}")) | ||
| .setHeader("RoundTripVariance", simple("${body[ROUND_TRIP_VARIANCE]}")) | ||
| // Now we will run a process to print the values out to the screen for each row | ||
| .process((exchange) -> { | ||
ThePrez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| System.out.println("Local Port Name: " + exchange.getIn().getHeader("localportname")); | ||
| System.out.println("Round Trip Variance: " + exchange.getIn().getHeader("RoundTripVariance")); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
|
|
||
| /** | ||
| * This actually "starts" the route, so Camel will start monitoring and routing | ||
| * activity here. | ||
| */ | ||
| context.start(); | ||
|
|
||
| /** | ||
| * This runs the check every 5 seconds if it is stopped | ||
| */ | ||
| while (!context.isStopped()) { | ||
| try { | ||
| Thread.sleep(5000); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| appender.out.type = Console | ||
| appender.out.name = out | ||
| appender.out.layout.type = PatternLayout | ||
| appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n | ||
| rootLogger.level = INFO | ||
| rootLogger.appenderRef.out.ref = out |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.