1 22 package org.objectweb.petals.component.common.basic; 23 24 import java.net.URI ; 25 import java.util.logging.Logger ; 26 27 import javax.jbi.messaging.DeliveryChannel; 28 import javax.jbi.messaging.ExchangeStatus; 29 import javax.jbi.messaging.MessageExchange; 30 import javax.jbi.messaging.NormalizedMessage; 31 import javax.xml.namespace.QName ; 32 33 import org.objectweb.petals.component.common.MEPConstants; 34 35 42 public abstract class AbstractComponent extends AbstractBasicComponent { 43 44 47 public AbstractComponent() { 48 super(); 49 } 50 51 57 public AbstractComponent(DeliveryChannel channel, Logger log) { 58 super(channel, log); 59 } 60 61 66 public boolean process(MessageExchange exchange) throws Exception { 67 if (ExchangeStatus.ACTIVE.equals(exchange.getStatus())) { 68 if (MessageExchange.Role.PROVIDER.equals(exchange.getRole())) { 69 if (MEPConstants.IN_ONLY_PATTERN.equals(exchange.getPattern())) { 70 processInOnly(exchange); 71 } else if (MEPConstants.ROBUST_IN_ONLY_PATTERN.equals(exchange 72 .getPattern())) { 73 processRobustInOnly(exchange); 74 } else if (MEPConstants.IN_OUT_PATTERN.equals(exchange 75 .getPattern()) 76 || MEPConstants.IN_OPTIONAL_OUT_PATTERN.equals(exchange 77 .getPattern())) { 78 processInOut(exchange); 79 } else { 80 Exception e = new Exception ( 81 "MessageExchangePattern not recognized :" 82 + exchange.getPattern()); 83 exchange.setError(e); 84 getDeliveryChannel().send(exchange); 85 throw e; 86 } 87 getDeliveryChannel().send(exchange); 88 } 89 } 90 return true; 91 } 92 93 101 protected void processInOnly(MessageExchange exchange) throws Exception { 102 try { 103 handleMessage(exchange.getEndpoint().getServiceName(), exchange 104 .getOperation(), exchange.getMessage("in"), exchange 105 .getMessage("out"), exchange.getPattern()); 106 } catch (Exception e) { 107 logError(new Exception ( 109 "Error occured while processing, but InOnly message can not contains Fault.", 110 e)); 111 } 112 exchange.setStatus(ExchangeStatus.DONE); 113 } 114 115 123 protected void processInOut(MessageExchange exchange) throws Exception { 124 try { 125 if (!ackFaultReception(exchange)) { 126 NormalizedMessage out = createNormalizedMessage(exchange); 127 128 boolean outTreated = handleMessage(exchange.getEndpoint() 129 .getServiceName(), exchange.getOperation(), exchange 130 .getMessage("in"), out, exchange.getPattern()); 131 132 if (outTreated) { 133 exchange.setMessage(out, "out"); 134 } else { 135 exchange.setStatus(ExchangeStatus.DONE); 136 } 137 } 138 } catch (Exception e) { 139 try { 140 exchange.setFault(createFault(e, exchange)); 141 } catch (Exception e1) { 142 logError(new Exception ( 143 "Error occured while processing, send a Fault.", e1)); 144 } 145 } 146 } 147 148 156 protected void processRobustInOnly(MessageExchange exchange) 157 throws Exception { 158 try { 159 handleMessage(exchange.getEndpoint().getServiceName(), exchange 160 .getOperation(), exchange.getMessage("in"), exchange 161 .getMessage("out"), exchange.getPattern()); 162 exchange.setStatus(ExchangeStatus.DONE); 163 } catch (Exception e) { 164 try { 165 exchange.setFault(createFault(e, exchange)); 166 } catch (Exception e1) { 167 logError(new Exception ( 168 "Error occured while processing, send a Fault.", e1)); 169 } 170 } 171 } 172 173 197 protected abstract boolean handleMessage(QName service, QName operation, 198 NormalizedMessage in, NormalizedMessage out, 199 URI messageExhangePattern) throws Exception ; 200 201 } 202 | Popular Tags |