Search in sources :

Example 61 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class MetadataLoggerTest method testDefaultMethods.

@Test
public void testDefaultMethods() {
    AdaptrisMessage msg = MessageLoggerTest.createMessage();
    MetadataElement e1 = msg.getMetadata("LENGTH_39");
    MetadataElement e2 = msg.getMetadata("LENGTH_43");
    String s = new MetadataKeysOnly().toString(e1, e2);
    System.err.println("testDefaultMethods:: " + s);
    assertNotNull(s);
    assertFalse(s.contains("The quick brown fox jumps over the lazy dog"));
    assertFalse(s.contains("Pack my box with five dozen liquor jugs"));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 62 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class SimpleHttpProducer method readResponse.

private void readResponse(HttpSession httpReply, AdaptrisMessage reply) throws IOException, CoreException {
    int responseCode = httpReply.getResponseLine().getResponseCode();
    if (!ignoreServerResponseCode()) {
        if (responseCode < 200 || responseCode > 299) {
            throw new ProduceException("Failed to send payload, got " + responseCode);
        }
    }
    if (getEncoder() != null) {
        copy(getEncoder().readMessage(httpReply), reply);
    } else {
        OutputStream out = reply.getOutputStream();
        InputStream in = httpReply.getResponseMessage().getInputStream();
        StreamUtil.copyStream(in, out);
        reply.addMetadata(new MetadataElement(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE, String.valueOf(responseCode)));
        out.close();
        in.close();
    }
    return;
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) MetadataElement(com.adaptris.core.MetadataElement) ProduceException(com.adaptris.core.ProduceException)

Example 63 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class MessageTypeTranslatorCase method assertMetadata.

public static void assertMetadata(AdaptrisMessage msg) {
    assertMetadata(msg, new MetadataElement(STRING_METADATA, STRING_VALUE));
    assertMetadata(msg, new MetadataElement(BOOLEAN_METADATA, BOOLEAN_VALUE));
    assertMetadata(msg, new MetadataElement(INTEGER_METADATA, INTEGER_VALUE));
}
Also used : MetadataElement(com.adaptris.core.MetadataElement)

Example 64 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class MessageTypeTranslatorCase method testMoveMetadata_JmsMessageToAdaptrisMessage_WithFilter.

@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);
        Message jmsMsg = createMessage(session);
        addProperties(jmsMsg);
        start(trans, session);
        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) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) Session(javax.jms.Session) Test(org.junit.Test)

Example 65 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class MetadataRequestHeaders method addHeaders.

@Override
public HttpURLConnection addHeaders(AdaptrisMessage msg, HttpURLConnection target) {
    MetadataCollection metadataSubset = getFilter().filter(msg);
    for (MetadataElement me : metadataSubset) {
        String value = unfold(me.getValue());
        log.trace("Adding Request Property [{}: {}]", me.getKey(), value);
        target.addRequestProperty(me.getKey(), value);
    }
    return target;
}
Also used : MetadataCollection(com.adaptris.core.MetadataCollection) MetadataElement(com.adaptris.core.MetadataElement)

Aggregations

MetadataElement (com.adaptris.core.MetadataElement)151 Test (org.junit.Test)101 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)94 XPath (com.adaptris.util.text.xml.XPath)23 Document (org.w3c.dom.Document)19 MetadataCollection (com.adaptris.core.MetadataCollection)18 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)18 ServiceException (com.adaptris.core.ServiceException)17 ServiceList (com.adaptris.core.ServiceList)14 Cache (com.adaptris.core.cache.Cache)14 MetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)12 ArrayList (java.util.ArrayList)11 CoreException (com.adaptris.core.CoreException)10 Service (com.adaptris.core.Service)10 HashSet (java.util.HashSet)9 ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)8 StandaloneProducer (com.adaptris.core.StandaloneProducer)7 StaticCacheValueTranslator (com.adaptris.core.services.cache.translators.StaticCacheValueTranslator)7 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)6 Session (javax.jms.Session)6