Java Code Examples for javax.xml.soap.SOAPMessage#getSOAPHeader()

The following examples show how to use javax.xml.soap.SOAPMessage#getSOAPHeader() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jdk8u60   File: EPRHeader.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 = DocumentBuilderFactory.newInstance();
            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);
        }
    }
 
Example 2
Source Project: j-road   File: AbstractXTeeBaseEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private XTeeHeader parseXteeHeader(SOAPMessage paringMessage) throws SOAPException {
  XTeeHeader pais = new XTeeHeader();
  if (paringMessage.getSOAPHeader() == null) {
    return pais;
  }

  SOAPHeader header = paringMessage.getSOAPHeader();
  for (Iterator<Node> headerElemendid = header.getChildElements(); headerElemendid.hasNext();) {
    Node headerElement = headerElemendid.next();
    if (!SOAPUtil.isTextNode(headerElement) && headerElement.getFirstChild() != null) {
      String localName = headerElement.getLocalName();
      String value = headerElement.getFirstChild().getNodeValue();
      pais.addElement(new QName(headerElement.getNamespaceURI(), localName), value);
    }
  }
  return pais;
}
 
Example 3
@Override
public void writeTo(SOAPMessage saaj) throws SOAPException {
    //TODO: SAAJ returns null instead of throwing SOAPException,
    // when there is no SOAPHeader in the message,
    // which leads to NPE.
    try {
        SOAPHeader header = saaj.getSOAPHeader();
        if (header == null) {
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        }
        Element node = (Element)infoset.writeTo(header);
        node.setAttributeNS(AddressingVersion.W3C.nsUri,AddressingVersion.W3C.getPrefix()+":"+IS_REFERENCE_PARAMETER,TRUE_VALUE);
    } catch (XMLStreamBufferException e) {
        throw new SOAPException(e);
    }
}
 
Example 4
Source Project: hottub   File: EPRHeader.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 = DocumentBuilderFactory.newInstance();
            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);
        }
    }
 
Example 5
@Override
public void writeTo(SOAPMessage saaj) throws SOAPException {
    //TODO: SAAJ returns null instead of throwing SOAPException,
    // when there is no SOAPHeader in the message,
    // which leads to NPE.
    try {
        SOAPHeader header = saaj.getSOAPHeader();
        if (header == null) {
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        }
        Element node = (Element)infoset.writeTo(header);
        node.setAttributeNS(AddressingVersion.W3C.nsUri,AddressingVersion.W3C.getPrefix()+":"+IS_REFERENCE_PARAMETER,TRUE_VALUE);
    } catch (XMLStreamBufferException e) {
        throw new SOAPException(e);
    }
}
 
Example 6
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        SOAPHeader header = saaj.getSOAPHeader();
        if (header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        infoset.writeTo(header);
    } catch (XMLStreamBufferException e) {
        throw new SOAPException(e);
    }
}
 
