[jboss-svn-commits] JBL Code SVN: r8969 - labs/jbossesb/trunk/product/samples/trailblazer/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jan 22 12:54:26 EST 2007


Author: daniel.brum at jboss.com
Date: 2007-01-22 12:54:26 -0500 (Mon, 22 Jan 2007)
New Revision: 8969

Modified:
   labs/jbossesb/trunk/product/samples/trailblazer/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/LoanBroker.java
Log:
2Way courier used for CreditAgency interaction


Modified: labs/jbossesb/trunk/product/samples/trailblazer/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/LoanBroker.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/LoanBroker.java	2007-01-22 17:38:47 UTC (rev 8968)
+++ labs/jbossesb/trunk/product/samples/trailblazer/client/src/org/jboss/soa/esb/samples/trailblazer/loanbroker/LoanBroker.java	2007-01-22 17:54:26 UTC (rev 8969)
@@ -24,11 +24,12 @@
 
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.actions.ActionProcessingException;
-import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.Call;
 import org.jboss.soa.esb.addressing.eprs.JMSEpr;
 import org.jboss.soa.esb.common.ModulePropertyManager;
-import org.jboss.soa.esb.couriers.Courier;
 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;
@@ -129,22 +130,8 @@
 	private int sendToCreditAgency(Customer customer) {
 		Message message = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
 		Message replyMessage=null;
-		int score =0;
+		int score =0;				
 		
-		//convert our customer to a bean xml representation
-		//		XMLEncoder encoder=null;
-		//		try {
-		//			ByteArrayOutputStream bytes = new ByteArrayOutputStream();
-		//			ObjectOutputStream oos = new ObjectOutputStream(bytes);
-		//			encoder = new XMLEncoder(oos);
-		//			encoder.writeObject(wCustomer);
-		//			encoder.close();
-		//			System.out.println("encoded customer: "+ bytes.toString());
-		//		} catch (IOException e2) {
-		//			// TODO Auto-generated catch block
-		//			e2.printStackTrace();
-		//		}		
-		
 		//set the customer inside the message - csv format for now to test
 		message.getBody().setContents(customer.getCSV().getBytes());	
 		
@@ -158,44 +145,43 @@
 			logger.debug("looking for the following service in the registry -- Name: " + serviceName);
 			
 			//EPRs to use for delivery and reply messages
-			EPR toEPR=null;
+			JMSEpr toEPR=null, replyEPR=null;
 			
 			//find the service in the registry
 			toEPR = (JMSEpr)registry.findEPR(serviceCategoryName, serviceName);
 
 			//use a 2-way courier so we can grab the response
-//			TwoWayCourier courier = CourierFactory.getCourier(toEPR, null);			
-			Courier courier = CourierFactory.getCourier(toEPR);
+			TwoWayCourier courier = CourierFactory.getCourier(toEPR, null);			
 			
-//			if (message.getHeader().getCall()==null) {
-//				Call call = new Call();
-//				message.getHeader().setCall(call);
-//			}			
+			//needs to have this in order to get the reply
+			if (message.getHeader().getCall()==null) {
+				Call call = new Call();
+				message.getHeader().setCall(call);
+			}			
 			
 			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); }			
 			
-//			replyEPR = CourierUtil.getTemporaryReplyToEpr(toEPR);
-//			message.getHeader().getCall().setReplyTo(replyEPR);		
+			replyEPR = (JMSEpr)CourierUtil.getTemporaryReplyToEpr(toEPR);
+			message.getHeader().getCall().setReplyTo(replyEPR);
+			
+			//send the message and get the response
 			if (courier.deliver(message)) {				
-//				courier.setReplyToEpr(replyEPR);
-//				replyMessage = courier.pickup(5000);	//TODO: replace with a time value from Config
+				courier.setReplyToEpr(replyEPR);
+				replyMessage = courier.pickup(5000);	//wait for 5 seconds then give up
 				if (replyMessage !=null) {
 					logger.debug("received reply from creditAgency action");
 					logger.debug("message received: " + replyMessage.getBody().getContents());
-					score = new Integer(new String(replyMessage.getBody().getContents())).intValue();
-					
-					
+					score = new Integer(new String(replyMessage.getBody().getContents())).intValue();					
+				}else {
+					logger.debug("reply not received from credit agency - setting a value of 5");
+					score = 5; 
 				}
 			} else
 				throw new ActionProcessingException("error delivering the message to the credit agency");
 			
-			
-			
-//		}catch(CourierTimeoutException ex1) {
-//			logger.error("timeout occured waiting for creditAgency response -  " + ex1);
 		}catch (Exception ex2) {
 			logger.error("exception occured: " + ex2);
 			ex2.printStackTrace();




More information about the jboss-svn-commits mailing list