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

booleanisFaultResponse(SOAPMessage message)
is Fault Response
return message.getSOAPBody().getFault() != null;
booleanisOutgoingMessage(SOAPMessageContext smc)
Returns true if the SOAPMessageContext is part of the request
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
return outboundProperty.booleanValue();
BooleanisSOAP12(SOAPMessage soapMessage)
Determines if the envelope is SOAP 1.1 or 1.2.
return soapMessage.getSOAPPart().getEnvelope().getNamespaceURI().equals(SOAP12_URI);
booleanisSOAP12(SOAPMessage soapMessage)
Determine if a SOAPMessage is SOAP 1.2
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(soapEnvelope.getNamespaceURI()))
    return true;
return false;
booleanisSOAPFault(SOAPMessage messageSOAP)
Indicates if a SOAP message is actually a SOAP fault
try {
    if (messageSOAP == null || messageSOAP.getSOAPBody().hasFault()) {
        return true;
} catch (SOAPException ignore) {
return false;
voidprintMessage(SOAPMessageContext smc)
Prints the SOAP Message on the console
try {
    System.out.println("*********Message Start********");
    System.out.println(
            "This is a " + (((Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue()
                    ? "Outbound request"
                    : "Inbound response"));
    smc.getMessage().writeTo(System.out);
    System.out.println("*********Message End**********");
...
voidprintSoapFaultException(SOAPFaultException sfe)
print Soap Fault Exception
snapshotLogger.log(Level.INFO, "SOAP Fault -");
if (sfe.getFault().hasDetail()) {
    snapshotLogger.log(Level.INFO, sfe.getFault().getDetail().getFirstChild().getLocalName());
if (sfe.getFault().getFaultString() != null) {
    System.out.println("\n Message: " + sfe.getFault().getFaultString());
voidprintSOAPMessage(SOAPMessage msg, String titol)
print SOAP Message
ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
msg.writeTo(byteArrayOS);
System.out.println("*******************************");
System.out.println(titol);
System.out.println("-------------------------------");
System.out.println(new String(byteArrayOS.toByteArray()));
System.out.println("*******************************");
voidprintTree(NodeList childNodes, String padding, ByteArrayOutputStream byteArrayOS)
print Tree
try {
    NodeList nodes = childNodes;
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = (Node) nodes.item(i);
        String name = node.getNodeName();
        if (node.hasChildNodes()) {
            byteArrayOS.write(('\n' + padding + "<" + name + ">").getBytes());
            printTree(node.getChildNodes(), padding + " ", byteArrayOS);
...
voidsaveMimeHeaders(SOAPMessage msg, String fileName)
save Mime Headers
FileOutputStream fos = new FileOutputStream(fileName);
ObjectOutputStream oos = new ObjectOutputStream(fos);
Hashtable hashTable = new Hashtable();
MimeHeaders mimeHeaders = msg.getMimeHeaders();
Iterator iterator = mimeHeaders.getAllHeaders();
while (iterator.hasNext()) {
    MimeHeader mimeHeader = (MimeHeader) iterator.next();
    hashTable.put(mimeHeader.getName(), mimeHeader.getValue());
...