users@jax-rpc.java.net

Problems implementing DataHandler for AttachmentPart

From: Oliver Jaun <olijaun_at_yahoo.com>
Date: Fri, 8 Oct 2004 04:42:04 -0700 (PDT)

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