1 22 package org.objectweb.petals.demo.mortgage.workflow.orchestration; 23 24 import java.util.logging.Level ; 25 import java.util.logging.Logger ; 26 27 import javax.jbi.messaging.DeliveryChannel; 28 import javax.jbi.messaging.InOut; 29 import javax.jbi.messaging.MessageExchange; 30 import javax.jbi.messaging.NormalizedMessage; 31 import javax.xml.namespace.QName ; 32 import javax.xml.transform.Source ; 33 34 import org.objectweb.petals.component.common.HandlingException; 35 import org.objectweb.petals.component.common.PEtALSComponentSDKException; 36 import org.objectweb.petals.component.common.util.SourceHelper; 37 38 44 public class DetailedMortgageProfiling implements MortgageProfiling { 45 46 public final static String MORTGAGE_SERVICE = "ProfilerImplService"; 47 48 public final static String MORTGAGE_SERVICE_OP = "evaluateDetailedProfile"; 49 50 protected DeliveryChannel channel; 51 52 protected Logger l; 53 54 protected MortgageProfilingUtil profilingUtil; 55 56 public DetailedMortgageProfiling() { 57 super(); 58 } 59 60 69 public DetailedMortgageProfiling(DeliveryChannel channel, Logger l) { 70 super(); 71 this.channel = channel; 72 this.l = l; 73 profilingUtil = new MortgageProfilingUtil(channel, l); 74 75 } 76 77 85 public MortgageResponse orchestrate(MortgageRequest request) 86 throws HandlingException { 87 MortgageResponse response = null; 88 89 if (request == null) { 90 throw new HandlingException("MortgageRequest must not be null !"); 91 } 92 93 l.info("###################################################"); 94 l.info("#### PROCESSING A DETAILED MORTGAGE RATE EVALUATION"); 95 l.info("###################################################"); 96 97 100 l.info("##### First step : Evalute Mortgage Profile #####"); 101 String profile = doEvalProfile(request.getSalary(), request 102 .getPropertyTaxes(), request.getInsurance(), request 103 .getAutoPayment(), request.getCreditCards(), request 104 .getOtherPayments()); 105 106 109 l.info("##### Second Step : Evaluate Mortgage Rate #####"); 110 if (profilingUtil == null) { 111 profilingUtil = new MortgageProfilingUtil(channel, l); 112 } 113 float rate = profilingUtil.doEvalMortgageRate(profile); 114 115 118 response = profilingUtil.createMortgageResponse(rate, request); 119 l 120 .info("##### Last Step : Send the response to the Mortgage requester#####"); 121 122 125 profilingUtil.doSendSummary(response); 126 127 return response; 128 } 129 130 151 protected Source createInMessageContent(float salary, float propertyTaxes, 152 float insurance, float autoPayment, float creditCards, 153 float otherPayments) throws PEtALSComponentSDKException { 154 155 StringBuffer soap = new StringBuffer (); 156 soap.append("<ns1:" + MORTGAGE_SERVICE_OP 157 + " xmlns:ns1=\"http://petals.objectweb.org/\">"); 158 soap.append("<salary>" + salary + "</salary>"); 159 soap.append("<propertyTaxes>" + propertyTaxes + "</propertyTaxes>"); 160 soap.append("<insurance>" + insurance + "</insurance>"); 161 soap.append("<autoPayment>" + autoPayment + "</autoPayment>"); 162 soap.append("<creditCards>" + creditCards + "</creditCards>"); 163 soap.append("<otherPayments>" + otherPayments + "</otherPayments>"); 164 soap.append("</ns1:" + MORTGAGE_SERVICE_OP + ">"); 165 166 return SourceHelper.createSource(soap.toString()); 167 } 168 169 183 protected String doEvalProfile(float salary, float propertyTaxes, 184 float insurance, float autoPayment, float creditCards, 185 float otherPayments) throws HandlingException { 186 187 MessageExchange msg = null; 188 try { 189 192 Source source = createInMessageContent(salary, propertyTaxes, 193 insurance, autoPayment, creditCards, otherPayments); 194 195 198 msg = channel.createExchangeFactory().createInOutExchange(); 199 msg.setService(new QName (MortgageProfilingUtil.DEFAULT_NS, 200 MORTGAGE_SERVICE)); 201 msg.setOperation(new QName (MORTGAGE_SERVICE_OP)); 202 203 206 NormalizedMessage inNM = msg.createMessage(); 207 inNM.setContent(source); 208 ((InOut) msg).setInMessage(inNM); 209 210 213 channel.sendSync(msg); 214 } catch (Exception e) { 215 throw new HandlingException("Error evaluating profile", e); 216 } 217 220 NormalizedMessage outNM = ((InOut) msg).getOutMessage(); 221 String response = "ProfileNotDefined"; 222 if (outNM != null) { 223 try { 224 response = SourceHelper.createString(outNM.getContent()); 225 } catch (PEtALSComponentSDKException e) { 226 throw new HandlingException(e); 227 } 228 if (response.indexOf("return") > -1) { 229 response = response.substring(response.indexOf("<return>") + 8, 230 response.indexOf("</return>")); 231 l.log(Level.INFO, response); 232 } 233 } else { 234 throw new HandlingException( 235 "Mortgage profiler web service response is null"); 236 } 237 l.info("##### Evaluated profile : " + response + " #####"); 238 return response; 239 } 240 241 } 242 | Popular Tags |