0

I Am working on an application that can send EDIFACT messages by mail. The sending and receiving mail is no problem, receiving an EDIFACT message (send by another application) works as well.

EDIFACT is a standard to send business to business information (invoices for example)

The mail has this structure:

Message-ID: 20101110081058.CLOCKT..SRC.SRCNUMBER.edi01@SENDER.DOMAIN.com
From: EDI-berichten <edi01@SENDER.DOMAIN.com>
Date: Wed, 10 Nov 2010 08:10:57
To: <ekt@DOMAIN.nl>
Subject: INVOIC;SRC
MIME-VERSION: 1.0
Content-type: application/EDIFACT;
  name=message.edi
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="message.edi"
X-OriginalArrivalTime: 10 Nov 2010 07:13:29.0843 (UTC) FILETIME=[C6CCD430:01CB80A6]
X-Virus-Scanned: clamav-milter 0.96.4 at pilot
X-Virus-Status: Clean

here you can find the EDIFACT specifications: http://www.faqs.org/rfcs/rfc1767.html

Normally you send an attachment by creating a MimeMultipart and add a text and an attach part to this. The edifact message however, does not have a message part, just the attachment.

when I add the attachment part to the content, like this:

MimeBodyPart attachBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(fileAttach);
attachBodyPart.setDataHandler(new DataHandler(source));
attachBodyPart.setFileName(source.getName());
msg.setContent(attachBodyPart, "application/EDIFACT");

I get this error:

javax.mail.MessagingException: IOException while sending message;
  nested exception is:
    javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/EDIFACT
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:930)

etc... and finally this:

Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/EDIFACT
    at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:877)
    at javax.activation.DataHandler.writeTo(DataHandler.java:302)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1383)
    at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1743)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:888)

Does anyone have any experience in creating a message like this one, or how to create a message handler for a type like application/EDIFACT?

In receiving a EDIFACT message and saving the attachment I had also the problem it's not in the default way to save an attachment, using:

mp = (Multipart)message.getContent();
BodyPart part = mp.getBodyPart(i);
part.getInputStream()

I had to use this instead (adding this info, because it might be a lead to the solution):

SharedByteArrayInputStream sbaIs = (SharedByteArrayInputStream)message.getContent()

** EDIT 18 mar 2013 **

The minimal response to my question over here was a reason to figure it out myselve, and in the end I made it an open source porject. it already was usefull to some developers.

So have a look: use and please feedback on it: https://github.com/iamit/IAmEdifact

michel.iamit
  • 5,788
  • 9
  • 55
  • 74
  • IAm close to a solution. – michel.iamit Nov 19 '10 at 16:09
  • Googling didn't get me an asnwer, neither this forum (so far): so I started a site for this kind of problem, where people can find how this works: https://sites.google.com/site/edifact4java/home (based on my own research) – michel.iamit Nov 19 '10 at 16:10

1 Answers1

3

Yesterday very late I have finished working on the solution of the problem descibed above. I could not find a proper answer anyweher on the internet. So I created a page with steps of how to do this (documentation is not entirely finished, but it will be soon)

The site: https://sites.google.com/site/edifact4java/home

In short, you have to do this:

  1. Add a DHC (DataContentHandler) to the MailcapCommandMap
  2. Create a DataContentHandler for the mime-type application/EDIFACT
  3. Create a MimePart customised for application/EDIFACT
  4. Create a DataHandler for an edifact file or message
  5. Create a message interface for edifact messages

And put all this together, and..... it works!!

A long puzzle, that's why I take the effort documenting it on a site. Hopefully somebody, some day can do his/her profit with it.

michel.iamit
  • 5,788
  • 9
  • 55
  • 74
  • Too bad this question and answer is marked as a tumbleweed. Through the linked site I made for this one, I received some e-mails with questions. So I know it's very specific... but at least it helps some people. So if you come here and find the answer on my site, please vote this up! – michel.iamit Nov 24 '11 at 12:39
  • So this is basically not an EDIFACT problem, but JavaMail. Good you solved it. – Thorbjørn Ravn Andersen Aug 05 '12 at 13:58