MapMetadataService extends MetadataServiceImpl { @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); } MapMetadataService(); @Override void doService(AdaptrisMessage msg); KeyValuePairList getMetadataKeyMap(); void setMetadataKeyMap(KeyValuePairList m); String getMetadataKey(); void setMetadataKey(String s);  }
@Test public void testRegexGroupReplacement() throws Exception { MapMetadataService service = createService(); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance() .newMessage("zzzzzzzz"); msg.addMetadata(METADATA_KEY, REGEXP_VALUE_TO_MATCH); service.doService(msg); assertTrue(msg.getMetadataValue(METADATA_KEY).equals(REGEX_NEW_METADATA_VALUE)); }