use of org.apache.cxf.interceptor.MessageSenderInterceptor in project camel by apache.
the class MessageLossSimulator method handleMessage.
public void handleMessage(Message message) throws Fault {
Object maps = RMContextUtils.retrieveMAPs(message, false, true);
// RMContextUtils.ensureExposedVersion(maps);
String action = getAction(maps);
if (RMContextUtils.isRMProtocolMessage(action)) {
return;
}
appMessageCount++;
// do not discard odd-numbered messages
if (0 != (appMessageCount % 2)) {
return;
}
// discard even-numbered message
InterceptorChain chain = message.getInterceptorChain();
ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
while (it.hasNext()) {
PhaseInterceptor<?> pi = (PhaseInterceptor<?>) it.next();
if (MessageSenderInterceptor.class.getName().equals(pi.getId())) {
chain.remove(pi);
LOG.debug("Removed MessageSenderInterceptor from interceptor chain.");
break;
}
}
message.setContent(OutputStream.class, new WrappedOutputStream(message));
message.getInterceptorChain().add(new AbstractPhaseInterceptor<Message>(Phase.PREPARE_SEND_ENDING) {
public void handleMessage(Message message) throws Fault {
try {
message.getContent(OutputStream.class).close();
} catch (IOException e) {
throw new Fault(e);
}
}
});
}
use of org.apache.cxf.interceptor.MessageSenderInterceptor in project cxf by apache.
the class MessageLossSimulator method handleMessage.
public void handleMessage(Message message) throws Fault {
AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true);
String action = null;
if (maps != null && null != maps.getAction()) {
action = maps.getAction().getValue();
}
if (RMContextUtils.isRMProtocolMessage(action)) {
return;
}
if (MessageUtils.isPartialResponse(message)) {
return;
}
if (Boolean.TRUE.equals(message.get(RMMessageConstants.RM_RETRANSMISSION))) {
return;
}
if (mode == 1) {
// never lose
return;
} else if (mode == -1) {
// always lose
} else {
// alternatively lose
synchronized (this) {
appMessageCount++;
if (0 != (appMessageCount % 2)) {
return;
}
}
}
InterceptorChain chain = message.getInterceptorChain();
ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
while (it.hasNext()) {
PhaseInterceptor<?> pi = (PhaseInterceptor<? extends Message>) it.next();
if (MessageSenderInterceptor.class.getName().equals(pi.getId())) {
chain.remove(pi);
LOG.fine("Removed MessageSenderInterceptor from interceptor chain.");
break;
}
}
message.setContent(OutputStream.class, new WrappedOutputStream(message));
message.getInterceptorChain().add(new MessageLossEndingInterceptor(throwsException));
}
use of org.apache.cxf.interceptor.MessageSenderInterceptor in project cxf by apache.
the class MessageLossSimulator method handleMessage.
// CHECKSTYLE:OFF: ReturnCount
public void handleMessage(Message message) throws Fault {
AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true);
// Fixed the build error of ws_rm, now there is no ensureExposedVersion anymore
// RMContextUtils.ensureExposedVersion(maps);
String action = null;
if (maps != null && null != maps.getAction()) {
action = maps.getAction().getValue();
}
if (RMContextUtils.isRMProtocolMessage(action)) {
return;
}
appMessageCount++;
// do not discard odd-numbered messages
if (0 != (appMessageCount % 2)) {
return;
}
// discard even-numbered message
InterceptorChain chain = message.getInterceptorChain();
ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
while (it.hasNext()) {
PhaseInterceptor<? extends Message> pi = (PhaseInterceptor<? extends Message>) it.next();
if (MessageSenderInterceptor.class.getName().equals(pi.getId())) {
chain.remove(pi);
LOG.info("Removed MessageSenderInterceptor from interceptor chain.");
break;
}
}
message.setContent(OutputStream.class, new WrappedOutputStream(message));
message.getInterceptorChain().add(new AbstractPhaseInterceptor<Message>(Phase.PREPARE_SEND_ENDING) {
public void handleMessage(Message message) throws Fault {
try {
message.getContent(OutputStream.class).close();
} catch (IOException e) {
throw new Fault(e);
}
}
});
}
Aggregations