List of usage examples for javax.xml.soap SOAPElement addAttribute
public SOAPElement addAttribute(QName qname, String value) throws SOAPException;
From source file:ru.codeinside.gws.crypto.cryptopro.CryptoProvider.java
public void sign(final SOAPMessage message) { try {/*from ww w .j av a 2 s . c om*/ loadCertificate(); final long startMs = System.currentTimeMillis(); final SOAPPart doc = message.getSOAPPart(); final QName wsuId = doc.getEnvelope().createQName("Id", "wsu"); final SOAPHeader header = message.getSOAPHeader(); final QName actor = header.createQName("actor", header.getPrefix()); final SOAPElement security = header.addChildElement("Security", "wsse", WSSE); security.addAttribute(actor, ACTOR_SMEV); SOAPElement binarySecurityToken = security.addChildElement("BinarySecurityToken", "wsse"); binarySecurityToken.setAttribute("EncodingType", WSS_BASE64_BINARY); binarySecurityToken.setAttribute("ValueType", WSS_X509V3); binarySecurityToken.setValue(DatatypeConverter.printBase64Binary(cert.getEncoded())); binarySecurityToken.addAttribute(wsuId, "CertId"); XMLSignature signature = new XMLSignature(doc, "", XMLSignature.ALGO_ID_SIGNATURE_GOST_GOST3410_3411, Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); { Element element = signature.getElement(); Element keyInfo = doc.createElementNS(Constants.SignatureSpecNS, "KeyInfo"); Element securityTokenReference = doc.createElementNS(WSSE, "SecurityTokenReference"); Element reference = doc.createElementNS(WSSE, "Reference"); reference.setAttribute("URI", "#CertId"); reference.setAttribute("ValueType", WSS_X509V3); securityTokenReference.appendChild(reference); keyInfo.appendChild(securityTokenReference); element.appendChild(keyInfo); security.appendChild(element); } Transforms transforms = new Transforms(doc); transforms.addTransform(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); signature.addDocument("#body", transforms, MessageDigestAlgorithm.ALGO_ID_DIGEST_GOST3411); signature.sign(privateKey); if (log.isDebugEnabled()) { log.debug("SIGN: " + (System.currentTimeMillis() - startMs) + "ms"); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }