Java Code Examples for javax.xml.soap.SOAPElement#setAttribute()

The following examples show how to use javax.xml.soap.SOAPElement#setAttribute() . 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: SOAP.java    From onvif-java-lib with Apache License 2.0 6 votes vote down vote up
protected void createSoapHeader(SOAPMessage soapMessage) throws SOAPException {
	onvifDevice.createNonce();
	String encrypedPassword = onvifDevice.getEncryptedPassword();
	if (encrypedPassword != null && onvifDevice.getUsername() != null) {

		SOAPPart sp = soapMessage.getSOAPPart();
		SOAPEnvelope se = sp.getEnvelope();
		SOAPHeader header = soapMessage.getSOAPHeader();
		se.addNamespaceDeclaration("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
		se.addNamespaceDeclaration("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");

		SOAPElement securityElem = header.addChildElement("Security", "wsse");
		// securityElem.setAttribute("SOAP-ENV:mustUnderstand", "1");

		SOAPElement usernameTokenElem = securityElem.addChildElement("UsernameToken", "wsse");

		SOAPElement usernameElem = usernameTokenElem.addChildElement("Username", "wsse");
		usernameElem.setTextContent(onvifDevice.getUsername());

		SOAPElement passwordElem = usernameTokenElem.addChildElement("Password", "wsse");
		passwordElem.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
		passwordElem.setTextContent(encrypedPassword);

		SOAPElement nonceElem = usernameTokenElem.addChildElement("Nonce", "wsse");
		nonceElem.setAttribute("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
		nonceElem.setTextContent(onvifDevice.getEncryptedNonce());

		SOAPElement createdElem = usernameTokenElem.addChildElement("Created", "wsu");
		createdElem.setTextContent(onvifDevice.getLastUTCTime());
	}
}
 
Example 2
Source File: MUTube.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
    for (QName qname : notUnderstoodHeaders) {
        SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
        soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
        soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
        Header header = new DOMHeader<Element>(soapEl);
        m.getHeaders().add(header);
    }
}
 
Example 3
Source File: MUTube.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
    for (QName qname : notUnderstoodHeaders) {
        SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
        soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
        soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
        Header header = new DOMHeader<Element>(soapEl);
        m.getHeaders().add(header);
    }
}
 
Example 4
Source File: MUTube.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
    for (QName qname : notUnderstoodHeaders) {
        SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
        soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
        soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
        Header header = new DOMHeader<Element>(soapEl);
        m.getHeaders().add(header);
    }
}
 
Example 5
Source File: MUTube.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
    for (QName qname : notUnderstoodHeaders) {
        SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
        soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
        soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
        Header header = new DOMHeader<Element>(soapEl);
        m.getHeaders().add(header);
    }
}
 
Example 6
Source File: MUTube.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
    for (QName qname : notUnderstoodHeaders) {
        SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
        soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
        soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
        Header header = new DOMHeader<Element>(soapEl);
        m.getHeaders().add(header);
    }
}
 
Example 7
Source File: MUTube.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
    for (QName qname : notUnderstoodHeaders) {
        SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
        soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
        soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
        Header header = new DOMHeader<Element>(soapEl);
        m.getHeaders().add(header);
    }
}
 
Example 8
Source File: MUTube.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
    for (QName qname : notUnderstoodHeaders) {
        SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
        soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
        soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
        Header header = new DOMHeader<Element>(soapEl);
        m.getHeaders().add(header);
    }
}
 
Example 9
Source File: MUTube.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
    for (QName qname : notUnderstoodHeaders) {
        SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
        soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
        soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
        Header header = new DOMHeader<Element>(soapEl);
        m.getHeaders().add(header);
    }
}
 
