Search in sources :

Example 11 with LogEvent

use of org.apache.cxf.ext.logging.event.LogEvent in project cxf by apache.

the class TruncatedTest method truncatedInboundInterceptorInputStream.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void truncatedInboundInterceptorInputStream() throws IOException {
    Message message = new MessageImpl();
    ByteArrayInputStream inputStream = new ByteArrayInputStream("TestMessage".getBytes(StandardCharsets.UTF_8));
    message.setContent(InputStream.class, inputStream);
    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) ByteArrayInputStream(java.io.ByteArrayInputStream) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 12 with LogEvent

use of org.apache.cxf.ext.logging.event.LogEvent in project cxf by apache.

the class SOAPLoggingTest method testEvents.

@Test
public void testEvents() throws MalformedURLException {
    TestService serviceImpl = new TestServiceImplementation();
    LoggingFeature loggingFeature = new LoggingFeature();
    TestEventSender sender = new TestEventSender();
    loggingFeature.setSender(sender);
    Endpoint ep = Endpoint.publish(SERVICE_URI, serviceImpl, loggingFeature);
    TestService client = createTestClient(loggingFeature);
    client.echo("test");
    ep.stop();
    List<LogEvent> events = sender.getEvents();
    Assert.assertEquals(4, events.size());
    checkRequestOut(events.get(0));
    checkRequestIn(events.get(1));
    checkResponseOut(events.get(2));
    checkResponseIn(events.get(3));
}
Also used : Endpoint(javax.xml.ws.Endpoint) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

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