Hi Oliver,
Please see inline ...
Oliver Jaun wrote:
>Hello
>
>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).
>
RFC 2045 (Format of Internet Message Bodies) talks about Base64
Content-Transfer-Encoding. Here's the relevant portion of this RFC:
The encoded output stream must be represented in lines of no more
than 76 characters each. All line breaks or other characters not
found in Table 1 must be ignored by decoding software. In base64
data, characters other than those in Table 1, line breaks, and other
white space probably indicate a transmission error, about which a
warning message or even a message rejection might be appropriate
under some circumstances.
This indicates that the attachment APIs are doing the right thing by
restricting the size of the lines to 76 characters.
>
>If you create a AttachmentPart and you use
>setMimeHeader("Content-Type-Encoding", "base64") then
>the default BASE64EncoderStream is used.
>
Yes that's true. When you set the value of Content-Transfer-Encoding
MIME header to "base64", the javax.mail.internet.MimeBodyPart.writeTo()
method writes the data to a Base64 encoding output stream. The
attachment APIs implementation is built on top of javax.mail.internet.*
classes, so there's no work-around to this situation.
Regards,
Vishal
>
>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 java.net.URI getUpdate(String updateId, String
>terminalId, BigInteger sliceNo) {
>try {
>MessageContext mc =
>servletEndpointContext.getMessageContext();
>FileInputStream fis = new
>FileInputStream("/tmp/bla.tar");
>InputStreamDataSource ids = new InputStreamDataSource(
>fis, "application/octet-stream", "distributedFile");
>
>DataHandler dh = new MyDataHandler(ids);
>AttachmentPart att =
>MessageFactory.newInstance().createMessage()
>.createAttachmentPart(dh);
>
>att.setDataHandler(dh);
>System.out.println("attachmentpart: " +
>att.getClass());
>
>att.setMimeHeader("Content-Type",
>"application/octet-stream");
>att.setMimeHeader("Content-Transfer-Encoding",
>"base64");
>att.setContentId("distributedFile");
>
>ArrayList list = new ArrayList();
>list.add(att);
>mc.setProperty(ServerPropertyConstants.SET_ATTACHMENT_PROPERTY,
>list);
>java.net.URI retVal = new
>java.net.URI("cid:distributedFile");
>return retVal;
>} catch(Exception e) {
>e.printStackTrace();
>}
>return null;
>}
>
>The Data Handler:
>
>class MyDataHandler extends DataHandler {
>public MyDataHandler(DataSource ds) {
>super(ds);
>System.out.println("init mydatahandler");
>}
>
>// os is passed as BASE64EncoderStream.... why???? I
>want to encode it myself!
>public void writeTo(OutputStream os) throws
>java.io.IOException {
>System.out.println("writeToooooooooooooooooooooo: " +
>os.getClass());
>super.writeTo(new Base64.OutputStream(os,
>Base64.DONT_BREAK_LINES | Base64.ENCODE));
>}
>}
>
>I hope anyone can help... Thanks a lot in advance
>
>Regards
>
>Oliver Jaun
>
>
>
>_______________________________
>Do you Yahoo!?
>Declare Yourself - Register online to vote today!
>http://vote.yahoo.com
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
>For additional commands, e-mail: users-help_at_jax-rpc.dev.java.net
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jax-rpc.dev.java.net
For additional commands, e-mail: users-help_at_jax-rpc.dev.java.net