For my latest customer/project I came up with this class:
package nl.darwin-it.osb.base64; import java.io.IOException; import java.io.InputStream; import java.io.ByteArrayInputStream; import weblogic.utils.encoders.BASE64Decoder; import weblogic.utils.encoders.BASE64Encoder; import java.nio.charset.Charset; public class Base64EncoderDecoder { private static final Charset UTF8_CHARSET; public static void main(final String[] args) { } public static String encode(final byte[] bytes) { final BASE64Encoder encoder = new BASE64Encoder(); final String encodedString = encoder.encodeBuffer(bytes); return encodedString; } public static int getLength(final byte[] bytes) { int length = bytes.length; return length; } public static byte[] decode(final String b64Document) throws IOException { final BASE64Decoder decoder = new BASE64Decoder(); final InputStream inputStream = new ByteArrayInputStream(b64Document.getBytes(Base64EncoderDecoder.UTF8_CHARSET)); final byte[] decodedBytes = decoder.decodeBuffer(inputStream); return decodedBytes; } static { UTF8_CHARSET = Charset.forName("UTF-8"); } }
And if you use JDeveloper11g as a IDE the only lib you need to compile this is: com.bea.core.utils.full_1.9.0.1.jar. Or com.bea.core.utils.full_1.10.0.0.jar, if using oepe version 11.1.1.8. The jars can be found in ${oracle.home}/modules. Where ${oracle.home} refers to your JDeveloper11g or OEPE-Middleware installation.
By the way, in my OSB project I need to process Attachments in my message (Soap with Attachments), where I need to upload the documents to a ContentServer. Unfortunately the ContentServer needs the filesize (it apparenlty does not determine it by base64-decoding it). So I added the getLength() method to determine it with a java-callout similar to the base64-encode.
Input of the methods is a variable like 'attachmentBin' resulted from an Assing with an expression like:
$attachments/ctx:attachment[ctx:Content-ID/text()=$contentId]/ctx:body/ctx:binary-content
4 comments :
you can try this free online service to convert string to base64 online(http://www.online-code.net/base64-string.html).
Yes, there are tons of them. When I need to do so, I google and pick one.
But this article talks about how to do so within an OSB proxy-service.
Hi
I want to use decode method, in order to convert String to base64.
But I always get as an answer, something like that: [B@186db54.
There isn't a base64 result at all...
Thanks in advance
Elad
Hi,
I would say that the content you provide to the method isn't appropriate or complete Base64 content. Check it with https://www.base64decode.org/. Or https://coderstoolbox.net/string/#!encoding=xml&action=encode&charset=us_ascii.
But could you ask the same question on community.oracle.com? Then more people can help and you could provide more details.
Regards,
Martien
Post a Comment