use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class CloneMessageServiceListTest method testNormalOperationPreserveKey.
@Test
public void testNormalOperationPreserveKey() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
CloneMessageServiceList service = createServiceList();
RegexMetadataFilter rmf = new RegexMetadataFilter();
rmf.addIncludePattern(KEY1);
service.setOverrideMetadataFilter(rmf);
try {
LifecycleHelper.initAndStart(service);
service.doService(msg);
// md not present because Service applied to a clone
assertNotNull(msg.getMetadataValue(KEY1));
assertEquals(VAL1, msg.getMetadataValue(KEY1));
} finally {
LifecycleHelper.stopAndClose(service);
}
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class CompositeRequestHeadersTest method testAddHeaders.
@Test
public void testAddHeaders() throws Exception {
Channel c = null;
HttpURLConnection urlC = null;
try {
c = HttpHelper.createAndStartChannel();
URL url = new URL(HttpHelper.createProduceDestination(c));
urlC = (HttpURLConnection) url.openConnection();
CompositeRequestHeaders headers = new CompositeRequestHeaders();
MetadataRequestHeaders meta = new MetadataRequestHeaders();
meta.setFilter(new RegexMetadataFilter());
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("");
String name = testName.getMethodName();
headers.addProvider(meta);
msg.addMetadata(name, name);
urlC = headers.addHeaders(msg, urlC);
assertTrue(contains(urlC, name, name));
} finally {
HttpHelper.stopChannelAndRelease(c);
}
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class HttpRequestServiceTest method testService_MetadataRequestHeaders.
@Test
public void testService_MetadataRequestHeaders() throws Exception {
MockMessageProducer mock = new MockMessageProducer();
Channel c = HttpHelper.createAndStartChannel(mock);
HttpRequestService service = new HttpRequestService().withUrl(HttpHelper.createProduceDestination(c)).withRequestHeaderProvider(new MetadataRequestHeaders(new RegexMetadataFilter()));
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
msg.addMetadata(getName(), getName());
try {
c.requestStart();
execute(service, msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertTrue(m2.headersContainsKey(getName()));
assertEquals(getName(), m2.getMetadataValue(getName()));
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class HttpProducer method init.
@Override
public void init() throws CoreException {
try {
if (getUserName() != null && getPassword() != null) {
authString = buildBasicRfc2617(getUserName(), Password.decode(ExternalResolver.resolve(getPassword())));
passwordAuth = new PasswordAuthentication(userName, Password.decode(ExternalResolver.resolve(getPassword())).toCharArray());
}
if (sendMetadataAsHeaders()) {
if (getSendMetadataRegexp() == null && getMetadataFilter() instanceof RemoveAllMetadataFilter) {
log.warn("No Metadata Regular expression configured, ignoring sendMetadataAsHeaders=true");
setSendMetadataAsHeaders(Boolean.FALSE);
} else {
if (getSendMetadataRegexp() != null && getMetadataFilter() instanceof RemoveAllMetadataFilter) {
log.trace("Overriding metadata-filter with filter based on {}", getSendMetadataRegexp());
RegexMetadataFilter filter = new RegexMetadataFilter();
filter.addIncludePattern(getSendMetadataRegexp());
setMetadataFilter(filter);
}
}
}
} catch (Exception e) {
throw new CoreException(e);
}
}
use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.
the class MultipartMessageBuilderTest method testService_WithHeader.
@Test
public void testService_WithHeader() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
msg.addMetadata("X-Interlok-Mime", "yes");
MultipartMessageBuilder service = new MultipartMessageBuilder().withMimeParts(new InlineMimePartBuilder()).withMimeHeaderFilter(new RegexMetadataFilter().withIncludePatterns("X-Interlok.*"));
// default just uses the payload.
ExampleServiceCase.execute(service, msg);
String payload = msg.getContent();
// The unique-id forms the content-id.
assertTrue(payload.contains(msg.getUniqueId()));
assertTrue(payload.contains("X-Interlok-Mime"));
}
Aggregations