This post is on little tool mimeswacurl for sending an arbitrary file as attachment of a SOAP with Attachments file to a service endpoint.
This is really useful if developing a DataPower service dealing with SOAP with Attachments.
On DataPower the so called attachment-manifest gives details of the SOAP document as well as all atachments.
Stylesheet manifest.xsl which just outputs var://local/attachment-manifest for demo application below:
$ cat manifest.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
extension-element-prefixes="dp"
>
<xsl:output omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:copy-of select="dp:variable('var://local/attachment-manifest')" />
</xsl:template>
</xsl:stylesheet>
$
$ mimeswacurl xslt.pdf http://dp3-l3:2051 | tidy -q -xml
<manifest>
<package-headers />
<root-headers>
<header>
<name>Content-Type</name>
<value>application/soap+xml</value>
</header>
<header>
<name>Content-Location</name>
<value>root</value>
</header>
</root-headers>
<media-type>
<value>multipart/related; boundary="epoch-1299951959";
type="text/xml"</value>
<type>multipart</type>
<sub-type>related</sub-type>
</media-type>
<attachments>
<attachment>
<uri>cid:binary</uri>
<size>61806</size>
<header>
<name>Content-Type</name>
<value>application/pdf</value>
</header>
<header>
<name>Content-Transfer-Encoding</name>
<value>binary</value>
</header>
<header>
<name>Content-Id</name>
<value><binary></value>
</header>
</attachment>
</attachments>
</manifest>
$
$ cat MimeType.java
import java.net.FileNameMap;
import java.net.URLConnection;
public class MimeType {
public static void main(String args[]) throws Exception {
String mimetype = URLConnection.getFileNameMap().getContentTypeFor(args[0]);
System.out.println( (mimetype!=null) ? mimetype : "application/octet-stream" );
}
}
$
$ cat mimeswacurl
#!/bin/bash
boundary=epoch-`date +%s`
echo "--$boundary
Content-Type: application/soap+xml
Content-Location: root
<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">
<env:Body>
<some_soap/>
</env:Body>
</env:Envelope>
--$boundary
Content-Type: `java -classpath ~/bin MimeType $1`
Content-Transfer-Encoding: binary
Content-Id: <binary>
" `cat $1` "
--$boundary--
" | curl -s --data-binary @- -H 'Content-Type: multipart/related; type="text/xml"; boundary="'$boundary'"' $2
$