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

SOAPMessagegetSOAPMessage(Map headerMap, InputStream is)
Parses SOAP message from InputStream with headers.
MimeHeaders mimeHeaders = new MimeHeaders();
for (Entry<String, String> entry : headerMap.entrySet()) {
    mimeHeaders.addHeader(entry.getKey(), entry.getValue());
SOAPMessage soapMessage = mf.createMessage(mimeHeaders, is);
soapMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
return soapMessage;
SOAPMessagegetSOAPMessage(Source msg)
get SOAP Message
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
message.getSOAPPart().setContent(msg);
message.saveChanges();
return message;
StringgetSOAPMessageAsString(SOAPMessage soapMessage)
get SOAP Message As String
try {
    TransformerFactory tff = TransformerFactory.newInstance();
    Transformer tf = tff.newTransformer();
    tf.setOutputProperty(OutputKeys.INDENT, "yes");
    tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    Source sc = soapMessage.getSOAPPart().getContent();
    ByteArrayOutputStream streamOut = new ByteArrayOutputStream();
    StreamResult result = new StreamResult(streamOut);
...
StringgetSoapMessageString(SOAPMessage message)
get Soap Message String
try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) {
    Source source = message.getSOAPPart().getContent();
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    StreamResult streamResult = new StreamResult(outStream);
    transformer.transform(source, streamResult);
    String returnValue = outStream.toString("utf-8");
    return returnValue;
} catch (Exception e) {
...
MessageFactorygetSOAPMsgFactory()
get SOAP Msg Factory
if (_msgFact == null) {
    _msgFact = MessageFactory.newInstance();
return _msgFact;
StringgetString(SOAPMessage msg)
get String
StringWriter w = new StringWriter();
StreamResult result = new StreamResult(w);
print(msg, result);
w.flush();
return w.toString();
booleanhasAttachments(SOAPMessage message)
Checks if the given SOAP message has attachments.
if (message == null) {
    return false;
if (message.countAttachments() == 0) {
    return false;
return true;
voidinvokeOneWay(Dispatch dispatch, String request, String... args)
invoke One Way
String fRequest = String.format(request, args);
dispatch.invokeOneWay(getSOAPMessage(makeStreamSource(fRequest)));
booleanisExceptionObject(Class o)
is Exception Object
final String behaviourString = "java.lang.Exception";
Class<?> behaviour;
try {
    behaviour = Class.forName(behaviourString);
} catch (ClassNotFoundException e) {
    throw new RuntimeException("Unable to determine interface behaviour from : " + behaviourString, e);
return checkBehaviour(o, behaviour);
...
booleanisFaultMessage(final SOAPMessage msg)
is Fault Message
try {
    return msg.getSOAPBody().getFault() != null;
} catch (final Exception ignore) {
return false;