javax.xml.soap.SOAPHeader.appendChild()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中javax.xml.soap.SOAPHeader.appendChild()方法的一些代码示例,展示了SOAPHeader.appendChild()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SOAPHeader.appendChild()方法的具体详情如下:
包路径:javax.xml.soap.SOAPHeader
类名称:SOAPHeader
方法名:appendChild

SOAPHeader.appendChild介绍

暂无

代码示例

代码示例来源:origin: com.hynnet/xws-security

public void writeTo(SOAPMessage saaj) throws SOAPException {
  try {
    // TODO what about in-scope namespaces
    // Not very efficient consider implementing a stream buffer
    // processor that produces a DOM node from the buffer.
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    XMLStreamBufferSource source = new XMLStreamBufferSource(completeHeader);
    DOMResult result = new DOMResult();
    t.transform(source, result);
    Node d = result.getNode();
    if(d.getNodeType() == Node.DOCUMENT_NODE)
      d = d.getFirstChild();
    SOAPHeader header = saaj.getSOAPHeader();
    Node node = header.getOwnerDocument().importNode(d, true);
    header.appendChild(node);
  } catch (Exception e) {
    throw new SOAPException(e);
  }
}

代码示例来源:origin: com.vmware.photon.controller/photon-vsphere-adapter-util

/**
 * Finds the Security element from the header. If not found then creates one
 * and returns the same
 *
 */
public static Node getOrCreateSecurityElement(SOAPHeader header) {
  NodeList targetElement = header.getElementsByTagNameNS(
      WSS_NS, SECURITY_ELEMENT_NAME);
  if (targetElement == null || targetElement.getLength() == 0) {
    JAXBElement<SecurityHeaderType> value = wsseObjFactory
        .createSecurity(wsseObjFactory.createSecurityHeaderType());
    Node headerNode = marshallJaxbElement(value).getDocumentElement();
    return header.appendChild(header.getOwnerDocument().importNode(
        headerNode, true));
  } else if (targetElement.getLength() > 1) {
    throw new RuntimeException(ERR_INSERTING_SECURITY_HEADER);
  }
  return targetElement.item(0);
}

代码示例来源:origin: usnistgov/iheos-toolkit2

private static void insertAssertionIntoSoapHeader(SOAPHeader soapHeader, String assertionStr) throws Exception {
  Element securityElement = soapHeader.getOwnerDocument().createElementNS(WSSEConstants.WSSE_NS, WSSEConstants.WSSE_LOCAL);
  if (assertionStr != null) {
    LOG.info("Assertion to be inserted: " + assertionStr);
    Node assertion = createNodeFromString(assertionStr);
    Node importedAssertion;
    try {
      importedAssertion = soapHeader.getOwnerDocument().importNode(assertion.getFirstChild(), true);
    }catch (DOMException e){
      throw new Exception("Cannot import assertion to soap document: " + e.getMessage());
    }
    try {
      securityElement.appendChild(importedAssertion);
    }catch (DOMException e){
      throw  new Exception("Cannot append Assertion to Security element: " + e.getMessage());
    }
  } else {
    LOG.error("No assertion can be asserted, assertionStr set to null");
    throw new Exception("No assertion can be asserted, assertionStr set to null");
  }
  try {
    soapHeader.appendChild(securityElement);
  }catch (DOMException e){
    throw new Exception("Cannot append Security element to SOAP Header: " + e.getMessage());
  }
}

代码示例来源:origin: com.sun.xml.ws/jaxws-rt

public void writeTo(SOAPMessage saaj) throws SOAPException {
  SOAPHeader header = saaj.getSOAPHeader();
  if(header == null)
    header = saaj.getSOAPPart().getEnvelope().addHeader();
  Node clone = header.getOwnerDocument().importNode(node,true);
  header.appendChild(clone);
}

代码示例来源:origin: com.sun.xml.ws/rt

public void writeTo(SOAPMessage saaj) throws SOAPException {
  try {
    // TODO what about in-scope namespaces
    // Not very efficient consider implementing a stream buffer
    // processor that produces a DOM node from the buffer.
    TransformerFactory tf = XmlUtil.newTransformerFactory(true);
    Transformer t = tf.newTransformer();
    XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
    DOMResult result = new DOMResult();
    t.transform(source, result);
    Node d = result.getNode();
    if(d.getNodeType() == Node.DOCUMENT_NODE)
      d = d.getFirstChild();
    SOAPHeader header = saaj.getSOAPHeader();
    if(header == null)
      header = saaj.getSOAPPart().getEnvelope().addHeader();
    Node node = header.getOwnerDocument().importNode(d, true);
    header.appendChild(node);
  } catch (Exception e) {
    throw new SOAPException(e);
  }
}

