Search in sources :

Example 66 with MetadataElement

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

the class MapMessageTranslator method translate.

/**
 * <p>
 * Translates an {@link com.adaptris.core.AdaptrisMessage} into a MapMessage.
 * </p>
 *
 * @param msg the <code>AdaptrisMessage</code> to translate
 * @return a new <code>MapMessage</code>
 * @throws JMSException
 */
@Override
public Message translate(AdaptrisMessage msg) throws JMSException {
    MapMessage jmsMsg = session.createMapMessage();
    jmsMsg.setString(getKeyForPayload(), msg.getContent());
    if (treatMetadataAsPartOfMessage()) {
        Set<MetadataElement> metadata = msg.getMetadata();
        for (Iterator<MetadataElement> itr = metadata.iterator(); itr.hasNext(); ) {
            MetadataElement element = itr.next();
            if (!isReserved(element.getKey())) {
                jmsMsg.setString(element.getKey(), element.getValue());
            }
        }
    }
    return helper.moveMetadata(msg, jmsMsg);
}
Also used : MapMessage(javax.jms.MapMessage) MetadataElement(com.adaptris.core.MetadataElement)

Example 67 with MetadataElement

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

the class AllRowsMetadataTranslator method translateResult.

@Override
public long translateResult(JdbcResult source, AdaptrisMessage target) throws SQLException, ServiceException {
    List<MetadataElement> added = new ArrayList<MetadataElement>();
    long resultSetCount = 0;
    for (JdbcResultSet resultSet : source.getResultSets()) {
        int counter = 0;
        String resultSetPrefix = source.countResultSets() > 1 ? Long.toString(resultSetCount) + getResultSetCounterPrefix() : "";
        for (JdbcResultRow row : resultSet.getRows()) {
            for (int i = 0; i < row.getFieldCount(); i++) {
                MetadataElement md = new MetadataElement(resultSetPrefix + getMetadataKeyPrefix() + getSeparator() + getColumnNameStyle().format(row.getFieldName(i)) + getSeparator() + counter, toString(row, i));
                if (log.isTraceEnabled()) {
                    added.add(md);
                }
                target.addMetadata(md);
            }
            counter++;
        }
        // In the event that we have multiple selects (unlikely from a JdbcDataQuery) then
        // row-total will have the total for each result set
        // resultSetCount will have the total for all resultSets.
        // if (!isEmpty(getRowTotalMetadataKey())) {
        // target.addMetadata(resultSetPrefix + getRowTotalMetadataKey(), String.valueOf(counter));
        // }
        resultSetCount += counter;
    }
    if (log.isTraceEnabled()) {
        log.debug("Added metadata : " + added);
    }
    return resultSetCount;
}
Also used : JdbcResultRow(com.adaptris.jdbc.JdbcResultRow) ArrayList(java.util.ArrayList) MetadataElement(com.adaptris.core.MetadataElement) JdbcResultSet(com.adaptris.jdbc.JdbcResultSet)

Example 68 with MetadataElement

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

the class StringMetadataParameter method createParameters.

@Override
public Map createParameters(AdaptrisMessage msg, Map existingParams) {
    MetadataCollection metadataToInclude = metadataFilter.filter(msg);
    if (metadataToInclude.size() == 0) {
        return existingParams;
    }
    Map params = existingParams == null ? new HashMap() : new HashMap(existingParams);
    for (MetadataElement e : metadataToInclude) {
        params.put(e.getKey(), e.getValue());
    }
    log.trace("Stylesheet parameters: {}", params);
    return params;
}
Also used : HashMap(java.util.HashMap) MetadataCollection(com.adaptris.core.MetadataCollection) MetadataElement(com.adaptris.core.MetadataElement) HashMap(java.util.HashMap) Map(java.util.Map)

Example 69 with MetadataElement

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

the class DecodingService method transcodeMessage.

@Override
public void transcodeMessage(AdaptrisMessage msg) throws ServiceException {
    try (InputStream msgIn = msg.getInputStream();
        OutputStream msgOut = msg.getOutputStream()) {
        AdaptrisMessage decodedMsg = getEncoder().readMessage(msgIn);
        for (MetadataElement me : decodedMsg.getMetadata()) {
            if (!isOverrideMetadata() && msg.headersContainsKey(me.getKey())) {
                continue;
            }
            msg.addMetadata(me);
        }
        StreamUtil.copyAndClose(decodedMsg.getInputStream(), msgOut);
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) MetadataElement(com.adaptris.core.MetadataElement) ServiceException(com.adaptris.core.ServiceException)

Example 70 with MetadataElement

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

the class MetadataResponseHeaderProvider method addHeaders.

@Override
public HttpServletResponse addHeaders(AdaptrisMessage msg, HttpServletResponse target) {
    MetadataCollection subset = getFilter().filter(msg);
    for (MetadataElement me : subset) {
        log.trace("Adding Response Header [{}: {}]", me.getKey(), me.getValue());
        target.addHeader(me.getKey(), me.getValue());
    }
    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