Search in sources :

Example 1 with Base64ByteTranslator

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));
}
Also used : Base64ByteTranslator(com.adaptris.util.text.Base64ByteTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 2 with Base64ByteTranslator

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));
}
Also used : Base64ByteTranslator(com.adaptris.util.text.Base64ByteTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 3 with Base64ByteTranslator

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);
    }
}
Also used : Base64ByteTranslator(com.adaptris.util.text.Base64ByteTranslator) PasswordException(com.adaptris.security.exc.PasswordException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with Base64ByteTranslator

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));
}
Also used : Base64ByteTranslator(com.adaptris.util.text.Base64ByteTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 5 with Base64ByteTranslator

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));
}
Also used : Base64ByteTranslator(com.adaptris.util.text.Base64ByteTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Aggregations

Base64ByteTranslator (com.adaptris.util.text.Base64ByteTranslator)5 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 Test (org.junit.Test)4 PasswordException (com.adaptris.security.exc.PasswordException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1