1

This is my first post and i'm really stuck. Here is what i need to do: I'm writing a java web service client using axis2 to generate the proxies and i'm trying to send an attachment. The attachment must be encoded by base64 and the proxy is calling for a datahandler. I've been using MimeUtility.encode to create the encoding but the datahandler does not like the output stream. The datahandler has only worked with a string but the string is not interperted correctly on the server side. If you can give me some direction i've been working on this for days. Here is the bad code i have, right now it does not read the data handler but hopefully it illustrates what i need to do:

int BUFFER_SIZE = 4096;
byte[] buffer = new byte[BUFFER_SIZE];
InputStream input = new FileInputStream("C:/test.docx");
OutputStream encodedOutput = MimeUtility.encode(new ByteArrayOutputStream(), "base64");
int n = input.read(buffer, 0, BUFFER_SIZE);
while (n >= 0) {
    encodedOutput.write(buffer, 0, n);
    n = input.read(buffer, 0, BUFFER_SIZE);
}
DataHandler dhandle = new DataHandler(encodedOutput, "base64");
jwcmrod
  • 11
  • 1
  • 3
  • +1 for proper formatting – Liam Jan 24 '12 at 04:41
  • What is the error message you're seeing? (If you're sending sizable files, it will improve transmission time to use MTOM encoding.) –  Jan 24 '12 at 04:47
  • here is the first error: Error reading data handler – jwcmrod Jan 24 '12 at 04:51
  • later on it says javax.activation.UnsupportedDataTypeException: no object DCH for MIME type base64 – jwcmrod Jan 24 '12 at 04:51
  • What is your `output` variable? You first reference it as you're passing it to the DataHandler constructor. Perhaps you mean to pass it `buffer`? –  Jan 24 '12 at 04:55
  • PS, it's a SAAS webservice i'm connecting to and they require base64, i'll have to deal with the 37% overhead. file limits are 9mb. – jwcmrod Jan 24 '12 at 04:56
  • made the correction, passing the outputstream encodedOutput to the datahandler – jwcmrod Jan 24 '12 at 05:00
  • Just a guess, but the documentation for DataHandler says the second parameter of the constructor should be a MIME type. "base64" is not a MIME type, it's an encoding. Have you tried passing "application/octet-stream" or possibly "text/plain" instead? – Brian Rogers Jan 24 '12 at 06:44
  • Hi Brian, i tried your suggestion, i still received the error, what you said makes sense. i must be missing a couple of steps. – jwcmrod Jan 24 '12 at 16:46

0 Answers0