use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class StandardResponseProducerTest method testResponse_MetadataResponseHeaders.
@Test
public void testResponse_MetadataResponseHeaders() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
RegexMetadataFilter filter = new RegexMetadataFilter();
filter.addIncludePattern(METADATA_REGEXP);
responder.setResponseHeaderProvider(new MetadataResponseHeaderProvider(filter));
AddMetadataService addMetadata = new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(CUSTOM_HEADER1, CUSTOM_VALUE1), new MetadataElement(CUSTOM_HEADER2, CUSTOM_VALUE2) }));
HttpConnection httpConnection = createConnection();
Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { addMetadata, new StandaloneProducer(responder) })));
StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
AdaptrisMessage msg = createMessage();
try {
c.requestStart();
start(requestor);
requestor.doService(msg);
assertEquals(TEXT, msg.getContent());
assertTrue(msg.containsKey(CUSTOM_HEADER1));
assertTrue(msg.containsKey(CUSTOM_HEADER2));
assertEquals(CUSTOM_VALUE1, msg.getMetadataValue(CUSTOM_HEADER1));
assertEquals(CUSTOM_VALUE2, msg.getMetadataValue(CUSTOM_HEADER2));
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class StandardHttpProducerTest method retrieveObjectForSampleConfig.
@SuppressWarnings("unchecked")
@Override
protected StandaloneProducer retrieveObjectForSampleConfig() {
StandardHttpProducer producer = new StandardHttpProducer().withURL("http://myhost.com/url/to/post/to");
CompositeRequestHeaders headers = new CompositeRequestHeaders(new MetadataRequestHeaders(new RegexMetadataFilter().withIncludePatterns("X-HTTP.*").withExcludePatterns("X-NotHttp.*")), new ConfiguredRequestHeaders().withHeaders(new KeyValuePair("SOAPAction", "urn:hello")));
producer.setRequestHeaderProvider(headers);
producer.setResponseHeaderHandler(new CompositeResponseHeaderHandler(new ResponseHeadersAsMetadata("resp_hdr_"), new ResponseHeadersAsObjectMetadata("resp_hdr_")));
producer.setAuthenticator(getAuthenticator("username", "password"));
StandaloneProducer result = new StandaloneProducer(producer);
return result;
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class HttpConsumerTest method testBug1549.
@Test
public void testBug1549() throws Exception {
HttpConnection connection = createConnection(null);
MockMessageProducer mockProducer = new MockMessageProducer();
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
consumer.setHeaderHandler(new MetadataHeaderHandler());
Channel adapter = JettyHelper.createChannel(connection, consumer, mockProducer);
try {
adapter.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
msg.addMetadata(X_HTTP_KEY1, METADATA_VALUE1);
msg.addMetadata(X_HTTP_KEY2, METADATA_VALUE2);
msg.addMetadata(IGNORED_METADATA, METADATA_VALUE1);
httpProducer.setSendMetadataAsHeaders(true);
RegexMetadataFilter filter = new RegexMetadataFilter();
filter.addIncludePattern("X-HTTP.*");
httpProducer.setMetadataFilter(filter);
httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg);
assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
doAssertions(mockProducer);
AdaptrisMessage consumedMsg = mockProducer.getMessages().get(0);
assertEquals("Consumed Payload", XML_PAYLOAD, consumedMsg.getContent());
assertTrue(consumedMsg.containsKey(X_HTTP_KEY1));
assertEquals(METADATA_VALUE1, consumedMsg.getMetadataValue(X_HTTP_KEY1));
assertTrue(consumedMsg.containsKey(X_HTTP_KEY2));
assertEquals(METADATA_VALUE2, consumedMsg.getMetadataValue(X_HTTP_KEY2));
assertFalse(consumedMsg.containsKey(IGNORED_METADATA));
} finally {
stop(httpProducer);
adapter.requestClose();
PortManager.release(connection.getPort());
}
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class MetadataFilterServiceTest method testServiceInclude.
@Test
public void testServiceInclude() throws Exception {
AdaptrisMessage msg = createMessage();
MetadataFilterService service = new MetadataFilterService();
RegexMetadataFilter filter = new RegexMetadataFilter();
filter.addIncludePattern(REG_EXP);
service.setFilter(filter);
execute(service, msg);
assertFalse(msg.containsKey(JMS_MESSAGE_ID));
assertEquals(DEF_VALUE, msg.getMetadataValue(JMS_KEY_1));
assertEquals(DEF_VALUE, msg.getMetadataValue(JMS_KEY_2));
assertEquals(DEF_VALUE, msg.getMetadataValue(JMS_KEY_3));
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class MetadataFilterServiceTest method retrieveObjectForSampleConfig.
@Override
protected Object retrieveObjectForSampleConfig() {
MetadataFilterService service = new MetadataFilterService();
RegexMetadataFilter filter = new RegexMetadataFilter();
filter.addExcludePattern(REG_EXP);
filter.addIncludePattern(MATCH_ANY);
filter.addExcludePattern("ANOTHER_REGULAR_EXPRESSION");
service.setFilter(filter);
return service;
}
Aggregations