Advertisement
Guest User

Untitled

a guest
Sep 13th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. try{
  2. MessageFactory messageFactory = MessageFactory.newInstance();
  3. soapMessage = messageFactory.createMessage();
  4. SOAPPart soapPart = soapMessage.getSOAPPart();
  5. SOAPEnvelope envelope = soapPart.getEnvelope();
  6.  
  7. SOAPHeader soapHeader = soapMessage.getSOAPHeader();
  8. System.out.println("****: "+soapHeader);
  9. //if no header, add one
  10. if (soapHeader == null){
  11. System.out.println("in if");
  12. soapHeader = envelope.getHeader();
  13. }
  14. Name qname = envelope.createName("Security", "wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
  15. SOAPHeaderElement security = soapHeader.addHeaderElement(qname);
  16.  
  17. security.addAttribute(new QName("xmlns:wsu"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
  18. // SOAPElement security = soapHeader.addChildElement("Security", "wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
  19. security.setMustUnderstand(true);
  20. SOAPElement usernameToken = security.addChildElement("UsernameToken", "wsse");
  21.  
  22. usernameToken.setAttribute("wsu:Id","UsernameToken-123" );
  23.  
  24. SOAPElement username = usernameToken.addChildElement("Username", "wsse");
  25. username.addTextNode("*****");
  26.  
  27. SOAPElement password = usernameToken.addChildElement("Password", "wsse");
  28. password.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
  29. password.addTextNode("****");
  30.  
  31. SOAPElement nonce = usernameToken.addChildElement("Nonce", "wsse");
  32. nonce.setAttribute("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
  33. nonce.setValue("8nfdG22JxQVy+Yfndty9Yw==");
  34.  
  35. SOAPElement created = usernameToken.addChildElement("Created", "wsse");
  36. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  37. Calendar c1 = Calendar.getInstance();
  38. created.setValue("2016-09-12T11:27:13.615Z");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement