Hello CY,
For the needs of one of our customers, we implemented the support of
AS2 filename preservation in a customized version of H2O. This version
is used in production environment and support about 1,000 messages a
day. We only tested it between 2 H2O instances and between H2O and
another commercial AS2 messaging system. It works very well for us but
you may encounter some problems with other facing software.
IMPORTANT NOTICE : because AS2 filename preservation implementation
required to modify H2O AS2 part code, the resulting customized H2O
version is not certified by Drummond as the official version is.
Regarding the AS2 filename preservation specification (which is still
a draft specification),
http://www.drummondgroup.com/pdfs/draft-ietf-ediint-filename-preservation-02.txt,
the filename is transmited in the AS2 message headers in a Content-
Disposition field, for example:
Content-Disposition: attachment; filename="myfile.txt"
In our customized version, we can set a filename when calling "sender"
service to send a file with any valid filename. And we can get a
filename set by the sender when calling the "receiver" service.
You will find 2 files attached to the group:
- as2_filename_preservation_20090625.diff is a diff file showing the
differences between official H2O code (latest version: 07/05/2009) and
our own version (based on the same H2O version). It can help you
understand how it works and you can apply it on your own H2O code if
you want.
- as2_filename_preservation_20090625_corvus-as2-core.jar is a compiled
version of the only JAR you need to update in a fresh and official H2O
installation to have the AS2 filename preservation working. To use it:
- Stop Tomcat
- Go in hermes2\plugins\hk.hku.cecid.edi.as2 folder
- Backup the original corvus-as2-core.jar
- Copy the one attached to this message (changing its name to
corvus-as2-core.jar)
- Restart Tomcat
- AS2 filename preservation should be now supported!!
Then, you'll need to change a little bit your client code (to set or
get the filenames). Based on the example supply with latest H2O
official version, here is how you can handle it:
To set the filename of an outgoing message, go in package
hk.hku.cecid.corvus.ws, file MessageSender.java, method
addRequestPayload (Payload [] payloads):
After:
// Create file datasource.
FileDataSource fileDS = null;
fileDS = new FileDataSource(new File(payloads[i].getFilePath()));
ap.setDataHandler(new DataHandler(fileDS));
ap.setContentType(payloads[i].getContentType());
Add the following line :
ap.setMimeHeader("Content-Disposition", "attachment; filename=
\"myfile.txt\"");
Of course, you should adapt this code to match your needs (like adding
a parameter to addRequestPayload to pass the filename for the payload)
To get the filename of an incoming message, go in package
hk.hku.cecid.corvus.ws, file MessageReceiver.java, method
getResponsePayloads():
After:
AttachmentPart ap = (AttachmentPart) itr.next();
payloads[index] = new Payload(
ap.getDataHandler().getInputStream(),
ap.getContentType());
Add the following lines:
if (ap.getMimeHeader("Content-Disposition") != null) {
String contentDisposition = ap.getMimeHeader("Content-
Disposition")[0];
Pattern p = Pattern.compile("attachment; filename=\"(.*)\"");
Matcher m = p.matcher(contentDisposition);
if (m.find() && !m.group(1).equals("")) {
String filename = m.group(1);
}
}
You must import java.util.regex.Matcher and java.util.regex.Pattern
classes to get it working.
Again, you will have to do adapt this code to match your needs.
Otherwise, the value in "filename" variable will be lost. For example,
we modified the Payload class to store the filename with the payload
content and its content-type but the best implementation depends of
your architectures, client constraints and development language.
You will not need to do database schema modifications because the AS2
filename is stored throught the files in hermes2\repository\as2-
message-repository.
Please kindly let the community know if you can get this patch
working.
Best Regards
--
Florent Paillard
Connectiv-IT :: Consultant
88 rue de Richelieu - 75002 Paris
+ 33 1 71 18 12 30