Testerpublic class Tester extends Object
Fields Summary |
---|
public static final String | HEADER_CONTENT_TYPEField HEADER_CONTENT_TYPE | public static final String | HEADER_CONTENT_TRANSFER_ENCODINGField HEADER_CONTENT_TRANSFER_ENCODING | private static final String | addressField address |
Methods Summary |
---|
private static void | addBodyPart(javax.mail.internet.MimeMultipart mp, javax.activation.DataHandler dh)Method addBodyPart
MimeBodyPart messageBodyPart = new MimeBodyPart();
try {
messageBodyPart.setDataHandler(dh);
String contentType = dh.getContentType();
if ((contentType == null) || (contentType.trim().length() == 0)) {
contentType = "application/octet-stream";
}
System.out.println("Content type: " + contentType);
messageBodyPart.setHeader(HEADER_CONTENT_TYPE, contentType);
messageBodyPart.setHeader(
HEADER_CONTENT_TRANSFER_ENCODING,
"binary"); // Safe and fastest for anything other than mail
mp.addBodyPart(messageBodyPart);
} catch (javax.mail.MessagingException e) {
}
| public static void | main(java.lang.String[] args)Method main
/*
* Start to prepare service call. Once this is done, several
* calls can be made on the port (see below)
*
* Fist: get the service locator. This implements the functionality
* to get a client stub (aka port).
*/
SwaServiceLocator service = new SwaServiceLocator();
/*
* Here we use an Axis specific call that allows to override the
* port address (service endpoint address) with an own URL. Comes
* in handy for testing.
*/
java.net.URL endpoint;
try {
endpoint = new java.net.URL(address);
} catch (java.net.MalformedURLException e) {
throw new javax.xml.rpc.ServiceException(e);
}
SwaPort port = (SwaPort) service.getSwaHttp(endpoint);
/*
* At this point all preparations are done. Using the port we can
* now perform as many calls as necessary.
*/
/*
* Prepare the Multipart attachment. It consists of several data files. The
* multipart container is of type "multipart/mixed"
*/
MimeMultipart mpRoot = new MimeMultipart();
System.out.println("MimeMultipart content: " + mpRoot.getContentType());
DataHandler dh = new DataHandler(new FileDataSource("duke.gif"));
addBodyPart(mpRoot, dh);
dh = new DataHandler(new FileDataSource("pivots.jpg"));
addBodyPart(mpRoot, dh);
// perform call
port.swaSend("AppName", mpRoot);
|
|