use of com.adaptris.util.text.Base64ByteTranslator in project interlok by adaptris.
the class Base64MetadataDecodeTest method testService.
@Test
public void testService() throws Exception {
Base64DecodeMetadataService service = new Base64DecodeMetadataService(METADATA_KEY).withStyle(Base64Encoding.BASIC);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("asdfghjk");
String metadataValue = new Base64ByteTranslator().translate("Hello World".getBytes());
msg.addMetadata(METADATA_KEY, metadataValue);
execute(service, msg);
assertNotSame(metadataValue, msg.getMetadataValue(METADATA_KEY));
assertEquals("Hello World", msg.getMetadataValue(METADATA_KEY));
}
use of com.adaptris.util.text.Base64ByteTranslator in project interlok by adaptris.
the class PayloadHashingServiceTest method testService.
@Test
public void testService() throws Exception {
PayloadHashingService service = new PayloadHashingService(SHA256, METADATA_KEY);
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 Base64ByteTranslator()), msg.getMetadataValue(METADATA_KEY));
}
use of com.adaptris.util.text.Base64ByteTranslator in project interlok by adaptris.
the class DynamicBasicAuthorizationHeader method setup.
@Override
public void setup(String target, AdaptrisMessage msg, ResourceTargetMatcher auth) throws CoreException {
try {
String username = Args.notBlank(msg.resolve(getUsername()), "username");
String password = Args.notBlank(msg.resolve(getPassword()), "password");
String encoded = new Base64ByteTranslator().translate(String.format("%s:%s", username, Password.decode(password)).getBytes("UTF-8"));
authHeader = String.format("Basic %s", encoded);
} catch (UnsupportedEncodingException | IllegalArgumentException | PasswordException e) {
throw ExceptionHelper.wrapCoreException(e);
}
}
use of com.adaptris.util.text.Base64ByteTranslator in project interlok by adaptris.
the class MetadataStreamOutputTest method testInsert_Encoding.
@Test
public void testInsert_Encoding() throws Exception {
String base64 = Base64.getEncoder().encodeToString(TEXT.getBytes());
MetadataStreamOutput p = new MetadataStreamOutput().withTranslator(new Base64ByteTranslator());
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
try (ByteArrayInputStream in = new ByteArrayInputStream(TEXT.getBytes());
OutputStream out = p.wrap(msg)) {
IOUtils.copy(in, out);
}
assertNotSame(base64, msg.getContent());
assertEquals(base64, msg.getMetadataValue(DEFAULT_METADATA_KEY));
}
use of com.adaptris.util.text.Base64ByteTranslator in project interlok by adaptris.
the class Base64MetadataDecodeTest method testService_Encoding.
@Test
public void testService_Encoding() throws Exception {
Base64DecodeMetadataService service = new Base64DecodeMetadataService(METADATA_KEY);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("asdfghjk", "UTF-8");
String metadataValue = new Base64ByteTranslator().translate("Hello World".getBytes("UTF-8"));
msg.addMetadata(METADATA_KEY, metadataValue);
execute(service, msg);
assertNotSame(metadataValue, msg.getMetadataValue(METADATA_KEY));
assertEquals("Hello World", msg.getMetadataValue(METADATA_KEY));
}
Aggregations