代码示例来源:origin: com.sun.xml.ws/rt

public void writeTo(SOAPMessage saaj) throws SOAPException {
  SOAPHeader header = saaj.getSOAPHeader();
  if(header == null)
    header = saaj.getSOAPPart().getEnvelope().addHeader();
  Node clone = header.getOwnerDocument().importNode(node,true);
  header.appendChild(clone);
}

代码示例来源:origin: javaee/metro-jax-ws

public void writeTo(SOAPMessage saaj) throws SOAPException {
  SOAPHeader header = saaj.getSOAPHeader();
  if(header == null)
    header = saaj.getSOAPPart().getEnvelope().addHeader();
  Node clone = header.getOwnerDocument().importNode(node,true);
  header.appendChild(clone);
}

代码示例来源:origin: org.switchyard.components/switchyard-component-sca

soapmsg.getSOAPHeader().appendChild(wsseNode);
  credentials.addAll(new SOAPMessageCredentialExtractor().extract(soapmsg));
} catch (Exception e) {

代码示例来源:origin: com.sun.xml.ws/jaxws-rt

public void writeTo(SOAPMessage saaj) throws SOAPException {
  try {
    // TODO what about in-scope namespaces
    // Not very efficient consider implementing a stream buffer
    // processor that produces a DOM node from the buffer.
    TransformerFactory tf = XmlUtil.newTransformerFactory(true);
    Transformer t = tf.newTransformer();
    XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
    DOMResult result = new DOMResult();
    t.transform(source, result);
    Node d = result.getNode();
    if(d.getNodeType() == Node.DOCUMENT_NODE)
      d = d.getFirstChild();
    SOAPHeader header = saaj.getSOAPHeader();
    if(header == null)
      header = saaj.getSOAPPart().getEnvelope().addHeader();
    Node node = header.getOwnerDocument().importNode(d, true);
    header.appendChild(node);
  } catch (Exception e) {
    throw new SOAPException(e);
  }
}

代码示例来源:origin: javaee/metro-jax-ws

public void writeTo(SOAPMessage saaj) throws SOAPException {
  try {
    // TODO what about in-scope namespaces
    // Not very efficient consider implementing a stream buffer
    // processor that produces a DOM node from the buffer.
    TransformerFactory tf = XmlUtil.newTransformerFactory(true);
    Transformer t = tf.newTransformer();
    XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
    DOMResult result = new DOMResult();
    t.transform(source, result);
    Node d = result.getNode();
    if(d.getNodeType() == Node.DOCUMENT_NODE)
      d = d.getFirstChild();
    SOAPHeader header = saaj.getSOAPHeader();
    if(header == null)
      header = saaj.getSOAPPart().getEnvelope().addHeader();
    Node node = header.getOwnerDocument().importNode(d, true);
    header.appendChild(node);
  } catch (Exception e) {
    throw new SOAPException(e);
  }
}

代码示例来源:origin: javaee/metro-jax-ws

public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
      // TODO what about in-scope namespaces
      // Not very efficient consider implementing a stream buffer
      // processor that produces a DOM node from the buffer. 
      Transformer t = XmlUtil.newTransformer();                                   
      SOAPHeader header = saaj.getSOAPHeader();
      if (header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
// TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be 
// uncommented and all lines below, except the catch block, can be removed.            
//            t.transform(epr.asSource(localName), new DOMResult(header));
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
      epr.writeTo(localName, w);
      w.flush();
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      DocumentBuilderFactory fac = XmlUtil.newDocumentBuilderFactory(false);
      fac.setNamespaceAware(true);
      Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
      Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
      header.appendChild(eprNodeToAdd);             
    } catch (Exception e) {
      throw new SOAPException(e);
    }
  }

代码示例来源:origin: com.sun.xml.ws/jaxws-rt

