1: 首先把证书导出
点击这把锁的标识,弹出
查看证书
点导出,生在一个myKey.cer 文件
2:然后根据这个.CER文件生成.trustStore 文件
keytool -import -file f:/myKey.cer -storepass netconfig -keystore f:/crtTrust.trustStore config -noprompt
3: 在需要用倒的地方加上
System.setProperty("javax.net.ssl.trustStore","f:/crtTrust.trustStore");
System.setProperty("javax.net.ssl.trustStorePassword", "netconfig");
4:如果服务器端需要用户名的密码验证,那得把用户名和密码传进去
System.setProperty("javax.net.ssl.trustStore","f:/crtTrust.trustStore");
System.setProperty("javax.net.ssl.trustStorePassword", "netconfig");
/**
* keytool -import -file f:/net.cer -storepass netconfig -keystore f:/crt1.trustStore -noprompt
* 生成 f:/crt1.trustStore 和 f:/crt 这两个文件都行。
*/
try
{
RPCServiceClient serviceClient = new RPCServiceClient();
Options option = serviceClient.getOptions();
// http://localhost:8087/HelloWord 访问 WSDL的路径名称
//https://localhost:8080/server/security?wsdl
EndpointReference tReference = new EndpointReference("https://localhost:8080/server/launchers?wsdl");
option.setTo(tReference);
Authenticator authenticator = new Authenticator();
List<String> auth = new ArrayList<String>();
auth.add(Authenticator.BASIC);
authenticator.setAuthSchemes(auth);
authenticator.setUsername("admin");
authenticator.setPassword("password");
authenticator.setPreemptiveAuthentication(true);
option.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
// 指定 sayHello 方法的参数 返回值对象
Class[] classes = new Class[] { List[].class };
//调用sayHello 的方法 及 WSDL 的命名空间 (注意:是WSDL中的namespace 属性 (在这里犯了一个大错))
// http://www.netconfig.org/server/security listUsers
QName qName = new QName("http://www.netconfig.org/server/launchers", "getLaunchers");
/**
* qName :表示方法名
*
* opAddEntryArgs :参数类型 object[]
*
* classes :返回值 类型 class
*/
Object[] obj = serviceClient.invokeBlocking(qName, new Object[] {}, classes);
List[] list_arr = (List[])obj[0];
for (int i= 0 ; i < list_arr.length; i ++)
{
List list_ = list_arr[i];
for (int j = 0 ; j < list_.size() ;j ++)
{
OMElementImpl omElementImpl = (OMElementImpl)list_.get(j);
System.out.println("localname--"+omElementImpl.getLocalName());
System.out.println("text--"+omElementImpl.getText());
}
//System.out.println("str---"+string_arr[i]);
}
}
catch (Exception e){
e.printStackTrace();
}