[jboss-svn-commits] JBL Code SVN: r7955 - in labs/jbossesb/trunk/product/samples/trailblazer2: . banks/src/org/jboss/soa/esb/samples/loanbroker/banks client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker esb/conf esb/src/org/jboss/soa/esb/samples/trailblazer/actions esb/src/org/jboss/soa/esb/samples/trailblazer/util

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 29 17:51:29 EST 2006


Author: daniel.brum at jboss.com
Date: 2006-11-29 17:51:18 -0500 (Wed, 29 Nov 2006)
New Revision: 7955

Added:
   labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/ProcessEmail.java
Modified:
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/ManagerJMS.java
   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/LoanBroker.java
   labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/QuoteRequest.java
   labs/jbossesb/trunk/product/samples/trailblazer2/esb/conf/banksgateway-esb.xml
   labs/jbossesb/trunk/product/samples/trailblazer2/esb/conf/loanbroker-esb.xml
   labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/actions/CreditAgencyActions.java
   labs/jbossesb/trunk/product/samples/trailblazer2/trailblazer-properties.xml
Log:


Modified: labs/jbossesb/trunk/product/samples/trailblazer2/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/ManagerJMS.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/ManagerJMS.java	2006-11-29 22:28:08 UTC (rev 7954)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/ManagerJMS.java	2006-11-29 22:51:18 UTC (rev 7955)
@@ -108,17 +108,20 @@
 	 * in an error a BankQuoteReply with ErrorCode other then 0 is send to the outgoing queue.
 	 * 
 	 * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
+	 * changed this to use a CSV from the request, left the reply as is - dbrum
 	 */
 	public void onMessage(Message message) {
 		QueueConnection outQueueConnection;
 		logger.info("Got message: " + message);
 		try {
 			TextMessage textMessage = (TextMessage) message;
-			String xml = textMessage.getText();
+//			String xml = textMessage.getText();
+			String csv = textMessage.getText();
 			XStream xstream = new XStream(new DomDriver());
-			BankQuoteRequest bankQuoteRequest = new BankQuoteRequest(); 
+			BankQuoteRequest bankQuoteRequest = getQuoteFromCSV(csv);
+			
             
-            xstream.fromXML(xml, bankQuoteRequest);
+//            xstream.fromXML(xml, bankQuoteRequest);
 			Bank bank = new Bank(BANK_NAME, RATE_PREMIUM, MAXLOANTERM);
 			BankQuoteReply bankQuoteReply = bank
 					.processMessage(bankQuoteRequest);
@@ -177,4 +180,17 @@
 		ManagerJMS managerJMS = new ManagerJMS();
 		managerJMS.listen();
 	}
+	
+	private BankQuoteRequest getQuoteFromCSV(String csv) {
+		BankQuoteRequest quote = new BankQuoteRequest();
+		String[] parsed = csv.split(",");
+		quote.ssn=Integer.parseInt(parsed[0]);
+		quote.creditScore=Integer.parseInt(parsed[1]);
+		quote.historyLength=Integer.parseInt(parsed[2]);
+		quote.loanAmount=Integer.parseInt(parsed[3]);
+		quote.loanTerm=Integer.parseInt(parsed[4]);
+		quote.customerUID=parsed[5];
+		
+		return quote;
+	}
 }
\ No newline at end of file

Modified: 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-29 22:28:08 UTC (rev 7954)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/Customer.java	2006-11-29 22:51:18 UTC (rev 7955)
@@ -30,6 +30,7 @@
 	public int		ssn=0;
 	public String	email="";
 	public int creditScore=0;
