Search in sources :

Example 1 with LogEvent

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());
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) DefaultLogEventMapper(org.apache.cxf.ext.logging.event.DefaultLogEventMapper) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 2 with LogEvent

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());
}
Also used : LogEventSender(org.apache.cxf.ext.logging.event.LogEventSender) PrettyLoggingFilter(org.apache.cxf.ext.logging.event.PrettyLoggingFilter) LogEvent(org.apache.cxf.ext.logging.event.LogEvent)

Example 3 with LogEvent

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());
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) StringWriter(java.io.StringWriter) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 4 with LogEvent

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());
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) StringReader(java.io.StringReader) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 5 with LogEvent

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());
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

LogEvent (org.apache.cxf.ext.logging.event.LogEvent)12 Test (org.junit.Test)10 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)7 Message (org.apache.cxf.message.Message)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 Exchange (org.apache.cxf.message.Exchange)6 DefaultLogEventMapper (org.apache.cxf.ext.logging.event.DefaultLogEventMapper)4 LoggingFeature (org.apache.cxf.ext.logging.LoggingFeature)3 Server (org.apache.cxf.endpoint.Server)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 AbstractJaxWsTest (org.apache.cxf.jaxws.AbstractJaxWsTest)2 PhaseInterceptor (org.apache.cxf.phase.PhaseInterceptor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 QName (javax.xml.namespace.QName)1