axis2.0 options 里面的 username password 感觉有点混淆概念,试了半天不是这两个属性,不知道属性放在这里什么用,API很不好找。
// 服务端引用
EndpointReference targetEPR = new EndpointReference(wsdl);
// 设置属性
Options options = new Options();
options.setTo(targetEPR);
// basic 认证
HttpTransportProperties.Authenticator authenticator = (HttpTransportProperties.Authenticator) options
.getProperty(HTTPConstants.AUTHENTICATE);
if (authenticator == null) {
authenticator = new HttpTransportProperties.Authenticator();
options.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
}
authenticator.setRealm(HttpTransportProperties.Authenticator.BASIC);
authenticator.setUsername("11200005555");
authenticator.setPassword("88888888");
// 设置xml字符集
options.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING, "GBK");
// 设置超时时间
options.setTimeOutInMilliSeconds(20000);