WEB服务调用的HTTP基本认证

时间:2010-08-27 22:31:25

标签: java axis2 basic-authentication webservice-client

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

但我无法为webservice调用设置用户名和密码。

我尝试将它们作为

放在端点网址中
  

http://username:password@somwserver/wsdl

但是我收到了未经授权的错误。我试图想出一种方法来将这个集合用于我的Java代码调用....

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

以下是我的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);

任何输入都将非常感谢!!

1 个答案:

答案 0 :(得分: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);
相关问题