Example 7
@Override
public void writeTo(SOAPMessage saaj) throws SOAPException {
    SOAPHeader header = saaj.getSOAPHeader();
    if (header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
    SOAPHeaderElement she = header.addHeaderElement(name);

    if (type != null)
        she.addAttribute(typeAttributeName, type);
    she.addTextNode(value);
}
 
Example 8
public void writeTo(SOAPMessage saaj) throws SOAPException {
    SOAPHeader header = saaj.getSOAPHeader();
    if(header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
    SOAPHeaderElement she = header.addHeaderElement(name);
    if(mustUnderstand) {
        she.setMustUnderstand(true);
    }
    she.addTextNode(value);
}
 
Example 9
public void writeTo(SOAPMessage saaj) throws SOAPException {
    SOAPHeader header = saaj.getSOAPHeader();
    if (header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
    SOAPHeaderElement she = header.addHeaderElement(av.faultDetailTag);
    she = header.addHeaderElement(new QName(av.nsUri, wrapper));
    she.addTextNode(problemValue);
}
 
Example 10
@Override
public void writeTo(SOAPMessage saaj) throws SOAPException {
    SOAPHeader header = saaj.getSOAPHeader();
    if (header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
    SOAPHeaderElement she = header.addHeaderElement(name);

    if (type != null)
        she.addAttribute(typeAttributeName, type);
    she.addTextNode(value);
}
 
Example 11
public void writeTo(SOAPMessage saaj) throws SOAPException {
    SOAPHeader header = saaj.getSOAPHeader();
    if(header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
    SOAPHeaderElement she = header.addHeaderElement(name);
    if(mustUnderstand) {
        she.setMustUnderstand(true);
    }
    she.addTextNode(value);
}
 
Example 12
public void writeTo(SOAPMessage saaj) throws SOAPException {
    SOAPHeader header = saaj.getSOAPHeader();
    if (header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
    SOAPHeaderElement she = header.addHeaderElement(av.faultDetailTag);
    she = header.addHeaderElement(new QName(av.nsUri, wrapper));
    she.addTextNode(problemValue);
}
 
Example 13
Source Project: hottub   File: JAXBHeader.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        SOAPHeader header = saaj.getSOAPHeader();
        if (header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        bridge.marshal(jaxbObject,header);
    } catch (JAXBException e) {
        throw new SOAPException(e);
    }
}
 
Example 14
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        SOAPHeader header = saaj.getSOAPHeader();
        if (header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        bridge.marshal(jaxbObject,header);
    } catch (JAXBException e) {
        throw new SOAPException(e);
    }
}
 
Example 15
Source Project: j-road   File: AbstractXTeeBaseEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected XRoadProtocolVersion parseProtocolVersion(SOAPMessage requestMessage) throws SOAPException {
  XRoadProtocolVersion version = null;
  // Extract protocol version by headers
  if (requestMessage.getSOAPHeader() != null) {
    NodeList reqHeaders = requestMessage.getSOAPHeader().getChildNodes();
    for (int i = 0; i < reqHeaders.getLength(); i++) {
      Node reqHeader = reqHeaders.item(i);
      if (reqHeader.getNodeType() != Node.ELEMENT_NODE
          || !reqHeader.getLocalName().equals(XTeeHeader.PROTOCOL_VERSION.getLocalPart())) {
        continue;
      }

      if ((version = XRoadProtocolVersion.getValueByVersionCode(SOAPUtil.getTextContent(reqHeader))) != null) {
        return version;
      }
    }
  }

  // Extract protocol version by namespaces
  SOAPEnvelope soapEnv = requestMessage.getSOAPPart().getEnvelope();
  Iterator<String> prefixes = soapEnv.getNamespacePrefixes();
  while (prefixes.hasNext()) {
    String nsPrefix = prefixes.next();
    String nsURI = soapEnv.getNamespaceURI(nsPrefix).toLowerCase();
    if ((version = XRoadProtocolVersion.getValueByNamespaceURI(nsURI)) != null) {
      return version;
    }
  }
  throw new IllegalStateException("Unsupported protocol version");
}
 
Example 16
public void writeTo(SOAPMessage saaj) throws SOAPException {
    SOAPHeader header = saaj.getSOAPHeader();
    if(header == null)
        header = saaj.getSOAPPart().getEnvelope().addHeader();
    SOAPHeaderElement she = header.addHeaderElement(new QName(getNamespaceURI(), getLocalPart()));
    she.addChildElement(actionLocalName);
    she.addTextNode(action);
    if (soapAction != null) {
        she.addChildElement(soapActionLocalName);
        she.addTextNode(soapAction);
    }
}
 
Example 17
Source Project: j-road   File: XRoadHeaderUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static XRoadHeader parseXRoadHeader(SOAPMessage paringMessage) throws SOAPException {
  XRoadHeader xroadHeader = new XRoadHeader();

  SOAPHeader header = paringMessage.getSOAPHeader();
  for (Iterator<Node> headerElemendid = header.getChildElements(); headerElemendid.hasNext(); ) {
    Node headerElement = headerElemendid.next();
    if (!SOAPUtil.isTextNode(headerElement) && headerElement.getFirstChild() != null) {
      XRoadHeaderElement el = parseHeaderElement(headerElement, header);
      if (el != null) {
        xroadHeader.addHeaderElement(el);
      }
    }
  }
  return xroadHeader;
}
 
Example 18
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);
}
 
Example 19
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        SOAPHeader header = saaj.getSOAPHeader();
        if (header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        infoset.writeTo(header);
    } catch (XMLStreamBufferException e) {
        throw new SOAPException(e);
    }
}
 
Example 20
Source Project: jdk8u60   File: DOMHeader.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
}