public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
      // TODO what about in-scope namespaces
      // Not very efficient consider implementing a stream buffer
      // processor that produces a DOM node from the buffer. 
      Transformer t = XmlUtil.newTransformer();                                   
      SOAPHeader header = saaj.getSOAPHeader();
      if (header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
// TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be 
// uncommented and all lines below, except the catch block, can be removed.            
//            t.transform(epr.asSource(localName), new DOMResult(header));
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
      epr.writeTo(localName, w);
      w.flush();
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      DocumentBuilderFactory fac = XmlUtil.newDocumentBuilderFactory(false);
      fac.setNamespaceAware(true);
      Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
      Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
      header.appendChild(eprNodeToAdd);             
    } catch (Exception e) {
      throw new SOAPException(e);
    }
  }

代码示例来源:origin: com.sun.xml.ws/rt

public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
      // TODO what about in-scope namespaces
      // Not very efficient consider implementing a stream buffer
      // processor that produces a DOM node from the buffer. 
      Transformer t = XmlUtil.newTransformer();                                   
      SOAPHeader header = saaj.getSOAPHeader();
      if (header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
// TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be 
// uncommented and all lines below, except the catch block, can be removed.            
//            t.transform(epr.asSource(localName), new DOMResult(header));
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
      epr.writeTo(localName, w);
      w.flush();
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      DocumentBuilderFactory fac = XmlUtil.newDocumentBuilderFactory(false);
      fac.setNamespaceAware(true);
      Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
      Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
      header.appendChild(eprNodeToAdd);             
    } catch (Exception e) {
      throw new SOAPException(e);
    }
  }

代码示例来源:origin: org.switchyard.components/switchyard-component-soap

private void copyToSOAPHeader(SOAPHeader soapHeader, Property property) throws IOException, SOAPException {
    if ((property != null) && (matches(property.getName(), getIncludeRegexes(), new ArrayList<Pattern>()))) {
      String v = property.getValue().toString();
      QName qname = new QName(HEADER_NAMESPACE_PROPAGATION, property.getName());
      if (SOAPHeadersType.XML.equals(_soapHeadersType)) {
        try {
          Element xmlElement = new ElementPuller().pull(new StringReader(v));
          Node xmlNode = soapHeader.getOwnerDocument().importNode(xmlElement, true);
          soapHeader.appendChild(xmlNode);
        } catch (Throwable t) {
          soapHeader.addChildElement(qname).setValue(v);
        }
      } else {
        soapHeader.addChildElement(qname).setValue(v);
      }
    }
  }
}

代码示例来源:origin: org.switchyard.components/switchyard-component-soap

if (value instanceof Node) {
  Node domNode = soapHeader.getOwnerDocument().importNode((Node)value, true);
  soapHeader.appendChild(domNode);
} else if (value instanceof Configuration) {
  Element configElement = new ElementPuller().pull(new StringReader(value.toString()));
  Node configNode = soapHeader.getOwnerDocument().importNode(configElement, true);
  soapHeader.appendChild(configNode);
} else {
  String v = value.toString();
      Element xmlElement = new ElementPuller().pull(new StringReader(v));
      Node xmlNode = soapHeader.getOwnerDocument().importNode(xmlElement, true);
      soapHeader.appendChild(xmlNode);
    } catch (Throwable t) {
      soapHeader.addChildElement(qname).setValue(v);

代码示例来源:origin: org.picketlink.distribution/picketlink-jbas5

if (useWSSE) {
  SOAPElement security = create(userName, passwd);
  soapMessage.getSOAPHeader().appendChild(security);
} else {
  String authorization = Base64.encodeBytes((userName + ":" + passwd).getBytes());

代码示例来源:origin: org.picketlink.distribution/picketlink-jbas7

if (useWSSE) {
  SOAPElement security = create(userName, passwd);
  soapMessage.getSOAPHeader().appendChild(security);
} else {
  String authorization = Base64.encodeBytes((userName + ":" + passwd).getBytes());

代码示例来源:origin: org.picketlink/picketlink-trust-jbossws

soapMessage.getSOAPHeader().appendChild(security);

代码示例来源:origin: apache/cxf

SAAJUtils.getHeader(saaj).appendChild(el);
} catch (SOAPException e) {

代码示例来源:origin: org.apache.cxf/cxf-rt-ws-security

SAAJUtils.getHeader(saaj).appendChild(el);
} catch (SOAPException e) {

相关文章