javax.xml.soap.SOAPHeaderElement Java Examples

The following examples show how to use javax.xml.soap.SOAPHeaderElement. 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 File: SimpleSoapPayloadPolicy.java    From apiman with Apache License 2.0 6 votes vote down vote up
/**
 * @see io.apiman.gateway.engine.policy.IPolicy#apply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
 */
@SuppressWarnings("nls")
@Override
public void apply(final ApiRequest request, final IPolicyContext context, final Object config,
        final IPolicyChain<ApiRequest> chain) {
    try {
        SOAPEnvelope soapPayload = context.getAttribute(PolicyContextKeys.REQUEST_PAYLOAD, (SOAPEnvelope) null);
        if (soapPayload != null) {
            SOAPHeader header = soapPayload.getHeader();
            SOAPHeaderElement header1 = (SOAPHeaderElement) header.examineAllHeaderElements().next();
            String prop1 = header1.getTextContent();
            request.getHeaders().put("X-Property-1", prop1);
            header.addHeaderElement(new QName("urn:ns5", "Property5")).setTextContent("value-5");
        }
        chain.doApply(request);
    } catch (Exception e) {
        chain.throwError(e);
    }
}
 
Example #2
Source File: SoapPayloadIOTest.java    From apiman with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link io.apiman.gateway.engine.io.SoapPayloadIO#marshall(org.w3c.dom.Document)}.
 */
@Test
public void testMarshall_Simple() throws Exception {
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPMessage message = msgFactory.createMessage();
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();

    SOAPHeader header = envelope.getHeader();
    SOAPHeaderElement cheader = header.addHeaderElement(new QName("urn:ns1", "CustomHeader"));
    cheader.setTextContent("CVALUE");

    SoapPayloadIO io = new SoapPayloadIO();
    byte[] data = io.marshall(envelope);
    String actual = new String(data);

    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header><CustomHeader xmlns=\"urn:ns1\">CVALUE</CustomHeader></SOAP-ENV:Header><SOAP-ENV:Body/></SOAP-ENV:Envelope>";
    Assert.assertEquals(expected, actual);
}
 
Example #3
Source File: SAAJMessageHeaders.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** Set the initial understood/not understood state of the headers in this
 * object
 */
private void initHeaderUnderstanding() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return;
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    while(allHeaders.hasNext()) {
        SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next();
        if (nextHdrElem == null) {
            continue;
        }
        if (nextHdrElem.getMustUnderstand()) {
            notUnderstood(nextHdrElem.getElementQName());
        }
        //only headers explicitly marked as understood should be
        //in the understoodHeaders set, so don't add anything to
        //that set at the beginning
    }

}
 
Example #4
Source File: SoapServlet.java    From mdw with Apache License 2.0 6 votes vote down vote up
protected Map<String,String> addSoapMetaInfo(Map<String, String> metaInfo, SOAPMessage soapMessage)
        throws SOAPException {
    SOAPHeader soapHeader = soapMessage.getSOAPHeader();
    if (soapHeader == null) {
        return metaInfo;
    }
    else {
        Map<String, String> newMetaInfo = new HashMap<String, String>();
        newMetaInfo.putAll(metaInfo);
        Iterator<?> iter = soapHeader.examineAllHeaderElements();
        while (iter.hasNext()) {
            SOAPHeaderElement headerElem = (SOAPHeaderElement) iter.next();
            if (!Listener.AUTHENTICATED_USER_HEADER.equals(headerElem.getNodeName()))
                newMetaInfo.put(headerElem.getNodeName(), headerElem.getTextContent());
        }
        return newMetaInfo;
    }
}
 
Example #5
Source File: SAAJMessageHeaders.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/** Set the initial understood/not understood state of the headers in this
 * object
 */
private void initHeaderUnderstanding() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return;
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    while(allHeaders.hasNext()) {
        SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next();
        if (nextHdrElem == null) {
            continue;
        }
        if (nextHdrElem.getMustUnderstand()) {
            notUnderstood(nextHdrElem.getElementQName());
        }
        //only headers explicitly marked as understood should be
        //in the understoodHeaders set, so don't add anything to
        //that set at the beginning
    }

}
 
Example #6
Source File: SAAJMessageHeaders.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Set the initial understood/not understood state of the headers in this
 * object
 */
