1 17 package org.apache.servicemix.eip.patterns; 18 19 import javax.jbi.management.DeploymentException; 20 import javax.jbi.messaging.ExchangeStatus; 21 import javax.jbi.messaging.InOnly; 22 import javax.jbi.messaging.MessageExchange; 23 import javax.jbi.messaging.NormalizedMessage; 24 import javax.jbi.messaging.RobustInOnly; 25 26 import org.apache.servicemix.eip.EIPEndpoint; 27 import org.apache.servicemix.eip.support.ExchangeTarget; 28 import org.apache.servicemix.jbi.util.MessageUtil; 29 30 42 public class StaticRecipientList extends EIPEndpoint { 43 44 47 private ExchangeTarget[] recipients; 48 57 private boolean reportErrors; 58 61 private String correlation; 62 63 66 public ExchangeTarget[] getRecipients() { 67 return recipients; 68 } 69 70 73 public void setRecipients(ExchangeTarget[] recipients) { 74 this.recipients = recipients; 75 } 76 77 80 public boolean isReportErrors() { 81 return reportErrors; 82 } 83 84 87 public void setReportErrors(boolean reportErrors) { 88 this.reportErrors = reportErrors; 89 } 90 91 94 public void validate() throws DeploymentException { 95 super.validate(); 96 if (recipients == null || recipients.length == 0) { 98 throw new IllegalArgumentException ("recipients should contain at least one ExchangeTarget"); 99 } 100 correlation = "StaticRecipientList.Correlation." + getService() + "." + getEndpoint(); 102 } 103 104 107 protected void processSync(MessageExchange exchange) throws Exception { 108 if (exchange instanceof InOnly == false && 109 exchange instanceof RobustInOnly == false) { 110 fail(exchange, new UnsupportedOperationException ("Use an InOnly or RobustInOnly MEP")); 111 return; 112 } 113 NormalizedMessage in = MessageUtil.copyIn(exchange); 114 for (int i = 0; i < recipients.length; i++) { 115 MessageExchange me = exchangeFactory.createExchange(exchange.getPattern()); 116 recipients[i].configureTarget(me, getContext()); 117 MessageUtil.transferToIn(in, me); 118 sendSync(me); 119 if (me.getStatus() == ExchangeStatus.ERROR && reportErrors) { 120 fail(exchange, me.getError()); 121 return; 122 } 123 } 124 done(exchange); 125 } 126 127 130 protected void processAsync(MessageExchange exchange) throws Exception { 131 if (reportErrors) { 135 throw new UnsupportedOperationException ("Not implemented"); 137 } else { 141 if (exchange.getStatus() == ExchangeStatus.DONE) { 142 return; 143 } else if (exchange.getStatus() == ExchangeStatus.ERROR) { 144 return; 145 } else if (exchange instanceof InOnly == false && 146 exchange instanceof RobustInOnly == false) { 147 fail(exchange, new UnsupportedOperationException ("Use an InOnly or RobustInOnly MEP")); 148 } else if (exchange.getFault() != null) { 149 done(exchange); 150 } else { 151 NormalizedMessage in = MessageUtil.copyIn(exchange); 152 for (int i = 0; i < recipients.length; i++) { 153 MessageExchange me = exchangeFactory.createExchange(exchange.getPattern()); 154 recipients[i].configureTarget(me, getContext()); 155 MessageUtil.transferToIn(in, me); 156 send(me); 157 } 158 done(exchange); 159 } 160 } 161 } 162 163 } 164 | Popular Tags |