Advertisement
Guest User

Untitled

a guest
Feb 5th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. <wsdl:Envelope xmlns:soap="..."
  2. xmlns:wsse="..." >
  3. <wsdl:Header>
  4. <wsse:Security>
  5. <wsse:UsernameToken>
  6. <wsse:Username>admin</wsse:Username>
  7. <wsse:Password>password</wsse:Password>
  8. </wsse:UsernameToken>
  9. </wsse:Security>
  10. </wsdl:Header>
  11. </wsdl:Envelope>
  12.  
  13. //create SOAP
  14. SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
  15. SOAPConnection connection = sfc.createConnection();
  16.  
  17. SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
  18. SOAPPart soapPart = soapMessage.getSOAPPart();
  19. SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
  20.  
  21. SOAPBody soapBody = soapEnvelope.getBody();
  22. SOAPElement Header = soapBody.addBodyElement(new QName("Header"));
  23.  
  24. //attribute
  25. SOAPElement Security= Header.addChildElement(new QName("Security"));
  26. SOAPElement UsernameToken= Security.addChildElement(new QName("UsernameToken"));
  27. SOAPElement Username= UsernameToken.addChildElement(new QName("Username"));
  28. SOAPElement Password= UsernameToken.addChildElement(new QName("Password"));
  29.  
  30. //enter the username and password
  31. Username.addTextNode("username");
  32. Password.addTextNode("password");
  33.  
  34. //send the soap and print out the result
  35. URL endpoint = "http://localhost:8080/soap/getMessage?wsdl";
  36. SOAPMessage response = connection.call(soapMessage, endpoint);
  37.  
  38.  
  39. ByteArrayOutputStream out = new ByteArrayOutputStream();
  40. String xml = "";
  41. try {
  42. response.writeTo(out);
  43. xml = out.toString("UTF-8");
  44. } catch (Exception e)
  45. {
  46. System.out.println(""+e);
  47. //log.error(e.getMessage(),e);
  48. }
  49.  
  50. System.out.println(""+xml);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement