Search in sources :

Example 61 with ExchangeImpl

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());
}
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 62 with ExchangeImpl

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());
}
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)

Example 63 with ExchangeImpl

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());
}
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)

Example 64 with ExchangeImpl

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());
}
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 65 with ExchangeImpl

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());
}
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)

Aggregations

ExchangeImpl (org.apache.cxf.message.ExchangeImpl)227 MessageImpl (org.apache.cxf.message.MessageImpl)189 Message (org.apache.cxf.message.Message)166 Exchange (org.apache.cxf.message.Exchange)159 Test (org.junit.Test)107 Endpoint (org.apache.cxf.endpoint.Endpoint)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 ByteArrayInputStream (java.io.ByteArrayInputStream)28 QName (javax.xml.namespace.QName)23 Bus (org.apache.cxf.Bus)23 HashMap (java.util.HashMap)22 List (java.util.List)22 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 SOAPMessage (javax.xml.soap.SOAPMessage)16 LogEvent (org.apache.cxf.ext.logging.event.LogEvent)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)14 Conduit (org.apache.cxf.transport.Conduit)14