Results 1 to 2 of 2

Thread: Security header not found:How to write an Axis Client for Spring WS

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Location
    hyderabad,India
    Posts
    3

    Default Security header not found:How to write an Axis Client for Spring WS

    Hi,

    I need some help/guidance in setting the security headers from an axis client.
    (that consumes spring-web service).

    I have written a client program, when i run it I get a server side error saying security header not found.

    (I'm using wss4j Security interceptor and wss4j.callback.SimplePasswordValidationCallbackHan dler)

    From some other forum I got the following way of setting security header in clinet (which is not working with me )


    Code:
    MyService ser = new MyServiceServiceLocator()
    					.getMyServiceSoap11();
    			
    
    			org.apache.axis.client.Stub stub = (org.apache.axis.client.Stub) ser;
    
    			
    			
    			
    			PrefixedQName name = new PrefixedQName(
    					"http://schemas.xmlsoap.org/ws/2002/07/secext", "Security",
    					"wsse");
    
    			System.out.println("Setting headers for authentication");
    
    			org.apache.axis.message.SOAPHeaderElement sh = new org.apache.axis.message.SOAPHeaderElement(
    					name);
    
    			SOAPElement sub = sh.addChildElement("UserNameToken");
    
    			SOAPElement UNElement = sub.addChildElement("Username");
    
    			String clntUserName = "name";
    			String clntPassword="myPassword";
    			
    			UNElement.addTextNode(clntUserName);
    			stub.setHeader(sh);
    
    			SOAPElement PwdElement = sub.addChildElement("Password");
    			PwdElement.addTextNode(clntPassword);


    I have posted SOAP request and obtained proper reponse using soapUI,

    but the client written (that includes above snippet) causes server to give no security header found error.


    Please give me some guidance on writing a proper client
    Thanks in advance,
    -K_aravind

  2. #2
    Join Date
    Dec 2009
    Location
    hyderabad,India
    Posts
    3

    Unhappy Sorry, my Mistake!

    Hi all,

    I'm extremely sorry for doing this...
    The code I've posted is allright except that I was adding the password node at the wrong place.

    Code:
    //This is the wrong code
    SOAPElement sub = sh.addChildElement("UserNameToken");
    
    			SOAPElement UNElement = sub.addChildElement("Username");
    
    			String clntUserName = "name";
    			String clntPassword="myPassword";
    			
    			UNElement.addTextNode(clntUserName);
    			stub.setHeader(sh);
    //No password added into header 
    			SOAPElement PwdElement = sub.addChildElement("Password");
    			PwdElement.addTextNode(clntPassword);

    Code:
    //The right code is:
    SOAPElement sub = sh.addChildElement("UserNameToken");
    
    			SOAPElement UNElement = sub.addChildElement("Username");
    
    			String clntUserName = "name";
    			String clntPassword="myPassword";
    			
    			UNElement.addTextNode(clntUserName);
    
    SOAPElement PwdElement = sub.addChildElement("Password");
    			PwdElement.addTextNode(clntPassword);
    
    			stub.setHeader(sh);


    My program is working fine now...

    Thanks and apologies to all who took time to look at my code

    -K_aravind

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •