Search in sources :

Example 1 with HexStringByteTranslator

use of com.adaptris.util.text.HexStringByteTranslator in project interlok by adaptris.

the class PayloadHashingServiceTest method testService_WithByteTranslator.

@Test
public void testService_WithByteTranslator() throws Exception {
    PayloadHashingService service = new PayloadHashingService(SHA256, METADATA_KEY);
    service.setByteTranslator(new HexStringByteTranslator());
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD);
    execute(service, msg);
    assertTrue(msg.containsKey(METADATA_KEY));
    assertEquals(PAYLOAD, msg.getContent());
    assertNotNull(msg.getMetadataValue(METADATA_KEY));
    assertEquals(createHash(new HexStringByteTranslator()), msg.getMetadataValue(METADATA_KEY));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator) Test(org.junit.Test)

Example 2 with HexStringByteTranslator

use of com.adaptris.util.text.HexStringByteTranslator in project interlok by adaptris.

the class MetadataHashingTest method testService_Encoding.

@Test
public void testService_Encoding() throws Exception {
    MetadataHashingService service = new MetadataHashingService(METADATA_KEY, "MD5", new HexStringByteTranslator());
    AdaptrisMessage msg = createMessage("UTF-8");
    execute(service, msg);
    assertEquals(METADATA_HASH_MD5, msg.getMetadataValue(METADATA_KEY));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator) Test(org.junit.Test)

Example 3 with HexStringByteTranslator

use of com.adaptris.util.text.HexStringByteTranslator in project interlok by adaptris.

the class MetadataHashingTest method testSetByteTranslator.

@Test
public void testSetByteTranslator() throws Exception {
    MetadataHashingService service = new MetadataHashingService();
    assertEquals(Base64ByteTranslator.class, service.getByteTranslator().getClass());
    service.setByteTranslator(new HexStringByteTranslator());
    assertEquals(HexStringByteTranslator.class, service.getByteTranslator().getClass());
    LifecycleHelper.init(service);
    LifecycleHelper.close(service);
    try {
        service.setByteTranslator(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
}
Also used : HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator) Test(org.junit.Test)

Example 4 with HexStringByteTranslator

use of com.adaptris.util.text.HexStringByteTranslator in project interlok by adaptris.

the class HexSequenceConfiguredReplacementSource method obtainValue.

public String obtainValue(AdaptrisMessage msg) throws ServiceException {
    String result = null;
    ByteTranslator hexToBytes = new HexStringByteTranslator();
    ByteTranslator bytesToString = new SimpleByteTranslator();
    if (!isEmpty(charset)) {
        bytesToString = new CharsetByteTranslator(charset);
    }
    try {
        result = bytesToString.translate(hexToBytes.translate(this.getValue()));
    } catch (Exception e) {
        throw new ServiceException(e);
    }
    return result;
}
Also used : ServiceException(com.adaptris.core.ServiceException) ByteTranslator(com.adaptris.util.text.ByteTranslator) HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator) SimpleByteTranslator(com.adaptris.util.text.SimpleByteTranslator) CharsetByteTranslator(com.adaptris.util.text.CharsetByteTranslator) CharsetByteTranslator(com.adaptris.util.text.CharsetByteTranslator) HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator) SimpleByteTranslator(com.adaptris.util.text.SimpleByteTranslator) ServiceException(com.adaptris.core.ServiceException)

Example 5 with HexStringByteTranslator

use of com.adaptris.util.text.HexStringByteTranslator in project interlok by adaptris.

the class StringToHexService method reformat.

@Override
public String reformat(String s, String msgCharset) throws Exception {
    ByteTranslator bytesToHex = new HexStringByteTranslator();
    ByteTranslator stringToBytes = new CharsetByteTranslator(getCharacterEncoding());
    return bytesToHex.translate(stringToBytes.translate(s));
}
Also used : ByteTranslator(com.adaptris.util.text.ByteTranslator) HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator) CharsetByteTranslator(com.adaptris.util.text.CharsetByteTranslator) CharsetByteTranslator(com.adaptris.util.text.CharsetByteTranslator) HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator)

Aggregations

HexStringByteTranslator (com.adaptris.util.text.HexStringByteTranslator)7 Test (org.junit.Test)4 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 ByteTranslator (com.adaptris.util.text.ByteTranslator)3 CharsetByteTranslator (com.adaptris.util.text.CharsetByteTranslator)3 ServiceException (com.adaptris.core.ServiceException)1 SimpleByteTranslator (com.adaptris.util.text.SimpleByteTranslator)1