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