Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. public class SecurityHeader implements WebServiceMessageCallback{
  2.  
  3. @Override
  4. public void doWithMessage(WebServiceMessage wsMessage) throws IOException, TransformerException {
  5. SOAPMessage soapMessage = ((SaajSoapMessage)wsMessage).getSaajMessage();
  6.  
  7. SOAPHeader header;
  8. SOAPHeaderElement security;
  9. SOAPHeaderElement usertoken;
  10. SOAPElement username;
  11. SOAPElement password;
  12.  
  13. try {
  14. header = soapMessage.getSOAPHeader();
  15. //header.addNamespaceDeclaration("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
  16. //header.addNamespaceDeclaration("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
  17. security = header.addHeaderElement(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", "wsse"));
  18. usertoken = header.addHeaderElement(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "UsernameToken", "wsu"));
  19.  
  20. username = usertoken.addChildElement("Username", "wsse");
  21. password = usertoken.addChildElement("Password", "wsse");
  22. password.setAttribute("Type","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
  23.  
  24. username.setTextContent("eppa2SAP_app");
  25. password.setTextContent("eppa2SAP_app123");
  26.  
  27. security.addChildElement(username);
  28. security.addChildElement(password);
  29. security.addChildElement(usertoken);
  30.  
  31. JAXBContext context = JAXBContext.newInstance();
  32.  
  33. Marshaller marshaller = context.createMarshaller();
  34. marshaller.marshal(null, ((SoapHeader) soapMessage).getResult());
  35.  
  36. } catch (JAXBException e) {
  37. throw new IOException("error while marshalling authentication JAXB.");
  38. } catch (MarshallingException e) {
  39. throw new IOException("error while marshalling authentication exception.");
  40. } catch (SOAPException e1) {
  41. // TODO Auto-generated catch block
  42. e1.printStackTrace();
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement