1 22 package org.objectweb.petals.demo.mortgage.workflow.sdk; 23 24 import java.net.URI ; 25 26 import javax.jbi.JBIException; 27 import javax.jbi.servicedesc.ServiceEndpoint; 28 import javax.xml.namespace.QName ; 29 30 import org.objectweb.petals.component.common.HandlingException; 31 import org.objectweb.petals.component.common.MEPConstants; 32 import org.objectweb.petals.component.common.se.AbstractServiceEngine; 33 import org.objectweb.petals.component.common.util.MessageExchangeWrapper; 34 import org.objectweb.petals.tools.jbicommon.descriptor.Extensions; 35 36 41 public class MortgageWorkflowEngine extends AbstractServiceEngine { 42 43 private ServiceEndpoint endpoint1; 44 45 private ServiceEndpoint endpoint2; 46 47 private static final String SERVICE = "MortgageWorkflow"; 48 49 private static final QName SERVICE_NAME = new QName ( 50 "http://petals.objectweb.org/", SERVICE); 51 52 public static final String ENDPOINT1 = "simpleMortgageProfiler"; 53 54 public static final String ENDPOINT2 = "detailedMortgageProfiler"; 55 56 private MortgageWorkflow workflow; 57 58 @Override 59 protected boolean onExchange(MessageExchangeWrapper exchange, 60 Extensions extensions) throws HandlingException { 61 String outContent = null; 62 boolean outResponse = false; 63 64 String opName = exchange.getOperationName(); 66 67 URI pattern = exchange.getExchangePattern(); 69 70 String stringContent = exchange.getInMessageContent(); 72 73 String endpointName = exchange.getEndpointName(); 75 76 if ("orchestrate".equalsIgnoreCase(opName) 77 && pattern.equals(MEPConstants.IN_OPTIONAL_OUT_PATTERN.value())) { 78 try { 79 outContent = workflow.orchestrate(endpointName, stringContent); 80 } catch (Exception e) { 81 throw new HandlingException(e); 82 } 83 } else { 84 throw new HandlingException("Operation not allowed (" + opName 85 + ") with the following pattern (" + pattern + ")"); 86 } 87 88 if (outContent != null) { 89 exchange.setOutMessageContent(outContent); 90 outResponse = true; 91 } else { 92 throw new HandlingException(opName 93 + " method returns a null result"); 94 } 95 96 return outResponse; 97 } 98 99 @Override 100 public void start() throws JBIException { 101 super.start(); 102 workflow = new MortgageWorkflowImpl(getLogger(), getChannel()); 103 endpoint1 = getContext().activateEndpoint(SERVICE_NAME, ENDPOINT1); 104 endpoint2 = getContext().activateEndpoint(SERVICE_NAME, ENDPOINT2); 105 106 } 107 108 @Override 109 public void stop() throws JBIException { 110 super.stop(); 111 workflow = null; 112 getContext().deactivateEndpoint(endpoint1); 113 getContext().deactivateEndpoint(endpoint2); 114 } 115 116 } 117 | Popular Tags |