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