2

我试图调用具有基本 HTTP 身份验证的 Web 服务。我使用 AXIS 的 WSDL2JAVA 工具生成了客户端代码。

但我无法为 web 服务调用设置用户名和密码。

我试图将它们放在端点网址中

http://用户名:密码@somwserver/wsdl

但我收到了未经授权的错误。我正在尝试找出一种方法来将此设置为我在 Java 代码中的调用....

注意:我可以通过soapUI 调用相同的服务并获得结果。我在请求的“Aut”选项卡中提供了用户名和密码。

这是我的 Stub 的一些代码片段,如果这对您有用的话

       _serviceClient = new org.apache.axis2.client.ServiceClient(configurationContext,_service);


    _serviceClient.getOptions().setTo(new org.apache.axis2.addressing.EndpointReference(
            targetEndpoint));
    _serviceClient.getOptions().setUseSeparateListener(useSeparateListener);

        //adding SOAP soap_headers
     _serviceClient.addHeadersToEnvelope(env);
    // set the message context with that soap envelope
    _messageContext.setEnvelope(env);

    // add the message contxt to the operation client
    _operationClient.addMessageContext(_messageContext);

    //execute the operation client
    _operationClient.execute(true);

任何输入将不胜感激!

4

1 回答 1

6
 HttpTransportProperties.Authenticator
                       auth = new HttpTransportProperties.Authenticator();
            auth.setUsername("username");
            auth.setPassword("password");

 _serviceClient.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.BASIC_AUTHENTICATE,auth);
于 2010-08-29T03:26:35.277 回答