private void initHeaderUnderstanding() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return;
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    while(allHeaders.hasNext()) {
        SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next();
        if (nextHdrElem == null) {
            continue;
        }
        if (nextHdrElem.getMustUnderstand()) {
            notUnderstood(nextHdrElem.getElementQName());
        }
        //only headers explicitly marked as understood should be
        //in the understoodHeaders set, so don't add anything to
        //that set at the beginning
    }

}
 
Example #7
Source File: SAAJMessageHeaders.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Set the initial understood/not understood state of the headers in this
 * object
 */
private void initHeaderUnderstanding() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return;
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    while(allHeaders.hasNext()) {
        SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next();
        if (nextHdrElem == null) {
            continue;
        }
        if (nextHdrElem.getMustUnderstand()) {
            notUnderstood(nextHdrElem.getElementQName());
        }
        //only headers explicitly marked as understood should be
        //in the understoodHeaders set, so don't add anything to
        //that set at the beginning
    }

}
 
Example #8
Source File: SAAJMessageHeaders.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** Set the initial understood/not understood state of the headers in this
 * object
 */
private void initHeaderUnderstanding() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return;
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    while(allHeaders.hasNext()) {
        SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next();
        if (nextHdrElem == null) {
            continue;
        }
        if (nextHdrElem.getMustUnderstand()) {
            notUnderstood(nextHdrElem.getElementQName());
        }
        //only headers explicitly marked as understood should be
        //in the understoodHeaders set, so don't add anything to
        //that set at the beginning
    }

}
 
Example #9
Source File: SAAJMessageHeaders.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/** Set the initial understood/not understood state of the headers in this
 * object
 */
private void initHeaderUnderstanding() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return;
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    while(allHeaders.hasNext()) {
        SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next();
        if (nextHdrElem == null) {
            continue;
        }
        if (nextHdrElem.getMustUnderstand()) {
            notUnderstood(nextHdrElem.getElementQName());
        }
        //only headers explicitly marked as understood should be
        //in the understoodHeaders set, so don't add anything to
        //that set at the beginning
    }

}
 
Example #10
Source File: SAAJMessageHeaders.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Header get(String nsUri, String localName, boolean markAsUnderstood) {
    SOAPHeaderElement h = find(nsUri, localName);
    if (h != null) {
        if (markAsUnderstood) {
            understood(nsUri, localName);
        }
        return new SAAJHeader(h);
    }
    return null;
}
 
Example #11
Source File: SAAJMessageHeaders.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<Header> asList() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return Collections.emptyList();
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    List<Header> headers = new ArrayList<Header>();
    while (allHeaders.hasNext()) {
        SOAPHeaderElement nextHdr = (SOAPHeaderElement) allHeaders.next();
        headers.add(new SAAJHeader(nextHdr));
    }
    return headers;
}
 
Example #12
Source File: SAAJMessageHeaders.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<Header> asList() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return Collections.emptyList();
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    List<Header> headers = new ArrayList<Header>();
    while (allHeaders.hasNext()) {
        SOAPHeaderElement nextHdr = (SOAPHeaderElement) allHeaders.next();
        headers.add(new SAAJHeader(nextHdr));
    }
    return headers;
}
 
Example #13
Source File: FaultDetailHeader.java    From openjdk-jdk8u with 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();
    SOAPHeaderElement she = header.addHeaderElement(av.faultDetailTag);
    she = header.addHeaderElement(new QName(av.nsUri, wrapper));
    she.addTextNode(problemValue);
}
 
Example #14
Source File: StringHeader.java    From openjdk-jdk8u with 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();
    SOAPHeaderElement she = header.addHeaderElement(name);
    if(mustUnderstand) {
        she.setMustUnderstand(true);
    }
    she.addTextNode(value);
}
 
Example #15
Source File: ProblemActionHeader.java    From openjdk-jdk9 with 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();
    SOAPHeaderElement she = header.addHeaderElement(new QName(getNamespaceURI(), getLocalPart()));
    she.addChildElement(actionLocalName);
    she.addTextNode(action);
    if (soapAction != null) {
        she.addChildElement(soapActionLocalName);
        she.addTextNode(soapAction);
    }
}
 
Example #16
Source File: SAAJMessageHeaders.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<Header> asList() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return Collections.emptyList();
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    List<Header> headers = new ArrayList<Header>();
    while (allHeaders.hasNext()) {
        SOAPHeaderElement nextHdr = (SOAPHeaderElement) allHeaders.next();
        headers.add(new SAAJHeader(nextHdr));
    }
    return headers;
}
 
