use of org.apache.camel.spi.HeaderFilterStrategy in project camel by apache.
the class SqsEndpoint method createExchange.
private Exchange createExchange(ExchangePattern pattern, com.amazonaws.services.sqs.model.Message msg) {
Exchange exchange = super.createExchange(pattern);
Message message = exchange.getIn();
message.setBody(msg.getBody());
message.setHeaders(new HashMap<String, Object>(msg.getAttributes()));
message.setHeader(SqsConstants.MESSAGE_ID, msg.getMessageId());
message.setHeader(SqsConstants.MD5_OF_BODY, msg.getMD5OfBody());
message.setHeader(SqsConstants.RECEIPT_HANDLE, msg.getReceiptHandle());
message.setHeader(SqsConstants.ATTRIBUTES, msg.getAttributes());
message.setHeader(SqsConstants.MESSAGE_ATTRIBUTES, msg.getMessageAttributes());
//Need to apply the SqsHeaderFilterStrategy this time
HeaderFilterStrategy headerFilterStrategy = getHeaderFilterStrategy();
//the Sqs class MessageAttributeValue will not leak to the client
for (Entry<String, MessageAttributeValue> entry : msg.getMessageAttributes().entrySet()) {
String header = entry.getKey();
Object value = translateValue(entry.getValue());
if (!headerFilterStrategy.applyFilterToExternalHeaders(header, value, exchange)) {
message.setHeader(header, value);
}
}
return exchange;
}
use of org.apache.camel.spi.HeaderFilterStrategy in project camel by apache.
the class DirectVmHeaderFilterStrategyTest method testPropertiesPropagatedOrNot.
public void testPropertiesPropagatedOrNot() throws Exception {
context.getRegistry(JndiRegistry.class).bind("headerFilterStrategy", new HeaderFilterStrategy() {
@Override
public boolean applyFilterToExternalHeaders(String headerName, Object headerValue, Exchange exchange) {
return headerName.equals("Header2");
}
@Override
public boolean applyFilterToCamelHeaders(String headerName, Object headerValue, Exchange exchange) {
return headerName.equals("Header1");
}
});
Exchange response = template.request("direct-vm:start.filter?headerFilterStrategy=#headerFilterStrategy", exchange -> {
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader("Header1", "Value1");
});
assertNull(response.getException());
assertNull(response.getOut().getHeader("Header2"));
response = template.request("direct-vm:start.nofilter", exchange -> {
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader("Header1", "Value1");
});
assertNull(response.getException());
assertEquals("Value2", response.getOut().getHeader("Header2", String.class));
}
use of org.apache.camel.spi.HeaderFilterStrategy in project camel by apache.
the class CxfRsHeaderFilterStrategyTest method testFilterCamelHeaders.
@Test
public void testFilterCamelHeaders() throws Exception {
HeaderFilterStrategy filter = new CxfRsHeaderFilterStrategy();
assertTrue("Get a wrong filtered result", filter.applyFilterToCamelHeaders(Exchange.CHARSET_NAME, "just a test", null));
assertTrue("Get a wrong filtered result", filter.applyFilterToCamelHeaders(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, "just a test", null));
assertTrue("Get a wrong filtered result", filter.applyFilterToCamelHeaders("org.apache.camel.such.Header", "just a test", null));
assertFalse("Get a wrong filtered result", filter.applyFilterToCamelHeaders("camel.result", "just a test", null));
}
Aggregations