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);
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations