Search in sources :

Example 56 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class DefaultLogEventMapperTest method shouldMaskHeaders.

@Test
public void shouldMaskHeaders() {
    final DefaultLogEventMapper mapper = new DefaultLogEventMapper();
    final Message message = new MessageImpl();
    message.put(Message.ENDPOINT_ADDRESS, "http://localhost:9001/");
    message.put(Message.REQUEST_URI, "/api");
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    final Map<String, Object> headers = new HashMap<>();
    headers.put(TEST_HEADER_NAME, Arrays.asList(TEST_HEADER_VALUE));
    final Set<String> sensitiveHeaders = new HashSet<>();
    sensitiveHeaders.add(TEST_HEADER_NAME);
    message.put(Message.PROTOCOL_HEADERS, headers);
    LogEvent event = mapper.map(message, sensitiveHeaders);
    assertEquals(MASKED_HEADER_VALUE, event.getHeaders().get(TEST_HEADER_NAME));
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class MaskSensitiveHelperTest method prepareInMessage.

private Message prepareInMessage() {
    Message message = new MessageImpl();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(loggingContent.getBytes(StandardCharsets.UTF_8));
    message.put(Message.CONTENT_TYPE, contentType);
    message.setContent(InputStream.class, inputStream);
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    return message;
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 58 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class MaskSensitiveHelperTest method prepareOutMessage.

private Message prepareOutMessage() {
    Message message = new MessageImpl();
    message.put(Message.CONTENT_TYPE, contentType);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    message.setContent(OutputStream.class, outputStream);
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    return message;
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 59 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class TransformTest method transformInboundInterceptorReader.

@Test
public void transformInboundInterceptorReader() {
    // Arrange
    Message message = new MessageImpl();
    StringReader stringReader = new StringReader(ORIG_LOGGING_CONTENT);
    message.setContent(Reader.class, stringReader);
    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) 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 60 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class TransformTest method transformOutboundInterceptorWriter.

@Test
public void transformOutboundInterceptorWriter() throws IOException {
    // Arrange
    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 TransformLoggingOutInterceptor(logEventSender);
    // Act
    interceptor.handleMessage(message);
    Writer out = message.getContent(Writer.class);
    out.write(ORIG_LOGGING_CONTENT);
    out.close();
    // Assert
    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) 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)

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