use of org.apache.cxf.message.ExchangeImpl 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());
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class TransformTest method transformOutboundInterceptorOutputStream.
@Test
public void transformOutboundInterceptorOutputStream() throws IOException {
// Arrange
Message message = new MessageImpl();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
message.setContent(OutputStream.class, outputStream);
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
LogEventSenderMock logEventSender = new LogEventSenderMock();
LoggingOutInterceptor interceptor = new TransformLoggingOutInterceptor(logEventSender);
// Act
interceptor.handleMessage(message);
byte[] payload = ORIG_LOGGING_CONTENT.getBytes(StandardCharsets.UTF_8);
OutputStream out = message.getContent(OutputStream.class);
out.write(payload);
out.close();
// Verify
LogEvent event = logEventSender.getLogEvent();
assertNotNull(event);
assertEquals(TRANSFORMED_LOGGING_CONTENT, event.getPayload());
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class TruncatedTest method truncatedOutboundInterceptorOutputStream.
@Test
public void truncatedOutboundInterceptorOutputStream() throws IOException {
Message message = new MessageImpl();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
message.setContent(OutputStream.class, outputStream);
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
LogEventSenderMock logEventSender = new LogEventSenderMock();
LoggingOutInterceptor interceptor = new LoggingOutInterceptor(logEventSender);
// set limit to 1 byte in order to get a truncated message!
interceptor.setLimit(1);
interceptor.handleMessage(message);
byte[] payload = "TestMessage".getBytes(StandardCharsets.UTF_8);
OutputStream out = message.getContent(OutputStream.class);
out.write(payload);
out.close();
LogEvent event = logEventSender.getLogEvent();
assertNotNull(event);
// only the first byte is read!
assertEquals("T", event.getPayload());
assertTrue(event.isTruncated());
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class TruncatedTest method truncatedOutboundInterceptorWriter.
@Test
public void truncatedOutboundInterceptorWriter() throws IOException {
Message message = new MessageImpl();
StringWriter stringWriter = new StringWriter();
message.setContent(Writer.class, stringWriter);
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
LogEventSenderMock logEventSender = new LogEventSenderMock();
LoggingOutInterceptor interceptor = new LoggingOutInterceptor(logEventSender);
// set limit to 1 byte in order to get a truncated message!
interceptor.setLimit(1);
interceptor.handleMessage(message);
Writer out = message.getContent(Writer.class);
out.write("TestMessage");
out.close();
LogEvent event = logEventSender.getLogEvent();
assertNotNull(event);
// only the first byte is read!
assertEquals("T", event.getPayload());
assertTrue(event.isTruncated());
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class TruncatedTest method truncatedInboundInterceptorReader.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void truncatedInboundInterceptorReader() throws IOException {
Message message = new MessageImpl();
StringReader stringReader = new StringReader("TestMessage");
message.setContent(Reader.class, stringReader);
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
LogEventSenderMock logEventSender = new LogEventSenderMock();
LoggingInInterceptor interceptor = new LoggingInInterceptor(logEventSender);
// set limit to 1 byte in order to get a truncated message!
interceptor.setLimit(1);
Collection<PhaseInterceptor<? extends Message>> interceptors = interceptor.getAdditionalInterceptors();
for (PhaseInterceptor intercept : interceptors) {
intercept.handleMessage(message);
}
interceptor.handleMessage(message);
LogEvent event = logEventSender.getLogEvent();
assertNotNull(event);
// only the first byte is read!
assertEquals("T", event.getPayload());
assertTrue(event.isTruncated());
}
Aggregations