Search in sources :

Example 16 with RegexMetadataFilter

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);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) Test(org.junit.Test)

Example 17 with RegexMetadataFilter

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);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) HttpURLConnection(java.net.HttpURLConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) URL(java.net.URL) Test(org.junit.Test)

Example 18 with RegexMetadataFilter

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()));
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest)

Example 19 with RegexMetadataFilter

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);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) CoreException(com.adaptris.core.CoreException) RemoveAllMetadataFilter(com.adaptris.core.metadata.RemoveAllMetadataFilter) ProduceException(com.adaptris.core.ProduceException) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException) PasswordAuthentication(java.net.PasswordAuthentication)

Example 20 with RegexMetadataFilter

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"));
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Aggregations

RegexMetadataFilter (com.adaptris.core.metadata.RegexMetadataFilter)33 Test (org.junit.Test)25 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)19 Channel (com.adaptris.core.Channel)8 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)5 Session (javax.jms.Session)5 StandaloneProducer (com.adaptris.core.StandaloneProducer)4 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)4 Message (javax.jms.Message)4 MetadataElement (com.adaptris.core.MetadataElement)3 MessageTypeTranslatorImp (com.adaptris.core.jms.MessageTypeTranslatorImp)3 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 ServiceList (com.adaptris.core.ServiceList)2 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)2 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)2 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)2 KeyValuePair (com.adaptris.util.KeyValuePair)2 CoreException (com.adaptris.core.CoreException)1