Search in sources :

Example 56 with KeyValuePair

use of com.adaptris.util.KeyValuePair in project interlok by adaptris.

the class IntegerValueMatcher method getNextServiceId.

public String getNextServiceId(String serviceKey, KeyValuePairBag mappings) {
    String result = null;
    Integer lhs = null;
    Integer rhs = null;
    try {
        lhs = Integer.parseInt(serviceKey);
    } catch (NumberFormatException e) {
        logR.trace("[{}] not parseable as an integer", serviceKey);
        return result;
    }
    Pattern matchPattern = Pattern.compile(INTEGER_OPERATOR_PATTERN);
    Set<KeyValuePair> pairs = sort(mappings);
    for (KeyValuePair kvp : pairs) {
        Matcher m = matchPattern.matcher(kvp.getKey());
        if (m.matches()) {
            String operator = m.group(1);
            rhs = Integer.parseInt(m.group(2));
            Operator o = OPERATORS.get(operator);
            if (o == null) {
                logR.trace("[{}] not handled, ignoring", kvp.getKey());
                continue;
            }
            logR.trace("Comparing [{}] against [{}] using {}", lhs, rhs, o.toString());
            if (o.matches(lhs, rhs)) {
                result = kvp.getValue();
                break;
            }
        } else {
            logR.trace("Ignoring {}, no match for regular expression [{}]", kvp.getKey(), INTEGER_OPERATOR_PATTERN);
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) KeyValuePair(com.adaptris.util.KeyValuePair) Matcher(java.util.regex.Matcher)

Example 57 with KeyValuePair

use of com.adaptris.util.KeyValuePair 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);
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) ArrayList(java.util.ArrayList) MetadataElement(com.adaptris.core.MetadataElement)

Example 58 with KeyValuePair

use of com.adaptris.util.KeyValuePair in project interlok by adaptris.

the class DocumentBuilderFactoryBuilder method withFeatures.

public DocumentBuilderFactoryBuilder withFeatures(Map<String, Boolean> f) {
    Map<String, Boolean> featureList = Args.notNull(f, "features");
    KeyValuePairSet newFeatures = new KeyValuePairSet();
    for (Map.Entry<String, Boolean> entry : featureList.entrySet()) {
        newFeatures.add(new KeyValuePair(entry.getKey(), String.valueOf(entry.getValue())));
    }
    return withFeatures(newFeatures);
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) KeyValuePairSet(com.adaptris.util.KeyValuePairSet) Map(java.util.Map)

Example 59 with KeyValuePair

use of com.adaptris.util.KeyValuePair in project interlok by adaptris.

the class AdapterStateSummaryTest method testAddChannelStateKeyValuePair.

@Test
public void testAddChannelStateKeyValuePair() {
    AdapterStateSummary s1 = new AdapterStateSummary();
    s1.addChannelState(new KeyValuePair(DEFAULT_KEY, ClosedState.getInstance().getClass().getName()));
    assertEquals(1, s1.getChannelStates().size());
    assertTrue(s1.getChannelStates().contains(new KeyValuePair(DEFAULT_KEY, "")));
    assertEquals(DEFAULT_KEY, s1.getChannelStates().getKeyValuePair(DEFAULT_KEY).getKey());
    assertEquals(ClosedState.getInstance().getClass().getName(), s1.getChannelStates().getKeyValuePair(DEFAULT_KEY).getValue());
    s1.addChannelState(new KeyValuePair("", "ABC"));
    assertEquals(1, s1.getChannelStates().size());
    try {
        s1.addChannelState(new KeyValuePair("ABC", ""));
        fail("Null Value in KeyValuePair");
    } catch (IllegalArgumentException expected) {
    }
    try {
        s1.addChannelState(null);
        fail("Null KeyValuePair");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) Test(org.junit.Test)

Example 60 with KeyValuePair

use of com.adaptris.util.KeyValuePair in project interlok by adaptris.

the class ConfiguredRequestHeadersTest method testSetHandlers.

@Test
public void testSetHandlers() throws Exception {
    ConfiguredRequestHeaders headers = new ConfiguredRequestHeaders();
    assertNotNull(headers.getHeaders());
    assertEquals(0, headers.getHeaders().size());
    String name = testName.getMethodName();
    headers.getHeaders().add(new KeyValuePair(name, name));
    assertEquals(1, headers.getHeaders().size());
    headers.setHeaders(new KeyValuePairSet());
    assertEquals(0, headers.getHeaders().size());
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) KeyValuePairSet(com.adaptris.util.KeyValuePairSet) Test(org.junit.Test)

Aggregations

KeyValuePair (com.adaptris.util.KeyValuePair)143 Test (org.junit.Test)79 KeyValuePairSet (com.adaptris.util.KeyValuePairSet)55 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)26 KeyValuePairList (com.adaptris.util.KeyValuePairList)12 StandardJndiImplementation (com.adaptris.core.jms.jndi.StandardJndiImplementation)11 StandaloneProducer (com.adaptris.core.StandaloneProducer)10 Channel (com.adaptris.core.Channel)9 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)9 TimeInterval (com.adaptris.util.TimeInterval)9 ServiceException (com.adaptris.core.ServiceException)7 JmsConnection (com.adaptris.core.jms.JmsConnection)6 ArrayList (java.util.ArrayList)6 CoreException (com.adaptris.core.CoreException)5 StandardWorkflow (com.adaptris.core.StandardWorkflow)5 PasProducer (com.adaptris.core.jms.PasProducer)5 MetadataCollection (com.adaptris.core.MetadataCollection)4 MetadataElement (com.adaptris.core.MetadataElement)4 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)4 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)3