Java SOAP Message getHeaderValue(SOAPMessage message, String tagName)

Here you can find the source of getHeaderValue(SOAPMessage message, String tagName)

Description

get Header Value

License

Open Source License

Declaration

public static String getHeaderValue(SOAPMessage message, String tagName) 

Method Source Code


//package com.java2s;
/*/*from   w  w w . j a  v  a2 s.c  o  m*/
                       ChargeTime.eu - Java-OCA-OCPP
                               
                       MIT License
                               
                       Copyright (C) 2016 Thomas Volden <tv@chargetime.eu>
                               
                       Permission is hereby granted, free of charge, to any person obtaining a copy
                       of this software and associated documentation files (the "Software"), to deal
                       in the Software without restriction, including without limitation the rights
                       to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
                       copies of the Software, and to permit persons to whom the Software is
                       furnished to do so, subject to the following conditions:
                               
                       The above copyright notice and this permission notice shall be included in all
                       copies or substantial portions of the Software.
                               
                       THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
                       IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
                       FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
                       AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
                       LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
                       OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
                       SOFTWARE.
                       */

import org.w3c.dom.NodeList;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;

public class Main {
    public static String getHeaderValue(SOAPMessage message, String tagName) {
        String value = null;
        try {
            SOAPHeader header = message.getSOAPPart().getEnvelope().getHeader();
            NodeList elements = header.getElementsByTagNameNS("*", tagName);
            if (elements.getLength() > 0)
                value = elements.item(0).getChildNodes().item(0).getNodeValue();
        } catch (SOAPException e) {
            e.printStackTrace();
        }
        return value;
    }
}

Related

  1. getBodyContent(SOAPBody body)
  2. getBytes(SOAPMessage soap)
  3. getDeclaredNamespaces(SOAPElement aElement, Map aPrefixMap)
  4. getExcludedTypes()
  5. getFaultCodeAndString(SOAPMessage message)
  6. getJarredPluginPath(String bundleId)
  7. getNamespaceDeclarations(SOAPEnvelope env, SOAPBodyElement body)
  8. getNamespacePrefix(SOAPElement element, String nsURI)
  9. getNamespacePrefixes(SOAPElement element)