users@jax-rpc.java.net

Re: Problems implementing DataHandler for AttachmentPart

From: Dennis Sosnoski <dms_at_sosnoski.com>
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
http://www.w3.org/TR/xmlschema-2/#base64Binary and the WS-I Attachments
profile
http://www.ws-i.org/Profiles/AttachmentsProfile-1.0-2004-08-24.html#Content-Transfer-Encoding
RFC 2045 (http://www.ietf.org/rfc/rfc2045.txt) 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:

>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).
>
>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 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
>
>
>


-- 
Dennis M. Sosnoski
Enterprise Java, XML, and Web Services
Training and Consulting
http://www.sosnoski.com
Redmond, WA  425.885.7197
---------------------------------------------------------------------
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