访问带用户名和密码的webservice(基于HTTP Basic Authentication的认证)

axis2 1.7生成的客户端:找到可以插入如下代码的地方

import org.apache.axis2.transport.http.HTTPConstants;

import org.apache.axis2.transport.http.HttpTransportProperties;

import org.apache.axis2.transport.http.impl.httpclient4.HttpTransportPropertiesImpl;

            org.apache.axis2.client.OperationClient _operationClient = _serviceClient.createClient(_operations[0].getName());
            Options ops = _operationClient.getOptions();
            HttpTransportPropertiesImpl.Authenticator auth=new HttpTransportPropertiesImpl.Authenticator() ;
            auth.setPassword("username");
            auth.setUsername("password");
            ops.setProperty(HTTPConstants.AUTHENTICATE, auth);

 

JaxWS RI 2.2.10生成的客户端:ZMMQYZXKSPP_Service是指接口入口类,ZMMQYZXKSPP是指代理接口。 

ZMMQYZXKSPP_Service s=new ZMMQYZXKSPP_Service();
    	ZMMQYZXKSPP sp = s.getZMMQYZXKSPP();
    	((BindingProvider)sp).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
    	((BindingProvider)sp).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");

 

猜你喜欢

转载自bnmnba.iteye.com/blog/2361980