Java Utililty Methods SOAP Message

List of utility methods to do SOAP Message

Description

The list of methods to do SOAP Message are organized into topic(s).

Method

voidaddAttachment(SOAPMessage soapMessage, String payloadId, String contentType, byte[] content)
add Attachment
addAttachment(soapMessage, payloadId, contentType, new ByteArrayInputStream(content));
voidaddMessageHandler(Object binding, SOAPHandler handler)
Add a message handler to a SOAP binding
final Binding b = ((BindingProvider) binding).getBinding();
List handlerList = b.getHandlerChain();
if (handlerList == null)
    handlerList = new ArrayList();
handlerList.add(handler);
b.setHandlerChain(handlerList);
voidaddMimeHeader(SOAPMessage message, String name, String value)
Adds a custom MIME header to a SOAPMessage .
message.getMimeHeaders().setHeader(name, value);
voidaddNamespace(SOAPMessage message, String prefix, String uri)
Adds a specified namespace to a SOAPMessage .
message.getSOAPPart().getEnvelope().addNamespaceDeclaration(prefix, uri);
SOAPMessageconstructMessage(String mimeHdrsFile, String msgFile)
construct Message
SOAPMessage message;
MimeHeaders mimeHeaders = new MimeHeaders();
FileInputStream fis = new FileInputStream(msgFile);
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(mimeHdrsFile));
Hashtable hashTable = (Hashtable) ois.readObject();
ois.close();
if (hashTable.isEmpty()) {
} else {
...
StringconvertSoapMessageToString(SOAPMessage message)
convert Soap Message To String
String result = null;
if (message != null) {
    ByteArrayOutputStream baos = null;
    try {
        baos = new ByteArrayOutputStream();
        message.writeTo(baos);
        result = baos.toString();
    } catch (SOAPException e) {
...
MimeHeaderscopy(MimeHeaders headers)
copy
MimeHeaders newHeaders = new MimeHeaders();
Iterator eachHeader = headers.getAllHeaders();
while (eachHeader.hasNext()) {
    MimeHeader currentHeader = (MimeHeader) eachHeader.next();
    newHeaders.addHeader(currentHeader.getName(), currentHeader.getValue());
return newHeaders;
MimeHeaderscopyMimeHeaders(MimeHeaders headers)
Create a copy of an existing MimeHeaders object.
MimeHeaders result = new MimeHeaders();
Iterator iterator = headers.getAllHeaders();
while (iterator.hasNext()) {
    MimeHeader hdr = (MimeHeader) iterator.next();
    result.addHeader(hdr.getName(), hdr.getValue());
return result;
SOAPMessagecreate()
Create an empty SOAPMessage
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
return soapMessage;
AttachmentPartcreateAttachmentPart(String cid, DataHandler dh, SOAPMessage message)
Create an SAAJ AttachmentPart from a JAXWS Attachment
AttachmentPart ap = message.createAttachmentPart(dh);
ap.setContentId(cid);
return ap;