Search in sources :

Example 6 with LogEvent

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

the class SOAPLoggingTest method testSoap.

@Test
public void testSoap() {
    DefaultLogEventMapper mapper = new DefaultLogEventMapper();
    Message message = new MessageImpl();
    ExchangeImpl exchange = new ExchangeImpl();
    ServiceInfo service = new ServiceInfo();
    BindingInfo info = new BindingInfo(service, "bindingId");
    SoapBinding value = new SoapBinding(info);
    exchange.put(Binding.class, value);
    OperationInfo opInfo = new OperationInfo();
    opInfo.setName(new QName("http://my", "Operation"));
    BindingOperationInfo boi = new BindingOperationInfo(info, opInfo);
    exchange.put(BindingOperationInfo.class, boi);
    message.setExchange(exchange);
    LogEvent event = mapper.map(message);
    Assert.assertEquals("{http://my}Operation", event.getOperationName());
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) QName(javax.xml.namespace.QName) BindingInfo(org.apache.cxf.service.model.BindingInfo) DefaultLogEventMapper(org.apache.cxf.ext.logging.event.DefaultLogEventMapper) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 7 with LogEvent

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

the class RESTLoggingTest method testBinary.

@Test
public void testBinary() throws IOException, InterruptedException {
    LoggingFeature loggingFeature = new LoggingFeature();
    TestEventSender sender = new TestEventSender();
    loggingFeature.setSender(sender);
    Server server = createService(SERVICE_URI_BINARY, new TestServiceRestBinary(), loggingFeature);
    server.start();
    WebClient client = createClient(SERVICE_URI_BINARY, loggingFeature);
    client.get(InputStream.class).close();
    loggingFeature.setLogBinary(true);
    client.get(InputStream.class).close();
    client.close();
    List<LogEvent> events = sender.getEvents();
    await().until(() -> events.size(), is(8));
    server.stop();
    server.destroy();
    // First call with binary logging false
    assertContentLogged(events.get(0));
    assertContentLogged(events.get(1));
    assertContentNotLogged(events.get(2));
    assertContentNotLogged(events.get(3));
    // Second call with binary logging true
    assertContentLogged(events.get(4));
    assertContentLogged(events.get(5));
    assertContentLogged(events.get(6));
    assertContentLogged(events.get(7));
}
Also used : Server(org.apache.cxf.endpoint.Server) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) InputStream(java.io.InputStream) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 8 with LogEvent

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

the class RESTLoggingTest method testEvents.

@Test
public void testEvents() throws MalformedURLException {
    LoggingFeature loggingFeature = new LoggingFeature();
    loggingFeature.setLogBinary(true);
    TestEventSender sender = new TestEventSender();
    loggingFeature.setSender(sender);
    Server server = createService(SERVICE_URI, new TestServiceRest(), loggingFeature);
    server.start();
    WebClient client = createClient(SERVICE_URI, loggingFeature);
    String result = client.get(String.class);
    Assert.assertEquals("test1", result);
    server.destroy();
    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 : Server(org.apache.cxf.endpoint.Server) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 9 with LogEvent

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

the class LoggingInInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    if (isLoggingDisabledNow(message)) {
        return;
    }
    createExchangeId(message);
    final LogEvent event = new DefaultLogEventMapper().map(message);
    if (shouldLogContent(event)) {
        addContent(message, event);
    } else {
        event.setPayload(AbstractLoggingInterceptor.CONTENT_SUPPRESSED);
    }
    sender.send(event);
}
Also used : LogEvent(org.apache.cxf.ext.logging.event.LogEvent) DefaultLogEventMapper(org.apache.cxf.ext.logging.event.DefaultLogEventMapper)

Example 10 with LogEvent

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

the class DefaultLogEventMapperTest method testNullValues.

/**
 * Test for NPE described in CXF-6436
 */
@Test
public void testNullValues() {
    DefaultLogEventMapper mapper = new DefaultLogEventMapper();
    Message message = new MessageImpl();
    message.put(Message.HTTP_REQUEST_METHOD, null);
    message.put(Message.REQUEST_URI, null);
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    LogEvent event = mapper.map(message);
    Assert.assertEquals("", 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)

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