adding authentification header to client stub axis2
Asked Answered
S

1

1

I built the wsdl-client-stub based on xmlbeans. Now I got stuck adding a custom header for authentification using xmlbeans since xmlbeans stubs are lacking the necessary Classes(?)

Actually, the header should look like:

<SOAP-ENV:Header> 
        <ns2:verifyingToken> 
            <UserID>9</UserID>
            <Token>29438094lkjslfkjlsdkjf</Token>
        </ns2:verifyingToken>
     </SOAP-ENV:Header>

So I tried as fallback going in between stub and ServiceClient:

ServiceClient sc = stub._getServiceClient();

OMFactory  omFactory     = OMAbstractFactory.getOMFactory();
        OMElement  omElement     = omFactory.createOMElement(new QName("SOAP-ENV", "Header", "ver"), null);
        OMElement  omElementVeri = omFactory.createOMElement(new QName("", "verifyingToken", ""), omElement);
        OMElement  omElementUser = omFactory.createOMElement(new QName("", "UserID", ""), omElementVeri);
                   omElementUser.setText(""+userid);

        OMElement  omElementPass   =   omFactory.createOMElement(new QName("", "Token", ""), omElementVeri);
                   omElementPass.setText(""+token);
        sc.addHeader(omElement);

eclipse is raising errors saying: The method createOMElement(String, OMNamespace) in the type OMFactory is not applicable for the arguments (QName, null) - The constructor QName(String, String, String) is undefined

Does anyone has a hint, what I should fix, to get this to work. I really appreciate your help,

Alex

Sheng answered 21/10, 2012 at 11:19 Comment(0)
M
6
ServiceClient client = stub._getServiceClient();
SOAP11Factory factory = new SOAP11Factory();
OMNamespace SecurityElementNamespace = factory.createOMNamespace("http://schemas.xmlsoap.org/ws/2002/12/secext", "wss");
OMElement usernameTokenEl = factory.createOMElement("UsernameToken", SecurityElementNamespace);

OMElement usernameEl = factory.createOMElement("Username", SecurityElementNamespace);
usernameEl.setText("123");
usernameTokenEl.addChild(usernameEl);

OMElement passwordEl = factory.createOMElement("Password", SecurityElementNamespace);
passwordEl.setText("123");
usernameTokenEl.addChild(passwordEl);

SOAPHeaderBlockImpl block = new SOAP11HeaderBlockImpl("Security", SecurityElementNamespace, factory);
block.addChild(usernameTokenEl);

client.addHeader(block);
Multipara answered 30/11, 2012 at 4:9 Comment(1)
I'm having troubles instantiating SOAP11HeaderBlockImpl with axis2 1.6.3 new SOAP11HeaderBlockImpl("Security", SecurityElementNamespace, factory); It ask for another parameter an OMDataSource how can I fix it?Martimartial

© 2022 - 2024 — McMap. All rights reserved.