Example #17
Source File: RelatesToHeader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@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 #18
Source File: SecureSoapMessages.java    From spring-ws-security-soap-example with MIT License 5 votes vote down vote up
private static final SOAPMessage getMessageToSign(final String pathBase)
        throws SOAPException, IOException {
    final SOAPMessage soapMessage;
    final SOAPPart soapPart;
    final SOAPEnvelope soapEnvelope;
    final SOAPHeader soapHeader;
    final SOAPHeaderElement secElement;
    final SOAPElement binaryTokenElement;

    soapMessage = SoapMessageUtils.getMessage(pathBase);
    soapPart = soapMessage.getSOAPPart();
    soapEnvelope = soapPart.getEnvelope();
    soapHeader = soapEnvelope.getHeader();

    secElement = soapHeader.addHeaderElement(soapEnvelope.createName(
            "Security", "wsse",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"));
    binaryTokenElement = secElement.addChildElement(soapEnvelope.createName(
            "BinarySecurityToken", "wsse",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"));
    binaryTokenElement.setAttribute("EncodingType",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
    binaryTokenElement.setAttribute("ValueType",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3");

    return soapMessage;
}
 
Example #19
Source File: SAAJMessageHeaders.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Header get(String nsUri, String localName, boolean markAsUnderstood) {
    SOAPHeaderElement h = find(nsUri, localName);
    if (h != null) {
        if (markAsUnderstood) {
            understood(nsUri, localName);
        }
        return new SAAJHeader(h);
    }
    return null;
}
 
Example #20
Source File: SAAJMessageHeaders.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<Header> asList() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return Collections.emptyList();
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    List<Header> headers = new ArrayList<Header>();
    while (allHeaders.hasNext()) {
        SOAPHeaderElement nextHdr = (SOAPHeaderElement) allHeaders.next();
        headers.add(new SAAJHeader(nextHdr));
    }
    return headers;
}
 
Example #21
Source File: HeaderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SOAPHeaderElement addUpgradeHeaderElement(String[] supportedSoapUris)
    throws SOAPException {

    if (supportedSoapUris == null) {
        log.severe("SAAJ0411.ver1_2.no.null.supportedURIs");
        throw new SOAPException("Argument cannot be null; array of supportedURIs cannot be null");
    }
    if (supportedSoapUris.length == 0) {
        log.severe("SAAJ0412.ver1_2.no.empty.list.of.supportedURIs");
        throw new SOAPException("List of supported URIs cannot be empty");
    }
    Name upgradeName = getUpgradeName();
    SOAPHeaderElement upgradeHeaderElement =
        (SOAPHeaderElement) addChildElement(upgradeName);
    Name supportedEnvelopeName = getSupportedEnvelopeName();
    for (int i = 0; i < supportedSoapUris.length; i ++) {
        SOAPElement subElement =
            upgradeHeaderElement.addChildElement(supportedEnvelopeName);
        String ns = "ns" + Integer.toString(i);
        subElement.addAttribute(
            NameImpl.createFromUnqualifiedName("qname"),
            ns + ":Envelope");
        subElement.addNamespaceDeclaration(ns, supportedSoapUris[i]);
    }
    return upgradeHeaderElement;
}
 
Example #22
Source File: SAAJMessageHeaders.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Header get(String nsUri, String localName, boolean markAsUnderstood) {
    SOAPHeaderElement h = find(nsUri, localName);
    if (h != null) {
        if (markAsUnderstood) {
            understood(nsUri, localName);
        }
        return new SAAJHeader(h);
    }
    return null;
}
 
Example #23
Source File: SAAJMessageHeaders.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private SOAPHeaderElement find(String nsUri, String localName) {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return null;
    }
    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    while(allHeaders.hasNext()) {
        SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next();
        if (nextHdrElem.getNamespaceURI().equals(nsUri) &&
                nextHdrElem.getLocalName().equals(localName)) {
            return nextHdrElem;
        }
    }
    return null;
}
 
Example #24
Source File: StringHeader.java    From openjdk-8-source with 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();
    SOAPHeaderElement she = header.addHeaderElement(name);
    if(mustUnderstand) {
        she.setMustUnderstand(true);
    }
    she.addTextNode(value);
}
 
Example #25
Source File: SAAJMessageHeaders.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<Header> asList() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return Collections.emptyList();
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    List<Header> headers = new ArrayList<Header>();
    while (allHeaders.hasNext()) {
        SOAPHeaderElement nextHdr = (SOAPHeaderElement) allHeaders.next();
        headers.add(new SAAJHeader(nextHdr));
    }
    return headers;
}
 
Example #26
Source File: AbstractSoapDecoder.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Deprecated
protected List<SoapHeader> getSoapHeader(SOAPHeader soapHeader) {
    Map<String, List<SOAPHeaderElement>> headersByNamespace = new HashMap<>();
    Iterator<?> headerElements = soapHeader.extractAllHeaderElements();
    while (headerElements.hasNext()) {
        SOAPHeaderElement element = (SOAPHeaderElement) headerElements.next();
        headersByNamespace.computeIfAbsent(element.getNamespaceURI(), Functions.forSupplier(LinkedList::new))
                .add(element);
    }
    List<SoapHeader> soapHeaders = Lists.newArrayList();
    for (Entry<String, List<SOAPHeaderElement>> key : headersByNamespace.entrySet()) {
        String namespace = key.getKey();
        try {
            Decoder<?, List<SOAPHeaderElement>> decoder =
                    getDecoder(new XmlNamespaceDecoderKey(namespace, SOAPHeaderElement.class));
            if (decoder != null) {
                Object object = decoder.decode(headersByNamespace.get(namespace));
                if (object instanceof SoapHeader) {
                    soapHeaders.add((SoapHeader) object);
                } else if (object instanceof List<?>) {
                    for (Object o : (List<?>) object) {
                        if (o instanceof SoapHeader) {
                            soapHeaders.add((SoapHeader) o);
                        }
                    }
                }
            } else {
                LOGGER.warn("The SOAP-Header elements for namespace '{}' are not supported by this server!",
                        namespace);
            }
        } catch (DecodingException owse) {
            LOGGER.debug("Requested SOAPHeader element is not supported", owse);
        }
    }
    return soapHeaders;
}
 
Example #27
Source File: StringHeader.java    From openjdk-jdk8u-backup with 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();
    SOAPHeaderElement she = header.addHeaderElement(name);
    if(mustUnderstand) {
        she.setMustUnderstand(true);
    }
    she.addTextNode(value);
}
 
Example #28
Source File: Soap.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public SOAPHeaderElement addHeader(String name, String prefix) {
    try {
        return this.envelope.getHeader().addHeaderElement(envelope.createQName(name, prefix));
    } catch (SOAPException e) {
        throw new RuntimeException("Could not add SOAP Header.", e);
    }
}
 
Example #29
Source File: SAAJMessageHeaders.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void advance() {
    while (soapHeaders.hasNext()) {
        SOAPHeaderElement nextHdr = (SOAPHeaderElement) soapHeaders.next();
        if (nextHdr != null &&
                (myNsUri == null || nextHdr.getNamespaceURI().equals(myNsUri)) &&
                (myLocalName == null || nextHdr.getLocalName().equals(myLocalName))) {
                current = nextHdr;
                //found it
                return;
            }
        }
    //if we got here we didn't find a match
    current = null;
}
 
Example #30
Source File: SAAJMessageHeaders.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Iterator<Header> getHeaders(final String nsUri, final String localName,
        final boolean markAsUnderstood) {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return null;
    }
    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    if (markAsUnderstood) {
        //mark all the matchingheaders as understood up front
        //make an iterator while we're doing that
        List<Header> headers = new ArrayList<Header>();
        while (allHeaders.hasNext()) {
            SOAPHeaderElement nextHdr = (SOAPHeaderElement) allHeaders.next();
            if (nextHdr != null &&
                    nextHdr.getNamespaceURI().equals(nsUri)) {
                if (localName == null ||
                        nextHdr.getLocalName().equals(localName)) {
                    understood(nextHdr.getNamespaceURI(), nextHdr.getLocalName());
                    headers.add(new SAAJHeader(nextHdr));
                }
            }
        }
        return headers.iterator();
    }
    //if we got here markAsUnderstood is false - return a lazy iterator rather
    //than traverse the entire list of headers now
    return new HeaderReadIterator(allHeaders, nsUri, localName);
}