[jboss-svn-commits] JBL Code SVN: r7757 - in labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer: . loanbroker
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 22 03:20:44 EST 2006
Author: daniel.brum at jboss.com
Date: 2006-11-22 03:20:33 -0500 (Wed, 22 Nov 2006)
New Revision: 7757
Added:
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/Customer.java
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/CustomerMasterFile.java
labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/LoanBroker.java
Log:
Added: labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/Customer.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/Customer.java 2006-11-22 08:03:49 UTC (rev 7756)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/Customer.java 2006-11-22 08:20:33 UTC (rev 7757)
@@ -0,0 +1,41 @@
+package org.jboss.soa.esb.samples.trailblazer.loanbroker;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+import java.io.Serializable;
+
+public class Customer implements Serializable {
+ public String name="" ,address="" ,employerName="";
+ public double salary=0.0 ,loanAmount=0.0;
+ public int loanDuration=0;
+ public int ssn=0;
+ public String email="";
+ public int creditScore=0;
+
+ public String getCSV() {
+ String buff = (name+","+ssn+","+address+","+employerName+","+salary+","
+ +loanAmount+","+loanDuration+","+email+","+creditScore);
+
+ return buff;
+ }
+
+}
Added: labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/CustomerMasterFile.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/CustomerMasterFile.java 2006-11-22 08:03:49 UTC (rev 7756)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/CustomerMasterFile.java 2006-11-22 08:20:33 UTC (rev 7757)
@@ -0,0 +1,86 @@
+package org.jboss.soa.esb.samples.trailblazer.loanbroker;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/*
+ * Utility class used to persist the customer quote requests to a serialized Hash list on the file system
+ * Key is the customer's SSN #
+ */
+
+public class CustomerMasterFile implements Serializable {
+ private static Map<String, Customer> customers;
+ private static final String TMP_DIR = System.getProperty("java.io.tmpdir","/tmp");
+ private static final File FILE = new File(TMP_DIR, "customers");
+
+ static {
+ getCustomers();
+ }
+
+ public static synchronized void writeCustomers() {
+ try {
+ ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(FILE));
+ stream.writeObject(customers);
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public static synchronized void getCustomers() {
+
+ try {
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(FILE));
+ customers = (Map<String, Customer>)ois.readObject();
+ } catch (Exception e) {
+ customers = new HashMap<String, Customer>();
+ }
+
+ }
+
+ public static Customer getCustomer(String id) {
+ return customers.get(id);
+ }
+
+ public static void addCustomer(String id, Customer customer) {
+ customers.put(id, customer);
+ writeCustomers();
+ }
+
+
+}
Added: labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/LoanBroker.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/LoanBroker.java 2006-11-22 08:03:49 UTC (rev 7756)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/LoanBroker.java 2006-11-22 08:20:33 UTC (rev 7757)
@@ -0,0 +1,176 @@
+package org.jboss.soa.esb.samples.trailblazer.loanbroker;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.couriers.TwoWayCourier;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.samples.trailblazer.web.WebCustomer;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
+import org.jboss.soa.esb.util.Util;
+
+/*
+ * LoanBroker is responsible for getting customer requests for loans onto the JBoss ESB
+ * Requests will come from a JSR-181 pojo web service (@org.jboss.soa.esb.samples.trailblazer.web.LoanBrokerWS)
+ * The sequence of events from the LoanBroker are:
+ * 1 - Prepare a request for the CreditAgency (transform the customer into a XML representation)
+ * 2 - Send to CreditAgency and get response (lookup the customer using the SSN (see @CustomerMasterFile)
+ * 3 - Prepare a LoanRequest for each of the banks in their unique data structures and send
+ * 4 - Collect the response(s) from the bank(s) and send an email to the customer with the quote offers
+ */
+
+public class LoanBroker {
+
+ private static Logger logger = Logger.getLogger(LoanBroker.class);
+ //used to locate our entries in the trailblazer-properties
+ private final String MODULE_NAME = "trailblazer";
+ private final String SERVICE_NAME = "org.jboss.soa.esb.trailblazer.request.service.epr.name";
+ private final String SERVICE_CAT = "org.jboss.soa.esb.trailblazer.request.service.category";
+
+ public LoanBroker() {
+ System.setProperty("org.jboss.soa.esb.propertyFile", "trailblazer-properties.xml");
+// System.setProperty("juddi.propertiesFile", "juddi.properties");
+
+ }
+
+ public void processLoanRequest(WebCustomer wCustomer){
+
+ Customer customer = getCustomer(wCustomer);
+ //keep the customer in a file someplace for later use, if needed
+ CustomerMasterFile.addCustomer(String.valueOf(customer.ssn), customer);
+
+ //step 1 - get the credit score for this customer
+ //use a CSV delimited String
+ Message message = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+ message.getBody().setContents(customer.getCSV().getBytes());
+// ActionUtils.setTaskObject(message, customer.getCSV());
+ try {
+ System.out.println("message: " + Util.serialize(message));
+ } catch (ParserConfigurationException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ try {
+ Registry registry = RegistryFactory.getRegistry();
+ String serviceCategoryName = ModulePropertyManager.getPropertyManager(MODULE_NAME).getProperty(SERVICE_CAT);
+ String serviceName = ModulePropertyManager.getPropertyManager(MODULE_NAME).getProperty(SERVICE_NAME);
+
+ logger.info("looking for the following service in the registry -- Category: " + serviceCategoryName);
+ logger.info("looking for the following service in the registry -- Name: " + serviceName);
+
+ EPR toEPR=null;
+ toEPR = registry.findEPR(serviceCategoryName, serviceName);
+ TwoWayCourier courier = CourierFactory.getCourier(toEPR, null);
+ if (null == courier) {
+ logger.info("could not get a valid courier to deliver the message");
+ throw new ActionProcessingException("could not find a courier to deliver the message for the serrvice " +
+ "(category-name: " + serviceCategoryName +"-" + serviceCategoryName);
+ }
+ if (null != courier) {
+ if (!courier.deliver(message)) {
+ throw new ActionProcessingException("error delivering the message");
+ }
+ courier.setReplyToEpr(CourierUtil.getTemporaryReplyToEpr(toEPR));
+ message = courier.pickup(5000);
+
+ }
+
+ System.out.println("message returned: " + Util.serialize(message));
+
+
+
+
+// for (Iterator<EPR> eprIterator=eprs.iterator();eprIterator.hasNext();){
+//
+// toEPR = eprIterator.next();
+// courier = CourierFactory.getCourier(toEPR, null);
+// if (null == courier) {
+// logger.info("could not get a valid courier to deliver the message");
+// break;
+// }
+//
+// //If not successful try the next EPR
+// if (courier.deliver(message)) {
+// break;
+// }
+// }
+// //get the response
+// if (null != courier)
+// replytToEPR = CourierUtil.getTemporaryReplyToEpr(toEPR);
+//
+//
+// CourierFactory.getCourier(toEPR, replytToEPR);
+//
+ }catch (Exception e) {
+ logger.error("exception occured: " + e);
+ }
+ //step 2 - send to JMS Bank
+
+ //step 3 - send to File Bank (when listener is ready)
+
+ //step 4 - send to SQL Bank (when listener ready)
+
+ }
+
+ private Customer getCustomer(WebCustomer wCustomer) {
+ Customer customer = new Customer();
+ customer.ssn = wCustomer.ssn;
+ customer.name = wCustomer.name;
+ customer.address = wCustomer.address;
+ customer.email = wCustomer.email;
+ customer.salary = wCustomer.salary;
+ customer.loanAmount = wCustomer.loanAmount;
+ customer.loanDuration = wCustomer.loanDuration;
+ customer.creditScore = 0;
+
+ return customer;
+ }
+
+ public static void main(String[] args) {
+ LoanBroker broker = new LoanBroker();
+ WebCustomer wCustomer = new WebCustomer("me", "123 Anywhere st.", "Jboss", 500.00, 12, 100.00,12345,"email");
+ broker.processLoanRequest(wCustomer);
+ }
+
+
+
+}
More information about the jboss-svn-commits
mailing list