+	public String quoteID, rateOffered, quoteCode;
 	
 	public String getCSV() {
 		String buff = (name+","+ssn+","+address+","+employerName+","+salary+","

Modified: 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-29 22:28:08 UTC (rev 7954)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/LoanBroker.java	2006-11-29 22:51:18 UTC (rev 7955)
@@ -38,6 +38,8 @@
 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 com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
 
 /*
  * LoanBroker is responsible for getting customer requests for loans onto the JBoss ESB
@@ -65,6 +67,20 @@
 		
 	}
 	
+	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 void processLoanRequest(WebCustomer wCustomer){
 		
 		Customer customer = getCustomer(wCustomer);
@@ -84,22 +100,6 @@
 		
 	}
 	
-	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;
-	}
-	
-	
-	
 	private void sendToJMSBank(Customer customer) {
 		try {
 			//create a Quote Request that the bank expects
@@ -109,11 +109,18 @@
 			quote.creditScore=customer.creditScore;
 			quote.creditHistoryLen=0;	//not sure who added this one
 			quote.term=customer.loanDuration;
+			quote.customerUniqueId=String.valueOf(customer.ssn);	//cheat and use the ssn as the unique i.d for now
 			
+			
+			
+//			XStream xstream = new XStream(new DomDriver());
+//			xstream.alias("org.jboss.soa.esb.samples.loanbroker.banks", QuoteRequest.class);
+//			String quoteXML = xstream.toXML(QuoteRequest.class);
+			
 			SendJMSMessage sender = new SendJMSMessage();
 			sender.setupConnection(
 					ModulePropertyManager.getPropertyManager(MODULE_NAME).getProperty(JMS_BANK_QUEUE));
-			sender.sendAMessage(quote.toString());
+			sender.sendAMessage(quote.getCSV());
 			sender.stop();
 		}catch (Exception e) {
 			logger.error(e);

Modified: labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/QuoteRequest.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/QuoteRequest.java	2006-11-29 22:28:08 UTC (rev 7954)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/QuoteRequest.java	2006-11-29 22:51:18 UTC (rev 7955)
@@ -118,6 +118,10 @@
 			+ ", customerUniqueId="+ customerUniqueId + "]";	
 	}
 	
+	public String getCSV() {
+		return (ssn+","+creditScore+","+creditHistoryLen+","+amount+","+term+","+customerUniqueId);
+	}
+	
 	public String getCustomerUniqueId() {
 		return customerUniqueId;
 	}

Modified: labs/jbossesb/trunk/product/samples/trailblazer2/esb/conf/banksgateway-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/esb/conf/banksgateway-esb.xml	2006-11-29 22:28:08 UTC (rev 7954)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/esb/conf/banksgateway-esb.xml	2006-11-29 22:51:18 UTC (rev 7955)
@@ -1,17 +1,15 @@
 <jms-banks-gateway parameterReloadSecs="180">
 	<esb-jms-gateway 
 		target-service-category="trailblazer" 
-		target-service-name="jmsbank" 
+		target-service-name="jmsbankreplies" 
 		gatewayClass="org.jboss.soa.esb.listeners.gateway.JmsGatewayListener" 
 		connection-factory="ConnectionFactory" 
 		destination-type="queue" 
-		destination-name="queue/A" 
+		destination-name="queue/D" 
 		jndi-type="jboss" 
-		jndi-URL="localhost"
-		message-selector="service='jmsbankresponse'"
-	>
+		jndi-URL="localhost">
 	<!--  no action needed as the inbound message is automatically converted
-     and sent to the queue for the target service"product/samples/trailblazer2/build.xml" 
+     and sent to the queue for the target service
   --> 
   	</esb-jms-gateway>
 </jms-banks-gateway>

Modified: labs/jbossesb/trunk/product/samples/trailblazer2/esb/conf/loanbroker-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/esb/conf/loanbroker-esb.xml	2006-11-29 22:28:08 UTC (rev 7954)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/esb/conf/loanbroker-esb.xml	2006-11-29 22:51:18 UTC (rev 7955)
@@ -1,39 +1,41 @@
 <Trailblazer parameterReloadSecs="180">
 
    <CreditCheck
-	service-category="trailblazer"
-	service-name="creditagency"
-   	listenerClass="org.jboss.soa.esb.listeners.message.JmsQueueListener"
-	connection-factory="ConnectionFactory"
-	destination-type="queue"
-   	destination-name="queue/A"
-	jndi-type="jboss"
-	jndi-URL="localhost"	
-	message-selector="service='creditAgency'"
-	maxThreads="2"
-    >        
-    <action class="org.jboss.soa.esb.samples.trailblazer.actions.CreditAgencyActions" process="processCreditRequest"/>
-    <!--  action class="org.jboss.soa.esb.actions.converters.SmooksTransformer" 		
-		from-type="text/csv:CreditCheck"
-		from-epr="trailblazer:loanbroker"
-		to-type="text/xml:CreditCheck"
-		to-epr="trailblazer:creditcheck" -->
-	
-	
+		service-category="trailblazer"
+		service-name="creditagency"
+	   	listenerClass="org.jboss.soa.esb.listeners.message.JmsQueueListener"
+		connection-factory="ConnectionFactory"
+		destination-type="queue"
+	   	destination-name="queue/A"
+		jndi-type="jboss"
+		jndi-URL="localhost"	
+		message-selector="service='creditAgency'"
+		maxThreads="1"
+	    >        
+	    <action class="org.jboss.soa.esb.samples.trailblazer.actions.CreditAgencyActions" process="processCreditRequest"/>
+    
    </CreditCheck>
    
+	<!-- 
+	this service will be invoked by the gateway service listening for bank repsonses.
+	It will immediately convert the xml message form the bank using smooks, then send
+	the message onto the bankresponseactions method
+	 -->
    <JMSBankResponse
-	service-category="trailblazer"
-	service-name="jmsbank"
-   	listenerClass="org.jboss.soa.esb.listeners.message.JmsQueueListener"
-	connection-factory="ConnectionFactory"
-	destination-type="queue"
-   	destination-name="queue/A"
-	jndi-type="jboss"
-	jndi-URL="localhost"	
-	message-selector="service='jmsbankresponse'"
-	maxThreads="1">
-	
-   </JMSBankResponse>
+		service-category="trailblazer"
+		service-name="jmsbankreplies"
+	   	listenerClass="org.jboss.soa.esb.listeners.message.JmsQueueListener"
+		connection-factory="ConnectionFactory"
+		destination-type="queue"
+	   	destination-name="queue/D"
+		jndi-type="jboss"
+		jndi-URL="localhost"	
+		maxThreads="1">
+		
+		<action class="org.jboss.soa.esb.samples.trailblazer.actions.BankResponseActions" process="processResponseFromJMSBank"/>
+    
+   </JMSBankResponse>
+   
    
+   
 </Trailblazer>

Modified: labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/actions/CreditAgencyActions.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/actions/CreditAgencyActions.java	2006-11-29 22:28:08 UTC (rev 7954)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/actions/CreditAgencyActions.java	2006-11-29 22:51:18 UTC (rev 7955)
@@ -18,7 +18,7 @@
  * MA  02110-1301, USA.
  * 
  * (C) 2005-2006,
- * @author mark.little at jboss.com
+ * @daniel.brum at jboss.com
  */
 
 import org.apache.log4j.Logger;

Added: labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/ProcessEmail.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/ProcessEmail.java	2006-11-29 22:28:08 UTC (rev 7954)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/ProcessEmail.java	2006-11-29 22:51:18 UTC (rev 7955)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.soa.esb.samples.trailblazer.util;
+
+import org.antlr.stringtemplate.StringTemplate;
+import org.antlr.stringtemplate.StringTemplateGroup;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.helpers.Email;
+
+
+public class ProcessEmail {
+	
+	private Logger logger = Logger.getLogger(this.getClass());
+	private org.jboss.soa.esb.samples.trailblazer.loanbroker.Customer customer = null;
+
+	public ProcessEmail(org.jboss.soa.esb.samples.trailblazer.loanbroker.Customer customer) {
+		logger.debug("creating email helper");
+		this.customer=customer;				
+	}
+	
+	public void sendEmail() {		
+		try {
+			String address = customer.email;
+			if (null==address) {
+				logger.info("no email address found for customer SSN  "+customer.ssn+" - no email being sent");
+				return;
+			}
+			logger.info("customer SSN " + customer.ssn + " - sending email to: " + address);
+			Email email = new Email();			
+			email.setSendTo(address);
+			email.setSubject("TrailBlazer Quote from Bank");
+//			File emailTemplate = new File(LoanBrokerConstants.EMAIL_TEMPLATE);
+//			String quoteMsg=FileUtil.readTextFile(emailTemplate);
+			email.setMessage(fillTemplate());
+			email.sendMessage();			
+		}catch (Exception e) {			
+			logger.error("error sending email - " + e);	
+			e.printStackTrace();		
+		}		
+	}
+	
+	private String fillTemplate() throws Exception{
+		StringTemplateGroup group =  new StringTemplateGroup("loan",
+				ModulePropertyManager.getPropertyManager("trailblazer").
+				getProperty("org.jboss.soa.esb.trailblazer.email.template.path"));
+		StringTemplate email = group.getInstanceOf(
+				ModulePropertyManager.getPropertyManager("trailblazer").
+				getProperty("org.jboss.soa.esb.trailblazer.email.template.file"));		
+		email.setAttribute("name", 		customer.name);
+		email.setAttribute("address",	customer.address);
+		email.setAttribute("ssn", 		customer.ssn);
+		email.setAttribute("email", 	customer.email);
+		email.setAttribute("salary", 	customer.salary);
+		email.setAttribute("amount", 	customer.loanAmount);
+		email.setAttribute("duration", 	customer.loanDuration);
+		email.setAttribute("quote", 	customer.quoteID);
+		email.setAttribute("rate", 		customer.rateOffered);
+		email.setAttribute("code", 		customer.quoteCode);
+				
+		return email.toString();
+		
+	}
+
+}

Modified: labs/jbossesb/trunk/product/samples/trailblazer2/trailblazer-properties.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/trailblazer-properties.xml	2006-11-29 22:28:08 UTC (rev 7954)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/trailblazer-properties.xml	2006-11-29 22:51:18 UTC (rev 7955)
@@ -79,6 +79,8 @@
     <properties name="trailblazer">
 		<property name="org.jboss.soa.esb.trailblazer.request.service.epr.name" value="creditagency"/>
 		<property name="org.jboss.soa.esb.trailblazer.request.service.category" value="trailblazer"/>
-		<property name="org.jboss.soa.esb.trailblazer.jmsbank.queue" value="queue/C"/>	
+		<property name="org.jboss.soa.esb.trailblazer.jmsbank.queue" value="queue/C"/>
+		<property name="org.jboss.soa.esb.trailblazer.email.template.path" value="template"/>
+		<property name="org.jboss.soa.esb.trailblazer.email.template.file" value="quote"/>		
     </properties>
 </esb>




More information about the jboss-svn-commits mailing list