summaryrefslogtreecommitdiffstats
path: root/Master/Daten- und Systemintegration/CamelPrototype/src
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Daten- und Systemintegration/CamelPrototype/src
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Daten- und Systemintegration/CamelPrototype/src')
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/FilenameGenerator.java9
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/Main.java13
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderNormalizer.java26
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderRoutes.java74
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystem.java148
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystemAdaptor.java18
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystemDerby.java173
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderTransformer.java25
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/META-INF/spring/camel-context.xml23
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/OrderMailBody.vm12
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/OrderService.wsdl71
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/log4j.properties22
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/main/webapp/WEB-INF/web.xml32
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/test/java/de/h_da/fbi/dsi/ws0910/camelprototype/CreateOrderRoutesTest.java112
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/CreateOrderRoutesTest-context.xml31
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/log4j.properties22
16 files changed, 811 insertions, 0 deletions
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/FilenameGenerator.java b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/FilenameGenerator.java
new file mode 100644
index 0000000..fbf4e04
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/FilenameGenerator.java
@@ -0,0 +1,9 @@
+package de.h_da.fbi.dsi.ws0910.camelprototype;
+
+import org.apache.camel.Exchange;
+
+public class FilenameGenerator {
+ public String getFilename(Exchange exchange) {
+ return "ordermail-"+exchange.getIn().getHeader("orderno")+".txt";
+ }
+}
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/Main.java b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/Main.java
new file mode 100644
index 0000000..e3b4315
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/Main.java
@@ -0,0 +1,13 @@
+package de.h_da.fbi.dsi.ws0910.camelprototype;
+
+public final class Main {
+
+ private Main() {
+ // do nothing here
+ }
+
+ public static void main(String[] args) throws Exception {
+ org.apache.camel.spring.Main.main(args);
+ }
+
+}
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderNormalizer.java b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderNormalizer.java
new file mode 100644
index 0000000..f7dc857
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderNormalizer.java
@@ -0,0 +1,26 @@
+package de.h_da.fbi.dsi.ws0910.camelprototype;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.dataformat.CsvDataFormat;
+
+public class OrderNormalizer extends RouteBuilder{
+ @Override
+ public void configure() throws Exception {
+ from("direct:new-orders-in")
+ .choice()
+ .when(header("from").isEqualTo(constant("csvinput")))
+ //csv order transformer
+ // convert CSV-File to InputNewOrder that further processing expects
+ .unmarshal(new CsvDataFormat())
+ .bean(OrderTransformer.class, "transformFromCsv")
+ // put the InputNewOrder into the channel
+ .to("direct:normalized-orders")
+
+ .when(header("from").isEqualTo(constant("cxf")))
+ // webservice order transformer
+ // we need to convert the CXF payload to InputNewOrder that further processing expects
+ .convertBodyTo(InputNewOrder.class)
+ // put the InputNewOrder into the channel
+ .to("direct:normalized-orders");
+ }
+}
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderRoutes.java b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderRoutes.java
new file mode 100644
index 0000000..19686c7
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderRoutes.java
@@ -0,0 +1,74 @@
+package de.h_da.fbi.dsi.ws0910.camelprototype;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+
+public class OrderRoutes extends RouteBuilder {
+ //OrderSystemAdaptor orderSysAdaptor = new OrderSystemAdaptor();
+ private String email_authuser = null;
+ private String email_authpw = null;
+ private String email_recipient = null;
+
+ public OrderRoutes() {
+ this("neworders@eisy.net.eu.org","crasher@smtp.eisy.net.eu.org","crashm3");
+ }
+ public OrderRoutes(String email_recipient,String email_authuser,String email_authpw) {
+ super();
+ this.email_recipient = email_recipient;
+ this.email_authuser = email_authuser;
+ this.email_authpw = email_authpw;
+ }
+
+ public void configure() throws Exception {
+ // endpoint to our CXF webservice
+ String cxfEndpoint = "cxf://http://localhost:8080/camelprototype/webservices/order"
+ + "?serviceClass=de.h_da.fbi.dsi.ws0910.camelprototype.OrderEndpoint"
+ + "&wsdlURL=OrderService.wsdl";
+
+ from(cxfEndpoint)
+ // set header field to keep track of requester
+ .setHeader("from",constant("cxf"))
+ .to("direct:new-orders-in");
+ from("file://target/csvinput?recursive=true&delete=true")
+ .setHeader("from",constant("csvinput"))
+ .to("direct:new-orders-in");
+
+ from("direct:normalized-orders")
+ // pass the new order to the order management system gateway
+ // function integration
+ .processRef("ordersystemadaptor")
+ // send the notification email
+ .to("direct:sendordermail")
+ // CBR: if the order was sent by a webservice request
+ .choice()
+ .when(header("from").isEqualTo("cxf"))
+ // send a response back to webservice client
+ // return OK as response
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ OutputNewOrder res = new OutputNewOrder();
+ res.setStatus("0");
+ res.setMessage((String) exchange.getIn().getHeader("orderno"));
+ exchange.getOut().setBody(res,OutputNewOrder.class);
+ }
+ })
+ .otherwise().end();
+
+ // generate order mail file
+ from("direct:sendordermail")
+ // set the file name
+ .setHeader("CamelFileName", bean(FilenameGenerator.class,"getFilename"))
+ // and create the mail body using velocity templating
+ .to("velocity:OrderMailBody.vm")
+ // and store the file
+ .to("file://target/ordermails/");
+
+ // from the file -> send email
+ from("file://target/ordermails/?move=sent")
+ // set the subject of the email
+ .setHeader("subject", constant("New Order notification"))
+ // send the email
+ .to("smtp://"+email_authuser+"?password="+email_authpw+"&to="+email_recipient);
+ }
+}
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystem.java b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystem.java
new file mode 100644
index 0000000..28a06d2
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystem.java
@@ -0,0 +1,148 @@
+package de.h_da.fbi.dsi.ws0910.camelprototype;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class OrderSystem {
+
+ private static final String DB_NAME = "jdbc:hsqldb:file:target/db/orderDB";
+ private static final String DB_USER="sa";
+ private static final String DB_PASSWORD="";
+ private static final String DB_DRV = "org.hsqldb.jdbcDriver";
+
+ private static final String CREATE_ORDERTBL_SQL = "CREATE TABLE \"orders\" (" +
+ "orderid INT generated by default as identity (start with 1) PRIMARY KEY, "+
+ "customerno VARCHAR(50) NOT NULL, " +
+ "order_created_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP )";
+ private static final String CREATE_ORDERPOSTBL_SQL = "CREATE TABLE \"orderpos\" (" +
+ "orderposid INT generated by default as identity (start with 1) PRIMARY KEY, "+
+ "orderid INT NOT NULL, "+
+ "articleno VARCHAR(50) NOT NULL,"+
+ "articlename VARCHAR(50) NOT NULL,"+
+ "amount INT NOT NULL )";
+
+ private static final String ORDER_INSERT_SQL = "INSERT INTO \"orders\" " +
+ "(orderid,customerno) VALUES(null,?)";
+ private static final String ORDERPOS_INSERT_SQL = "INSERT INTO \"orderpos\" " +
+ "(orderposid,orderid,articleno,articlename,amount) VALUES(null,?,?,?,?)";
+ private Connection con = null;
+ private static OrderSystem theInstance = null;
+
+ public static OrderSystem getInstance() throws ClassNotFoundException, SQLException {
+ if(theInstance == null) {
+ theInstance = new OrderSystem();
+ }
+ return theInstance;
+ }
+
+ public OrderSystem() throws ClassNotFoundException, SQLException {
+ Class.forName(DB_DRV);
+ initDB();
+ }
+
+ private void initDB() throws SQLException {
+ try {
+ Statement stmt = getDbConnection().createStatement();
+ ResultSet rs = getDbConnection().getMetaData().getTables(null,null, "orders", null);
+ if(!rs.next()) stmt.execute(CREATE_ORDERTBL_SQL);
+ rs = getDbConnection().getMetaData().getTables(null,null, "orderpos", null);
+ if(!rs.next()) stmt.execute(CREATE_ORDERPOSTBL_SQL);
+ stmt.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ private Connection getDbConnection() {
+ if (con == null) {
+ try {
+ con = DriverManager.getConnection(DB_NAME,DB_USER,DB_PASSWORD);
+ } catch (SQLException sqle) {
+ sqle.printStackTrace();
+ //throw new RuntimeException("Error connecting to DB",sqle);
+ }
+ }
+ return con;
+ }
+
+ private String insertNewOrder(InputNewOrder newOrder) {
+ int orderNo = -1;
+ try {
+ PreparedStatement pStmt = getDbConnection().prepareStatement(ORDER_INSERT_SQL);
+ pStmt.setString(1, newOrder.getCustomerNo());
+ pStmt.execute();
+ CallableStatement cstmt = getDbConnection().prepareCall("{CALL IDENTITY()}");
+ ResultSet row = cstmt.executeQuery();
+ if(row.next()) {
+ orderNo = row.getInt(1);
+ }
+ row.close();
+ cstmt.close();
+ if (orderNo != -1) {
+ for(OrderPosition pos : newOrder.getOrderpositions()) {
+ pStmt = getDbConnection().prepareStatement(ORDERPOS_INSERT_SQL);
+ int j = 0;
+ pStmt.setInt(++j, orderNo);
+ pStmt.setString(++j, pos.getArticleNo());
+ pStmt.setString(++j, pos.getArticle());
+ pStmt.setInt(++j, pos.getAmount());
+ pStmt.executeUpdate();
+ }
+ }
+ pStmt.close();
+ } catch (SQLException sqle) {
+ sqle.printStackTrace();
+ }
+ return Integer.toString(orderNo);
+ }
+
+ public synchronized String handleNewOrder(InputNewOrder newOrder) {
+ String orderNum = insertNewOrder(newOrder);
+ return orderNum;
+ }
+ public synchronized void dumpOrders() {
+ StringBuilder dump = new StringBuilder();
+ try {
+ dump.append("=============================\n");
+ dump.append("\tStart Order Dump\n");
+ dump.append("=============================\n");
+ dump.append("OrderID").append("\t").append("CustNo").append("\t");
+ dump.append("ArtNo").append("\t").append("Article").append("\t\t");
+ dump.append("Amount").append("\t").append("Created on").append("\n");
+ dump.append("--------------------------------------------------------\n");
+ Statement stmt = getDbConnection().createStatement();
+ String sql = "SELECT * from \"orders\" AS o JOIN \"orderpos\" AS op ON o.orderid = op.orderid";
+ ResultSet rs = stmt.executeQuery(sql);
+ while(rs.next()) {
+ dump.append(rs.getString("orderid")).append("\t");
+ dump.append(rs.getString("customerno")).append("\t");
+ dump.append(rs.getString("articleno")).append("\t");
+ dump.append(rs.getString("articlename")).append("\t");
+ dump.append(rs.getString("amount")).append("\t");
+ dump.append(rs.getTimestamp("order_created_ts")).append("\n");
+ }
+ rs.close();
+ stmt.close();
+ dump.append("=============================\n");
+ dump.append("\tFinish Order Dump\n");
+ dump.append("=============================\n");
+ System.out.println(dump.toString());
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ public synchronized void shutdown() {
+ try {
+ Statement stmt = getDbConnection().createStatement();
+ stmt.execute("SHUTDOWN");
+ stmt.close();
+ theInstance = null;
+ } catch (SQLException sqle) {
+ sqle.printStackTrace();
+ }
+ }
+}
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystemAdaptor.java b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystemAdaptor.java
new file mode 100644
index 0000000..551454b
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystemAdaptor.java
@@ -0,0 +1,18 @@
+package de.h_da.fbi.dsi.ws0910.camelprototype;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+public class OrderSystemAdaptor implements Processor{
+ private OrderSystem ordersystem;
+ public OrderSystemAdaptor(OrderSystem ordersystem) {
+ super();
+ this.ordersystem = ordersystem;
+ }
+ public void process(Exchange exchange) throws Exception {
+ InputNewOrder newOrder = exchange.getIn().getBody(InputNewOrder.class);
+ // here happens functional integration of a legacy system
+ String orderNum =ordersystem.handleNewOrder(newOrder);
+ exchange.getIn().setHeader("orderno", orderNum);
+ }
+}
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystemDerby.java b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystemDerby.java
new file mode 100644
index 0000000..dff0acf
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderSystemDerby.java
@@ -0,0 +1,173 @@
+package de.h_da.fbi.dsi.ws0910.camelprototype;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class OrderSystemDerby {
+
+ private static final String DB_URL = "jdbc:derby:;databaseName=orderDB;create=true;";
+ private static final String DB_DRV = "org.apache.derby.jdbc.EmbeddedDriver";
+
+ private static final String CREATE_ORDERTBL_SQL = "CREATE TABLE \"orders\" (" +
+ "orderid INT generated by default as identity (start with 1) PRIMARY KEY, "+
+ "customerno VARCHAR(50) NOT NULL, " +
+ "order_created_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP )";
+ private static final String CREATE_ORDERPOSTBL_SQL = "CREATE TABLE \"orderpos\" (" +
+ "orderposid INT generated by default as identity (start with 1) PRIMARY KEY, "+
+ "orderid INT NOT NULL, "+
+ "articleno VARCHAR(50) NOT NULL,"+
+ "articlename VARCHAR(50) NOT NULL,"+
+ "amount INT NOT NULL )";
+
+ private static Connection con = null;
+
+ static {
+ String dbdir = System.getProperty("user.dir");
+ dbdir += System.getProperty("file.separator")+"target";
+ dbdir += System.getProperty("file.separator")+"db";
+ System.setProperty("derby.system.home", dbdir);
+ try {
+ Class.forName(DB_DRV);
+
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ initDB();
+ }
+
+ private static void initDB() {
+ try {
+ Statement stmt = getDbConnection().createStatement();
+ ResultSet rs = getDbConnection().getMetaData().getTables(null,"APP", "orders", null);
+ if(!rs.next()) stmt.execute(CREATE_ORDERTBL_SQL);
+ rs = getDbConnection().getMetaData().getTables(null,"APP", "orderpos", null);
+ if(!rs.next()) stmt.execute(CREATE_ORDERPOSTBL_SQL);
+ stmt.close();
+ } catch (SQLException e) {
+ if(!e.getSQLState().equals("X0Y32")) {
+ e.printStackTrace();
+ }
+ }
+ }
+ private static Connection getDbConnection() {
+ if (con == null) {
+ try {
+ con = DriverManager.getConnection(DB_URL);
+ } catch (SQLException sqle) {
+ sqle.printStackTrace();
+ if(!sqle.getSQLState().equals("XBM0J")) {
+ try {
+ Class.forName(DB_DRV);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ try {
+ con = DriverManager.getConnection(DB_URL);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ throw new RuntimeException("Error connecting to DB",sqle);
+ }
+ initDB();
+ } else {
+ shutdown();
+ try {
+ con = DriverManager.getConnection(DB_URL);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ throw new RuntimeException("Error connecting to DB",sqle);
+ }
+ }
+ } catch (NullPointerException npe) {
+ try {
+ Class.forName(DB_DRV);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ initDB();
+ }
+ }
+ return con;
+ }
+
+ private static String insertNewOrder(InputNewOrder newOrder) {
+ int orderNo = -1;
+ try {
+ Statement stmt = getDbConnection().createStatement();
+ String sql = "INSERT INTO \"orders\" (customerno) VALUES('"+newOrder.getCustomerNo()+"')";
+ stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
+ ResultSet row = stmt.getGeneratedKeys();
+ if(row.next()) {
+ orderNo = row.getInt(1);
+ }
+ row.close();
+ if (orderNo != -1) {
+
+ for(OrderPosition pos : newOrder.getOrderpositions()) {
+ sql = "INSERT INTO \"orderpos\" " +
+ "(orderid,articleno,articlename,amount) " +
+ "VALUES("+orderNo+",'"+pos.getArticleNo()+"','"
+ +pos.getArticle()+"',"+pos.getAmount()+")";
+ stmt.executeUpdate(sql);
+ }
+ }
+ stmt.close();
+ } catch (SQLException sqle) {
+ sqle.printStackTrace();
+ }
+ return Integer.toString(orderNo);
+ }
+
+ public static String handleNewOrder(InputNewOrder newOrder) {
+ String orderNum = insertNewOrder(newOrder);
+ return orderNum;
+ }
+ public static void dumpOrders() {
+ StringBuilder dump = new StringBuilder();
+ try {
+ dump.append("=============================\n");
+ dump.append("\tStart Order Dump\n");
+ dump.append("=============================\n");
+ dump.append("OrderID").append("\t").append("CustNo").append("\t");
+ dump.append("ArtNo").append("\t").append("Article").append("\t\t");
+ dump.append("Amount").append("\t").append("Created on").append("\n");
+ dump.append("--------------------------------------------------------\n");
+ Statement stmt = getDbConnection().createStatement();
+ String sql = "SELECT * from \"orders\" AS o JOIN \"orderpos\" AS op ON o.orderid = op.orderid";
+ ResultSet rs = stmt.executeQuery(sql);
+ while(rs.next()) {
+ dump.append(rs.getString("orderid")).append("\t");
+ dump.append(rs.getString("customerno")).append("\t");
+ dump.append(rs.getString("articleno")).append("\t");
+ dump.append(rs.getString("articlename")).append("\t");
+ dump.append(rs.getString("amount")).append("\t");
+ dump.append(rs.getTimestamp("order_created_ts")).append("\n");
+ }
+ rs.close();
+ stmt.close();
+ dump.append("=============================\n");
+ dump.append("\tFinish Order Dump\n");
+ dump.append("=============================\n");
+ System.out.println(dump.toString());
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ public static void shutdown() {
+ boolean gotSQLExc = false;
+ try {
+ DriverManager.getConnection("jdbc:derby:;shutdown=true");
+ } catch (SQLException se) {
+ if ( se.getSQLState().equals("XJ015") ) {
+ gotSQLExc = true;
+ }
+ }
+ if (!gotSQLExc) {
+ System.out.println("Database did not shut down normally");
+ } else {
+ System.out.println("Database shut down normally");
+ }
+ }
+}
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderTransformer.java b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderTransformer.java
new file mode 100644
index 0000000..6c27c7b
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/java/de/h_da/fbi/dsi/ws0910/camelprototype/OrderTransformer.java
@@ -0,0 +1,25 @@
+package de.h_da.fbi.dsi.ws0910.camelprototype;
+
+import java.util.List;
+import org.apache.camel.Exchange;
+
+public class OrderTransformer {
+ public void transformFromCsv(Exchange ex) {
+ String filename = ex.getIn().getHeader("CamelFileName",String.class);
+ // csv format will generate a List<List<String>> as body
+ // to avoid unchecked casting this ugly thing is necessary
+ List<?> lines = (List<?>) ex.getIn().getBody();
+ InputNewOrder res = new InputNewOrder();
+ String customerNo = filename.split("\\.")[0];
+ res.setCustomerNo(customerNo);
+ for(Object line: lines) {
+ List<?> cols = (List<?>) line;
+ OrderPosition orderPos = new OrderPosition();
+ orderPos.articleNo = (String) cols.get(0);
+ orderPos.article = (String) cols.get(1);
+ orderPos.amount = Integer.parseInt((String) cols.get(2));
+ res.getOrderpositions().add(orderPos);
+ }
+ ex.getIn().setBody(res);
+ }
+}
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/META-INF/spring/camel-context.xml b/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/META-INF/spring/camel-context.xml
new file mode 100644
index 0000000..c412226
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/META-INF/spring/camel-context.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans 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-2.5.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <import resource="classpath:META-INF/cxf/cxf.xml"/>
+ <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
+ <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
+
+ <!-- create a camel context as to start Camel -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <package>de.h_da.fbi.dsi.ws0910.camelprototype</package>
+ </camelContext>
+ <bean id="ordersystem"
+ class="de.h_da.fbi.dsi.ws0910.camelprototype.OrderSystem"
+ destroy-method="shutdown"/>
+ <bean id="ordersystemadaptor"
+ class="de.h_da.fbi.dsi.ws0910.camelprototype.OrderSystemAdaptor">
+ <constructor-arg ref="ordersystem" />
+ </bean>
+</beans> \ No newline at end of file
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/OrderMailBody.vm b/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/OrderMailBody.vm
new file mode 100644
index 0000000..0b85af6
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/OrderMailBody.vm
@@ -0,0 +1,12 @@
+Customer $body.customerNo has placed a new order via $headers.from
+
+Order-No.: $headers.orderno
+Cust.No.: $body.customerNo
+
+Art.-No. Article Amount
+====================================================
+#foreach($orderPos in $body.orderpositions)
+$orderPos.articleNo $orderPos.article $orderPos.amount
+#end
+
+This is an auto generated email. You cannot reply. \ No newline at end of file
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/OrderService.wsdl b/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/OrderService.wsdl
new file mode 100644
index 0000000..296f6be
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/OrderService.wsdl
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://camelprototype.ws0910.dsi.fbi.h_da.de" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="OrderService" targetNamespace="http://camelprototype.ws0910.dsi.fbi.h_da.de">
+ <wsdl:types>
+ <xsd:schema targetNamespace="http://camelprototype.ws0910.dsi.fbi.h_da.de">
+ <xsd:element name="inputNewOrder">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="customerNo" type="xsd:string" />
+ <xsd:element name="orderpositions"
+ type="tns:orderPosition" maxOccurs="unbounded"
+ minOccurs="1">
+ </xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="outputNewOrder">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="status" type="xsd:string"></xsd:element>
+ <xsd:element name="message" type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+
+
+ <xsd:complexType name="orderPosition">
+ <xsd:sequence>
+ <xsd:element name="article" type="xsd:string"></xsd:element>
+
+ <xsd:element name="amount" type="xsd:int"></xsd:element>
+ <xsd:element name="articleNo" type="xsd:string"></xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:schema>
+ </wsdl:types>
+ <wsdl:message name="inputNewOrder">
+ <wsdl:part name="in" element="tns:inputNewOrder"></wsdl:part>
+ </wsdl:message>
+ <wsdl:message name="outputNewOrder">
+ <wsdl:part name="out" element="tns:outputNewOrder"></wsdl:part>
+ </wsdl:message>
+ <wsdl:portType name="OrderEndpoint">
+ <wsdl:operation name="CreateOrder">
+ <wsdl:input message="tns:inputNewOrder" name="input"/>
+ <wsdl:output message="tns:outputNewOrder" name="output"/>
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="OrderServiceBinding" type="tns:OrderEndpoint">
+
+ <soap:binding style="document"
+ transport="http://schemas.xmlsoap.org/soap/http" />
+ <wsdl:operation name="CreateOrder">
+
+ <soap:operation
+ soapAction="http://camelprototype.ws0910.dsi.fbi.h_da.de/PlaceNewOrder" />
+ <wsdl:input name="input">
+
+ <soap:body use="literal" />
+ </wsdl:input>
+ <wsdl:output name="output">
+
+ <soap:body use="literal" />
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="OrderEndpointService">
+ <wsdl:port binding="tns:OrderServiceBinding" name="OrderService">
+ <soap:address location="http://localhost:8080/camelprototype/webservices/order"/>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/log4j.properties b/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/log4j.properties
new file mode 100644
index 0000000..82dd219
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/resources/log4j.properties
@@ -0,0 +1,22 @@
+
+# default properties to initialise log4j
+log4j.rootLogger=INFO, console
+
+# Console appender
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/dsi-order.log
+log4j.appender.file.append=true
+
+# settings for specific packages
+#log4j.logger.org.springframework=WARN
+#log4j.logger.org.apache.cxf=WARN
+
+# Camel logging
+log4j.logger.org.apache.camel=INFO \ No newline at end of file
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/main/webapp/WEB-INF/web.xml b/Master/Daten- und Systemintegration/CamelPrototype/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..da15020
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <display-name>DSI CamelPrototype Web Application</display-name>
+
+ <!-- location of spring xml files -->
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>classpath:camel-config.xml</param-value>
+ </context-param>
+
+ <!-- the listener that kick-starts Spring -->
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+
+ <!-- CXF servlet -->
+ <servlet>
+ <servlet-name>CXFServlet</servlet-name>
+ <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <!-- all our webservices are mapped under this URI pattern -->
+ <servlet-mapping>
+ <servlet-name>CXFServlet</servlet-name>
+ <url-pattern>/webservices/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/test/java/de/h_da/fbi/dsi/ws0910/camelprototype/CreateOrderRoutesTest.java b/Master/Daten- und Systemintegration/CamelPrototype/src/test/java/de/h_da/fbi/dsi/ws0910/camelprototype/CreateOrderRoutesTest.java
new file mode 100644
index 0000000..20a9bbd
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/test/java/de/h_da/fbi/dsi/ws0910/camelprototype/CreateOrderRoutesTest.java
@@ -0,0 +1,112 @@
+package de.h_da.fbi.dsi.ws0910.camelprototype;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.jvnet.mock_javamail.Mailbox;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+@ContextConfiguration(locations="/CreateOrderRoutesTest-context.xml")
+public class CreateOrderRoutesTest extends AbstractJUnit4SpringContextTests{
+ private static final long WAIT = 2000;
+ private static Mailbox inbox;
+ private static String EMAILRECIPIENT = "neworders@mycompany.com";
+ // should be the same address as we have in our route
+ private static String ADDRESS = "http://localhost:8080/camelprototype/webservices/order";
+
+ protected static OrderEndpoint createCXFClient() {
+ // we use CXF to create a client for us as its easier than JAXWS and works
+ JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+ factory.setServiceClass(OrderEndpoint.class);
+ factory.setAddress(ADDRESS);
+ return (OrderEndpoint) factory.create();
+ }
+ protected InputNewOrder createWSTestData() {
+ // create input parameter
+ InputNewOrder input = new InputNewOrder();
+ input.setCustomerNo("456");
+ OrderPosition orderPos1 = new OrderPosition();
+ orderPos1.setAmount(2);
+ orderPos1.setArticle("Super Gadget");
+ orderPos1.setArticleNo("7890");
+ input.getOrderpositions().add(orderPos1);
+
+ OrderPosition orderPos2 = new OrderPosition();
+ orderPos2.setAmount(8);
+ orderPos2.setArticle("Mega Gadget");
+ orderPos2.setArticleNo("6543");
+ input.getOrderpositions().add(orderPos2);
+
+ OrderPosition orderPos3 = new OrderPosition();
+ orderPos3.setAmount(3);
+ orderPos3.setArticle("Great Nonsens");
+ orderPos3.setArticleNo("N6543");
+ input.getOrderpositions().add(orderPos3);
+ return input;
+ }
+ private void createCsvTestData() throws IOException {
+ BufferedWriter bw = new BufferedWriter(new FileWriter("target/csvinput/34524.csv"));
+ bw.write("574,One Article,3\n");
+ bw.write("575,Second Article,4\n");
+ bw.write("852,Another Article,5");
+ bw.close();
+ }
+ @Test
+ public void testWebserviceNewOrder() throws Exception {
+ try {
+ // assert mailbox is empty before starting
+ assertEquals("Should not have mails", 0, inbox.size());
+ // create the webservice client
+ OrderEndpoint client = createCXFClient();
+ // create Test Order for webservice testclient
+ InputNewOrder testOrder = createWSTestData();
+ for (int count=1;count<=5;count++) {
+ // send the request
+ OutputNewOrder out = client.createOrder(testOrder);
+ // assert we got a OK back
+ assertEquals("0", out.getStatus());
+ //assert we got an order number back
+ assertFalse("Should have an order number", out.getMessage().isEmpty());
+ System.out.println("Received orderno: "+out.getMessage());
+ // let some time pass to allow Camel to pickup the file and send it as an email
+ Thread.sleep(WAIT);
+ // assert mail box
+ assertEquals("Should have got "+count+" mails", count, inbox.size());
+ }
+ } catch (Exception ex) {
+ throw new Exception("Error executing Webservice Test", ex);
+ }
+ }
+
+ @Test
+ public void testCSVNewOrder() throws Exception {
+ // assert mailbox is empty before starting
+ assertEquals("Should not have mails", 0, inbox.size());
+ // create csv test data
+ createCsvTestData();
+ // let some time pass to allow Camel to pickup the file and send it as an email
+ Thread.sleep(WAIT);
+ // assert mail box
+ assertEquals("Should have got 1 mail", 1, inbox.size());
+ }
+ @Before
+ public void cleanInbox() {
+ inbox.clear();
+ }
+ @BeforeClass
+ public static void setUp() throws Exception {
+ inbox = Mailbox.get(EMAILRECIPIENT);
+ }
+ @AfterClass
+ public static void tearDown() throws Exception {
+ OrderSystem.getInstance().dumpOrders();
+ }
+}
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/CreateOrderRoutesTest-context.xml b/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/CreateOrderRoutesTest-context.xml
new file mode 100644
index 0000000..c485b04
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/CreateOrderRoutesTest-context.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans 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-2.5.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <import resource="classpath:META-INF/cxf/cxf.xml"/>
+ <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
+ <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
+
+ <!-- create a camel context as to start Camel -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <routeBuilder ref="orderroutes" />
+ <routeBuilder ref="ordernormalizer" />
+ </camelContext>
+ <bean id="ordernormalizer" class="de.h_da.fbi.dsi.ws0910.camelprototype.OrderNormalizer"/>
+ <bean id="ordersystem"
+ class="de.h_da.fbi.dsi.ws0910.camelprototype.OrderSystem"
+ destroy-method="shutdown"/>
+ <bean id="ordersystemadaptor"
+ class="de.h_da.fbi.dsi.ws0910.camelprototype.OrderSystemAdaptor">
+ <constructor-arg ref="ordersystem" />
+ </bean>
+ <bean id="orderroutes"
+ class="de.h_da.fbi.dsi.ws0910.camelprototype.OrderRoutes">
+ <constructor-arg index="0" type="java.lang.String" value="neworders@mycompany.com" />
+ <constructor-arg index="1" type="java.lang.String" value="someone@localhost" />
+ <constructor-arg index="2" type="java.lang.String" value="" />
+ </bean>
+</beans> \ No newline at end of file
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/log4j.properties b/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/log4j.properties
new file mode 100644
index 0000000..6d3a2b3
--- /dev/null
+++ b/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/log4j.properties
@@ -0,0 +1,22 @@
+
+# default properties to initialise log4j
+log4j.rootLogger=INFO, file
+
+# Console appender
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/dsi-order-test.log
+log4j.appender.file.append=true
+
+# settings for specific packages
+log4j.logger.org.springframework=WARN
+log4j.logger.org.apache.cxf=WARN
+
+# Camel logging
+log4j.logger.org.apache.camel=DEBUG \ No newline at end of file