Example 10
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 11
Source File: AarXTeeConsumerCallback.java    From j-road with Apache License 2.0 5 votes vote down vote up
private void addType(SOAPElement ele) {
	if (eleAttrs.containsKey(ele.getElementName().getLocalName())) {
		Attribute attr = eleAttrs.get(ele.getElementName().getLocalName());
		ele.setAttribute(attr.getAttrName(), attr.getAttrValue());
	}
	java.util.Iterator eleChilds = ele.getChildElements();
	while (eleChilds.hasNext()) {
		Object nextEle = eleChilds.next();
		if (nextEle instanceof SOAPElement) {
			addType((SOAPElement) nextEle);
		}
	}
}
 
Example 12
Source File: SOAPRequestBuilder.java    From cougar with Apache License 2.0 5 votes vote down vote up
public void iterate(SOAPEnvelope envelope, Node node,
		SOAPElement parentElement) throws SOAPException {

	// if the node is an element then process it and it's children
	if(node instanceof Element){
		
			Element elemt = (Element) node;
			String localName = elemt.getNodeName();
			SOAPElement newParent = parentElement.addChildElement(localName,"bas", nameSpace);
			
			// If the node has attributes then process them
			if(node.hasAttributes()){
				AttributeMap map = (AttributeMap) node.getAttributes();
				for (int x = 0; x < map.getLength(); x++) {
					String name = map.item(x).getNodeName();
					newParent.setAttribute(name, map.item(x).getNodeValue());
				}
			}
			
			org.w3c.dom.NodeList childNodes = node.getChildNodes();
			// for each of this nodes children recursively call this method
			for (int i = 0; i < childNodes.getLength(); i++) {
				iterate(envelope, childNodes.item(i), newParent);
			}
			
	} else if (node.getNodeType() == Node.TEXT_NODE){ // Node is a text node so add it's value
		String value = node.getNodeValue();
		if (value==null) {
			parentElement.addTextNode("");
		} else {
			parentElement.addTextNode(value);
		}
	}
	// Else is some other kind of node which can be ignored
}
 
Example 13
Source File: SimpleSecurityHandler.java    From onvif with Apache License 2.0 4 votes vote down vote up
@Override
public boolean handleMessage(final SOAPMessageContext msgCtx) {
  // System.out.println("SimpleSecurityHandler");

  // Indicator telling us which direction this message is going in
  final Boolean outInd = (Boolean) msgCtx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

  // Handler must only add security headers to outbound messages
  if (outInd.booleanValue()) {
    try {
      // Create the xml
      SOAPMessage soapMessage = msgCtx.getMessage();
      SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
      SOAPHeader header = envelope.getHeader();
      if (header == null) header = envelope.addHeader();

      SOAPPart sp = soapMessage.getSOAPPart();
      SOAPEnvelope se = sp.getEnvelope();
      se.addNamespaceDeclaration(WSSE_PREFIX, WSSE_NS);
      se.addNamespaceDeclaration(WSU_PREFIX, WSU_NS);

      SOAPElement securityElem = header.addChildElement(WSSE_LN, WSSE_PREFIX);
      // securityElem.setAttribute("SOAP-ENV:mustUnderstand", "1");

      SOAPElement usernameTokenElem =
          securityElem.addChildElement(USERNAME_TOKEN_LN, WSSE_PREFIX);

      SOAPElement usernameElem = usernameTokenElem.addChildElement(USERNAME_LN, WSSE_PREFIX);
      usernameElem.setTextContent(username);

      SOAPElement passwordElem = usernameTokenElem.addChildElement(PASSWORD_LN, WSSE_PREFIX);
      passwordElem.setAttribute(PASSWORD_TYPE_ATTR, PASSWORD_DIGEST);
      passwordElem.setTextContent(encryptPassword(password));

      SOAPElement nonceElem = usernameTokenElem.addChildElement(NONCE_LN, WSSE_PREFIX);
      nonceElem.setAttribute("EncodingType", BASE64_ENCODING);
      nonceElem.setTextContent(Base64.encodeBase64String(nonce.getBytes()));

      SOAPElement createdElem = usernameTokenElem.addChildElement(CREATED_LN, WSU_PREFIX);
      createdElem.setTextContent(getLastUTCTime());
    } catch (final Exception e) {
      e.printStackTrace();
      return false;
    }
  }
  return true;
}