use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class ReformatMetadata method doService.
/**
* <p>
* Adds the configured metadata to the message.
* </p>
*
* @param msg the message to process
*/
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
if (isBlank(getMetadataKeyRegexp())) {
return;
}
try {
Set<MetadataElement> metadata = msg.getMetadata();
Set<MetadataElement> modifiedMetadata = new HashSet<MetadataElement>();
for (MetadataElement e : metadata) {
if (e.getKey().matches(metadataKeyRegexp)) {
modifiedMetadata.add(new MetadataElement(e.getKey(), reformat(e.getValue(), msg)));
}
}
logMetadata("Modified metadata : {}", modifiedMetadata);
msg.setMetadata(modifiedMetadata);
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class RegexpMetadataQuery method doQuery.
/**
* <p>
* Performs the query against the payload of the supplied String and
* constructs a MetdataElement with the configured Key and the result as the
* Value.
* </p>
* @param message the String to run the Query on
* @return a MetadataElement with the configured Key and the result of the
* Query as it's Value <b>NOTE: the Value of the MetadataElement will be null
* if nulls have been allowed</b>
* @throws CoreException wrapping any underlying Exception
*/
public synchronized MetadataElement doQuery(String message) throws Exception {
Args.notBlank(getMetadataKey(), "metadata-key");
Args.notBlank(getQueryExpression(), "query-expression");
if (pattern == null) {
pattern = Pattern.compile(getQueryExpression());
}
Matcher matcher = pattern.matcher(message);
MetadataElement elem = new MetadataElement();
elem.setKey(getMetadataKey());
if (matcher.find()) {
elem.setValue(matcher.group(1));
} else {
if (!allowNullResults()) {
throw new CoreException("Failed to match pattern [" + metadataKey + "] to input string");
}
}
return elem;
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class RegexpMetadataService method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
String message = msg.getContent();
List<MetadataElement> added = new ArrayList<>();
try {
for (RegexpMetadataQuery q : getRegexpMetadataQueries()) {
MetadataElement elem = q.doQuery(message);
if (BooleanUtils.or(new boolean[] { !isEmpty(elem.getValue()), addNullValues() })) {
msg.addMetadata(elem);
added.add(elem);
}
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
logMetadata("Added metadata : {}", added);
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class UrlEncodedMetadataValues method buildEncodedString.
protected String buildEncodedString(AdaptrisMessage msg) throws Exception {
MetadataCollection filtered = metadataFilter().filter(msg);
StringBuilder result = new StringBuilder();
for (MetadataElement e : filtered) {
if (result.length() > 1) {
// This is not the first parameter so add a separator
result.append(separator());
}
result.append(e.getKey()).append("=").append(URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8.name()));
}
return result.toString();
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class MapMetadataService method doService.
/**
* @see com.adaptris.core.Service#doService(AdaptrisMessage)
*/
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
if (metadataKey == null || !msg.headersContainsKey(metadataKey)) {
log.debug("Message does not contain metadatakey [" + metadataKey + "]");
return;
}
String metadataValue = msg.getMetadataValue(metadataKey);
metadataValue = ObjectUtils.defaultIfNull(metadataValue, "");
List<MetadataElement> mapped = new ArrayList<>();
for (KeyValuePair k : getMetadataKeyMap()) {
if (metadataValue.matches(k.getKey())) {
String newMetadataValue = doSubstitution(metadataValue, k, msg);
MetadataElement e = new MetadataElement(metadataKey, newMetadataValue);
msg.addMetadata(e);
mapped.add(e);
break;
}
}
logMetadata("Modified Metadata : {}", mapped);
}
Aggregations