Web services Axis2 Adb客户端基于https的基本身份验证安全url

Web services Axis2 Adb客户端基于https的基本身份验证安全url,web-services,https,client,axis2,axis,Web Services,Https,Client,Axis2,Axis,我在Stackoverflow上仔细研究了这个问题,发现了一些类似的问题,但没有一个解决了我的问题。我已汇编了所有“建议”解决方案,但没有任何效果:-( 我有一个wsdl,我使用adb客户机(Axis 2)生成了客户机代码。wsdl说明此请求将通过Https url发送。我能够使用wsdl到java成功创建存根。但是我不确定如何进行基本身份验证。告诉我详细信息的文档还说明,我的用户名和pwd应使用Base64编码 使用的身份验证方法是HTTP Basic。用户名和 密码需要以base64格式编码

我在Stackoverflow上仔细研究了这个问题,发现了一些类似的问题,但没有一个解决了我的问题。我已汇编了所有“建议”解决方案,但没有任何效果:-( 我有一个wsdl,我使用adb客户机(Axis 2)生成了客户机代码。wsdl说明此请求将通过Https url发送。我能够使用wsdl到java成功创建存根。但是我不确定如何进行基本身份验证。告诉我详细信息的文档还说明,我的用户名和pwd应使用Base64编码

使用的身份验证方法是HTTP Basic。用户名和 密码需要以base64格式编码–UTF8字符 设定

示例:Username:Password=“VXNlcm5hbWU6UGFzc3dvcmQ=”

顺便说一句,我已经在soapui中尝试了这个wsdl,并且得到了正确的响应,但是我的java代码无法正常工作

现在是wsdl

<?xml version="1.0" encoding="UTF-8"?>
<definitions targetNamespace="urn:OTSB2B" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:OTSB2B" xmlns:intf="urn:OTSB2B" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:types>
        <schema targetNamespace="urn:OTSB2B" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:urn="urn:OTSB2B">
            <simpleType name="tn">
                <restriction base="string">
                    <length value="10"/>
                </restriction>
            </simpleType>
            <simpleType name="prov">
                <restriction base="string">
                    <length value="2"/>
                    <enumeration value="on"/>
                    <enumeration value="qc"/>
                </restriction>
            </simpleType>
            <element name="getPresaleByTN">
                <complexType>
                    <sequence>
                        <element name="tn" type="urn:tn"/>
                        <element name="prov" type="urn:prov"/>
                    </sequence>
                </complexType>
            </element>
            <element name="getPresaleByTNReturn" type="xsd:string"/>
            <element name="isAlive"/>
            <element name="isAliveReturn" type="xsd:boolean"/>
        </schema>
    </wsdl:types>
    <message name="isAliveRequest">
        <part element="impl:isAlive" name="isAlive"/>
    </message>
    <message name="getPresaleByTNRequest">
        <part element="impl:getPresaleByTN" name="getPresaleByTN"/>
    </message>
    <message name="isAliveResponse">
        <part element="impl:isAliveReturn" name="isAliveReturn"/>
    </message>
    <message name="getPresaleByTNResponse">
        <part element="impl:getPresaleByTNReturn" name="getPresaleByTNReturn"/>
    </message>
    <portType name="GetPresaleByTN">
        <operation name="getPresaleByTN">
            <input message="impl:getPresaleByTNRequest" name="getPresaleByTNRequest"/>
            <output message="impl:getPresaleByTNResponse" name="getPresaleByTNResponse"/>
        </operation>
        <operation name="isAlive">
            <input message="impl:isAliveRequest" name="isAliveRequest"/>
            <output message="impl:isAliveResponse" name="isAliveResponse"/>
        </operation>
    </portType>
    <binding name="DominoSoapBinding" type="impl:GetPresaleByTN">
        <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="getPresaleByTN">
            <wsdlsoap:operation soapAction=""/>
            <input name="getPresaleByTNRequest">
                <wsdlsoap:body use="literal"/>
            </input>
            <output name="getPresaleByTNResponse">
                <wsdlsoap:body use="literal"/>
            </output>
        </operation>
        <operation name="isAlive">
            <wsdlsoap:operation soapAction=""/>
            <input name="isAliveRequest">
                <wsdlsoap:body use="literal"/>
            </input>
            <output name="isAliveResponse">
                <wsdlsoap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="GetPresaleByTNService">
        <port binding="impl:DominoSoapBinding" name="Domino">
            <wsdlsoap:address location="https://b2b.ivv.bell.ca/ots-qualification-service-tn"/>
        </port>
    </service>
</definitions>
这给了我以下错误:

org.apache.axis2.AxisFault:无法添加字符串头,您必须 将QName的namespaceURI设置为 org.apache.axis2.client.ServiceClient.addStringHeader(ServiceClient.java:434) 位于com.dinesh.bellAxis.App.main(App.java:30)

然后我试了这个

GetPresaleByTNServiceStub stub = new GetPresaleByTNServiceStub();
            ServiceClient client = stub._getServiceClient();

            HttpTransportProperties.Authenticator basicAuth = new HttpTransportProperties.Authenticator();
            basicAuth.setUsername("XXX");
            basicAuth.setPassword("CCCCC");
            basicAuth.setPreemptiveAuthentication(true);

            stub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, basicAuth);

            GetPresaleByTNServiceStub.GetPresaleByTN request = new GetPresaleByTN();
            Tn tn = new Tn();
            tn.setTn("4164390001");
            request.setTn(tn);
            request.setProv(Prov.on);

            GetPresaleByTNReturn response = stub.getPresaleByTN(request);
            System.out.println(response.getGetPresaleByTNReturn());
这给了我以下错误:

org.apache.axis2.AxisFault:传输级别信息不匹配 SOAP消息命名空间URI位于 org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)位于 org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:90) 在 org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:353) 在 org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416) 在 org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228) 在 org.apache.axis2.client.OperationClient.execute(OperationClient.java:163) 在 GetPresaleByTNServiceStub.getPresaleByTN(GetPresaleByTNServiceStub.java:460)

