简体   繁体   English

WEBService调用的HTTP基本身份验证

[英]HTTP Basic Authentication for WEBService call

I trying to invoke a web service, which has an Basic HTTP Authentication. 我试图调用具有基本HTTP身份验证的Web服务。 I generated the client code using the WSDL2JAVA tool from AXIS. 我使用AXIS的WSDL2JAVA工具生成了客户端代码。

But I am not able to set the username and password to the webservice call. 但是我无法将用户名和密码设置为webservice调用。

I tried to have them in the endpoint url as 我试图将它们包含在端点URL中

http://username:password@somwserver/wsdl HTTP://用户名:密码@ somwserver / WSDL

But I am getting the unauthorized error for this. 但是我得到了未经授权的错误。 I am trying to figure out a way to get this set to my call in the Java code.... 我试图找出一种方法来将此设置用Java代码调用。

Note : I am able to invoke the same service via the soapUI and get the results. 注意:我能够通过soapUI调用相同的服务并获得结果。 I provided the username and password in the "Aut" tab on the request. 我在请求的“自动”标签中提供了用户名和密码。

Here is some of the code snippets of my Stub, if this is userful for you 这是我的存根的一些代码片段,如果这对您有用的话

       _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);

Any inputs will be greatly appreciated!! 任何输入将不胜感激!

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

 _serviceClient.getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.BASIC_AUTHENTICATE,auth);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM