【问题标题】:adding authentification header to client stub axis2将身份验证标头添加到客户端存根axis2
【发布时间】:2012-10-21 11:19:11
【问题描述】:

我基于 xmlbeans 构建了 wsdl-client-stub。现在,由于 xmlbeans 存根缺少必要的类(?)

,我无法使用 xmlbeans 添加自定义标头进行身份验证

其实标题应该是这样的:

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

所以我尝试在存根和 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 引发错误说: OMFactory 类型中的方法 createOMElement(String, OMNamespace) 不适用于参数 (QName, null) - 构造函数 QName(String, String, String) 未定义

有没有人有提示,我应该解决什么,才能让它工作。 非常感谢您的帮助,

亚历克斯

【问题讨论】:

    标签: axis2 soap-client stub soapheader


    【解决方案1】:
    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);
    

    【讨论】:

    • 我在用 axis2 1.6.3 new SOAP11HeaderBlockImpl("Security", SecurityElementNamespace, factory); 实例化 SOAP11HeaderBlockImpl 时遇到问题;它要求另一个参数 OMDataSource 我该如何解决?
    猜你喜欢
    • 2011-08-17
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-22
    • 2023-03-24
    • 2014-06-02
    相关资源
    最近更新 更多