接下来我尝试了这个:我认为这是不正确的,因为它是WS-Security,而不是基本身份验证,但我用尽了所有的选项

GetPresaleByTNServiceStub stub = new GetPresaleByTNServiceStub();
            ServiceClient client = stub._getServiceClient();

            OMFactory omFactory = OMAbstractFactory.getOMFactory();
            OMElement omSecurityElement = omFactory.createOMElement(new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", "wsse"), null);


            OMElement omusertoken = omFactory.createOMElement(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "UsernameToken", "wsu"), null);

            OMElement omuserName = omFactory.createOMElement(new QName("", "Username", "wsse"), null);
            omuserName.setText("XXXX");

            OMElement omPassword = omFactory.createOMElement(new QName("", "Password", "wsse"), null);
            omPassword.addAttribute("Type","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText",null );
            omPassword.setText("YYYYYYY");

            omusertoken.addChild(omuserName);
            omusertoken.addChild(omPassword);
            omSecurityElement.addChild(omusertoken);
            stub._getServiceClient().addHeader(omSecurityElement);

            GetPresaleByTNServiceStub.GetPresaleByTN request = new GetPresaleByTN();
            Tn tn = new Tn();
            tn.setTn("4164390001");
            request.setTn(tn);
            request.setProv(Prov.on);

            GetPresaleByTNReturn response = stub.getPresaleByTN(request);
            System.out.println(response.getGetPresaleByTNReturn());
这会产生以下错误:

线程“main”java.lang.IllegalArgumentException中的异常:无法 在以下位置创建带有空命名空间名称的前缀元素: org.apache.axiom.om.impl.llom.OMElementImpl.handleNamespace(OMElementImpl.java:186) 在 org.apache.axiom.om.impl.llom.OMElementImpl.(OMElementImpl.java:161) 在 org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory.createOMElement(OMLinkedListImplFactory.java:126) 位于com.dinesh.bellAxis.App2.main(App2.java:37)

我不知道下一步该做什么,我已经检查了ApacheAxis2上的所有文档,并在谷歌上搜索了所有地方,但可以让代码正常工作


任何建议

代码片段1和3都不起作用,因为它们试图创建一条对SOAP(片段1)或XML(片段3)无效的消息。无论如何,它们试图将SOAP头添加到消息中,这不是基本身份验证的目的


代码片段2看起来正确。从异常的堆栈跟踪(更准确地说是handleResponse方法的存在)您可以看到响应有问题。错误消息可能表明响应的内容类型与响应中实际使用的SOAP版本不匹配。这意味着服务有问题,而不是客户端有问题。

经过大量的尝试和错误并阅读了SAAj教程后,我找到了答案在甲骨文网站上

我可以用这个做基本的身份验证 String authorization=new sun.misc.BASE64Encoder().encode((“myUserName”+”:“+”myPassword”).getBytes(); headers.addHeader(“授权”、“基本”+授权)


这是完整的教程-

谢谢Andreas。如果该服务出现问题,那么它将无法与SOAP UI工具一起工作。我的第二个代码段使用的是HttpTransportProperties。Authenticator理论上是正确的,我过去尝试访问各种其他服务时没有遇到任何问题,但错误-传输级别信息与org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)上的SOAP消息命名空间URI不匹配建议我的SOAP是1.1,而服务接受1.2/2.0,我应该尝试将wsdl转换为2.0吗?您的参数是有缺陷的,因为它隐式地假设SOAPUI在响应的内容类型和SOAP命名空间之间执行与Axis2相同的一致性检查。有证据证明这一点吗?我在发送SOAP时也遇到了这个问题响应WCF服务和我获得的服务org.apache.axis2.AxisFault:未能添加字符串头,您必须为QName提供namespaceURI。任何可能解决此问题的工作都将不胜感激。
GetPresaleByTNServiceStub stub = new GetPresaleByTNServiceStub();
            ServiceClient client = stub._getServiceClient();

            OMFactory omFactory = OMAbstractFactory.getOMFactory();
            OMElement omSecurityElement = omFactory.createOMElement(new QName( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", "wsse"), null);


            OMElement omusertoken = omFactory.createOMElement(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "UsernameToken", "wsu"), null);

            OMElement omuserName = omFactory.createOMElement(new QName("", "Username", "wsse"), null);
            omuserName.setText("XXXX");

            OMElement omPassword = omFactory.createOMElement(new QName("", "Password", "wsse"), null);
            omPassword.addAttribute("Type","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText",null );
            omPassword.setText("YYYYYYY");

            omusertoken.addChild(omuserName);
            omusertoken.addChild(omPassword);
            omSecurityElement.addChild(omusertoken);
            stub._getServiceClient().addHeader(omSecurityElement);

            GetPresaleByTNServiceStub.GetPresaleByTN request = new GetPresaleByTN();
            Tn tn = new Tn();
            tn.setTn("4164390001");
            request.setTn(tn);
            request.setProv(Prov.on);

            GetPresaleByTNReturn response = stub.getPresaleByTN(request);
            System.out.println(response.getGetPresaleByTNReturn());