Adding Authentication elements to Soap Header

diegoslayer31

New Member
I am trying to add authentication related details in Soap Header. It should look something like this:\[code\] <soapenv:Header><authenticationInfo> <userId>?</userId> <password>?</password></authenticationInfo>\[/code\]For achieveing this, i got to know that i need to implement the interface SOAPHandler. Also i got this bit of code by google search. This method is present in MyHandler class which implements SOAPHandler interface:\[code\] public boolean handleMessage(javax.xml.ws.handler.soap.SOAPMessageContext context) { try { SOAPMessage message = context.getMessage(); javax.xml.soap.SOAPHeader header = message.getSOAPHeader(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); if (header == null) { header = envelope.addHeader(); } QName qNameUserCredentials = new QName("https://your.target.namespace/", "UserCredentials"); SOAPHeaderElement userCredentials = header.addHeaderElement(qNameUserCredentials); QName qNameUsername = new QName("https://your.target.namespace/", "Username"); SOAPHeaderElement username = header.addHeaderElement(qNameUsername ); username.addTextNode(this.username); QName qNamePassword = new QName("https://your.target.namespace/", "Password"); SOAPHeaderElement password = header.addHeaderElement(qNamePassword); password.addTextNode(this.password); userCredentials.addChildElement(username); userCredentials.addChildElement(password); message.saveChanges(); } catch (Exception e) { // TODO } return true;}\[/code\]But i am not able to understand how and where to use this MyHandler class which implements the SOAPHandler interface. I have got a service class which contains all the methods signature which will be exposed to the web service clients. All these information will be present in the SOAP Body part. Internally, these service will invoke the handlers to perform the Business Logic. I want to know:Where and how to invoke this MyHandler class which implements the SOAPHandler for adding the SOAP Header elements?Please help me out on this.
 
Back
Top