Search in sources :

Example 26 with RegexMetadataFilter

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

Example 27 with RegexMetadataFilter

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;
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) KeyValuePair(com.adaptris.util.KeyValuePair) StandaloneProducer(com.adaptris.core.StandaloneProducer)

Example 28 with RegexMetadataFilter

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

Example 29 with RegexMetadataFilter

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

Example 30 with RegexMetadataFilter

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

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