Re: Problems implementing DataHandler for AttachmentPart

From: Dennis Sosnoski <>
Date: Fri, 15 Oct 2004 10:32:18 -0700

Strict base64 encoding is defined in terms of RFC 2045, which is
referenced by both the XML Schema recommendation and the WS-I Attachments
RFC 2045 ( says that you should
generated lines of no more than 76 characters for compatibility across
different forms of transport, although you're allowed to accept lines
that are longer.

  - Dennis

Oliver Jaun wrote:

>I want to implement my own DataHandler because I need
>strict base64 encoding for my SOAP Attachments. The
>BASE64EncoderStream makes newlines after 76
>characters. This does not conform to strict base64
>encoding (newline is not part of base64 alphabet).
>If you create a AttachmentPart and you use
>setMimeHeader("Content-Type-Encoding", "base64") then
>the default BASE64EncoderStream is used.
>So I implemeted my own DataHandler and added it to the
>AttachmentPart. In the DataHandler I implemented the
>writeTo(OutputStream os) method. Now something funny
>(well, not really ;-) happens: The OutputStream passed
>is already a BASE64EncoderStream. My idea was to do
>something like this: MyBase64Encoder(os) and write te
>data from the DataSource to this stream.
>I either got something completly wrong or this is a
>bug... Here's my code
>public getUpdate(String updateId, String
>terminalId, BigInteger sliceNo) {
>try {
>MessageContext mc =
>FileInputStream fis = new
>InputStreamDataSource ids = new InputStreamDataSource(
>fis, "application/octet-stream", "distributedFile");
>DataHandler dh = new MyDataHandler(ids);
>AttachmentPart att =
>System.out.println("attachmentpart: " +
>ArrayList list = new ArrayList();
> retVal = new
>return retVal;
>} catch(Exception e) {
>return null;
>The Data Handler:
>class MyDataHandler extends DataHandler {
>public MyDataHandler(DataSource ds) {
>System.out.println("init mydatahandler");
>// os is passed as BASE64EncoderStream.... why???? I
>want to encode it myself!
>public void writeTo(OutputStream os) throws
> {
>System.out.println("writeToooooooooooooooooooooo: " +
>super.writeTo(new Base64.OutputStream(os,
>I hope anyone can help... Thanks a lot in advance
>Oliver Jaun
>Do you Yahoo!?
>Declare Yourself - Register online to vote today!
>To unsubscribe, e-mail:
>For additional commands, e-mail:

Dennis M. Sosnoski
Enterprise Java, XML, and Web Services
Training and Consulting
Redmond, WA  425.885.7197
To unsubscribe, e-mail:
For additional commands, e-mail: