Search in sources :

Example 21 with RegexMetadataFilter

use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.

the class GenericMessageTypeTranslatorCase method testMetadataConverter.

@Test
public void testMetadataConverter() throws Exception {
    MessageTypeTranslatorImp trans = createTranslator().withMetadataConverters(new StringMetadataConverter(new RegexMetadataFilter().withIncludePatterns(STRING_METADATA)), new IntegerMetadataConverter(new RegexMetadataFilter().withIncludePatterns(INTEGER_METADATA)), new BooleanMetadataConverter(new RegexMetadataFilter().withIncludePatterns(BOOLEAN_METADATA)));
    try {
        Session session = activeMqBroker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        start(trans, session);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        addMetadata(msg);
        Message jmsMsg = trans.translate(msg);
        assertJmsProperties(jmsMsg);
    } finally {
        stop(trans);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 22 with RegexMetadataFilter

use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.

the class BytesMessageTranslatorTest method testMoveMetadata_JmsMessageToAdaptrisMessage_WithFilter.

@Override
@Test
public void testMoveMetadata_JmsMessageToAdaptrisMessage_WithFilter() throws Exception {
    MessageTypeTranslatorImp trans = createTranslator();
    RegexMetadataFilter regexp = new RegexMetadataFilter();
    regexp.addExcludePattern("IntegerMetadataKey");
    trans.setMetadataFilter(regexp);
    try {
        Session session = activeMqBroker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        BytesMessage jmsMsg = createMessage(session);
        addProperties(jmsMsg);
        start(trans, session);
        // We aren't actually producing the message, so we have to
        // switch to read-only mode.
        jmsMsg.reset();
        AdaptrisMessage msg = trans.translate(jmsMsg);
        assertMetadata(msg, new MetadataElement(STRING_METADATA, STRING_VALUE));
        assertMetadata(msg, new MetadataElement(BOOLEAN_METADATA, BOOLEAN_VALUE));
        assertFalse(msg.containsKey(INTEGER_METADATA));
    } finally {
        stop(trans);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) BytesMessage(javax.jms.BytesMessage) MetadataElement(com.adaptris.core.MetadataElement) Session(javax.jms.Session) Test(org.junit.Test)

Example 23 with RegexMetadataFilter

use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.

the class CreateQueryStringFromMetadataTest method createService.

public CreateQueryStringFromMetadata createService() {
    CreateQueryStringFromMetadata svc = new CreateQueryStringFromMetadata().withMetadataFilter(new RegexMetadataFilter().withIncludePatterns("param1", "param2", "param3")).withQuerySeparator(null);
    svc.setResultKey("resultKey");
    return svc;
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter)

Example 24 with RegexMetadataFilter

use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.

the class MessageTypeTranslatorCase method testSetMetadataFilter.

@Test
public void testSetMetadataFilter() throws Exception {
    MessageTypeTranslatorImp translator = createTranslator();
    assertNull(translator.getMetadataFilter());
    assertNotNull(translator.metadataFilter());
    assertEquals(NoOpMetadataFilter.class, translator.metadataFilter().getClass());
    RegexMetadataFilter filter = new RegexMetadataFilter();
    translator.setMetadataFilter(filter);
    assertEquals(filter, translator.getMetadataFilter());
    assertEquals(filter, translator.metadataFilter());
    translator.setMetadataFilter(null);
    assertNull(translator.getMetadataFilter());
    assertNotNull(translator.metadataFilter());
    assertEquals(NoOpMetadataFilter.class, translator.metadataFilter().getClass());
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) Test(org.junit.Test)

Example 25 with RegexMetadataFilter

use of com.adaptris.core.metadata.RegexMetadataFilter in project interlok by adaptris.

the class StandardResponseProducerTest method testResponse_CompositeResponseHeaders.

@Test
public void testResponse_CompositeResponseHeaders() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setSendPayload(false);
    CompositeResponseHeaderProvider provider = new CompositeResponseHeaderProvider(new MetadataResponseHeaderProvider(new RegexMetadataFilter()), new ConfiguredResponseHeaderProvider(new KeyValuePair("Hello", "World")));
    responder.setResponseHeaderProvider(provider);
    AddMetadataService meta = new AddMetadataService();
    meta.addMetadataElement(getName(), getName());
    ServiceList sl = new ServiceList(new Service[] { meta, new StandaloneProducer(responder) });
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), sl));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        assertNotSame(TEXT, msg.getContent());
        assertTrue(msg.containsKey(getName()));
        assertTrue(msg.containsKey("Hello"));
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) 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) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) StandaloneProducer(com.adaptris.core.StandaloneProducer) 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