use of org.apache.cxf.ext.logging.event.LogEvent in project cxf by apache.
the class DefaultLogEventMapperTest method testRest.
@Test
public void testRest() {
DefaultLogEventMapper mapper = new DefaultLogEventMapper();
Message message = new MessageImpl();
message.put(Message.HTTP_REQUEST_METHOD, "GET");
message.put(Message.REQUEST_URI, "test");
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
LogEvent event = mapper.map(message);
Assert.assertEquals("GET[test]", event.getOperationName());
}
use of org.apache.cxf.ext.logging.event.LogEvent in project cxf by apache.
the class TestPrettyLoggingFilter method filter.
private void filter(String payload, String expected, boolean truncated) {
LogEvent logEvent = new LogEvent();
logEvent.setPayload(payload);
logEvent.setContentType("text/xml");
logEvent.setTruncated(truncated);
LogEventSender dummy = new LogEventSender() {
public void send(LogEvent event) {
}
};
PrettyLoggingFilter prettyFilter = new PrettyLoggingFilter(dummy);
prettyFilter.setPrettyLogging(true);
prettyFilter.send(logEvent);
assertEquals(expected, logEvent.getPayload());
}
use of org.apache.cxf.ext.logging.event.LogEvent 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.ext.logging.event.LogEvent 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());
}
use of org.apache.cxf.ext.logging.event.LogEvent 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());
}
Aggregations