use of org.apache.cxf.phase.PhaseInterceptor 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.phase.PhaseInterceptor in project tesb-rt-se by Talend.
the class DemoInterceptor method printInterceptorChain.
/**
* Prints out the interceptor chain in a format that is easy to read. It
* also filters out instances of the DemoInterceptor so you can see what the
* chain would look like in a normal invokation.
*
* @param chain
*/
public void printInterceptorChain(InterceptorChain chain) {
Iterator<Interceptor<? extends Message>> it = chain.iterator();
String phase = "";
StringBuilder builder = null;
while (it.hasNext()) {
Interceptor<? extends Message> interceptor = it.next();
if (interceptor instanceof DemoInterceptor) {
continue;
}
if (interceptor instanceof PhaseInterceptor) {
PhaseInterceptor pi = (PhaseInterceptor) interceptor;
if (!phase.equals(pi.getPhase())) {
if (builder != null) {
System.out.println(builder.toString());
} else {
builder = new StringBuilder(100);
}
builder.setLength(0);
builder.append(" ");
builder.append(pi.getPhase());
builder.append(": ");
phase = pi.getPhase();
}
String id = pi.getId();
int idx = id.lastIndexOf('.');
if (idx != -1) {
id = id.substring(idx + 1);
}
builder.append(id);
builder.append(' ');
}
}
}
use of org.apache.cxf.phase.PhaseInterceptor in project cxf by apache.
the class MaskSensitiveHelperTest method shouldReplaceSensitiveDataIn.
@Test
public void shouldReplaceSensitiveDataIn() {
// Arrange
final LoggingInInterceptor inInterceptor = new LoggingInInterceptor(logEventSender);
inInterceptor.addSensitiveElementNames(SENSITIVE_ELEMENTS);
final Message message = prepareInMessage();
// Act
Collection<PhaseInterceptor<? extends Message>> interceptors = inInterceptor.getAdditionalInterceptors();
for (PhaseInterceptor intercept : interceptors) {
intercept.handleMessage(message);
}
inInterceptor.handleMessage(message);
// Verify
LogEvent event = logEventSender.getLogEvent();
assertNotNull(event);
assertEquals(maskedContent, event.getPayload());
}
use of org.apache.cxf.phase.PhaseInterceptor in project cxf by apache.
the class TransformTest method transformInboundInterceptorReader.
@Test
public void transformInboundInterceptorReader() {
// Arrange
Message message = new MessageImpl();
StringReader stringReader = new StringReader(ORIG_LOGGING_CONTENT);
message.setContent(Reader.class, stringReader);
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
LogEventSenderMock logEventSender = new LogEventSenderMock();
LoggingInInterceptor interceptor = new TransformLoggingInInterceptor(logEventSender);
// Act
Collection<PhaseInterceptor<? extends Message>> interceptors = interceptor.getAdditionalInterceptors();
for (PhaseInterceptor intercept : interceptors) {
intercept.handleMessage(message);
}
interceptor.handleMessage(message);
// Verify
LogEvent event = logEventSender.getLogEvent();
assertNotNull(event);
// only the first byte is read!
assertEquals(TRANSFORMED_LOGGING_CONTENT, event.getPayload());
}
use of org.apache.cxf.phase.PhaseInterceptor in project cxf by apache.
the class TransformTest method transformInboundInterceptorInputStream.
@Test
public void transformInboundInterceptorInputStream() {
// Arrange
Message message = new MessageImpl();
ByteArrayInputStream inputStream = new ByteArrayInputStream(ORIG_LOGGING_CONTENT.getBytes(StandardCharsets.UTF_8));
message.setContent(InputStream.class, inputStream);
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
LogEventSenderMock logEventSender = new LogEventSenderMock();
LoggingInInterceptor interceptor = new TransformLoggingInInterceptor(logEventSender);
// Act
Collection<PhaseInterceptor<? extends Message>> interceptors = interceptor.getAdditionalInterceptors();
for (PhaseInterceptor intercept : interceptors) {
intercept.handleMessage(message);
}
interceptor.handleMessage(message);
// Verify
LogEvent event = logEventSender.getLogEvent();
assertNotNull(event);
// only the first byte is read!
assertEquals(TRANSFORMED_LOGGING_CONTENT, event.getPayload());
}
Aggregations