WebService接口登录验证代码生成调用

1、参考使用CXF生成WebService接口调用代码_时光下的旅途-CSDN博客生成调用代码

注意:前端登录后,保存为XML文件,根据XML生成接口调用代码

2、调用接口时,设置账号密码(使用jdk方法)

新建MyAuthenticator,继承Authenticator,设置账号密码

public class MyAuthenticator extends Authenticator {

  private String username;
  private String password;

  public MyAuthenticator(String username, String password) {
    this.username = username;
    this.password = password;
  }

  @Override
  protected PasswordAuthentication getPasswordAuthentication() {

    return new PasswordAuthentication(username, password.toCharArray());
  }

}

调用方法:

    Authenticator.setDefault(new MyAuthenticator("账号","密码"));
    ZQUERYRECEIVERFID erp_ws = null;
    try {
      erp_ws = new ZQUERYRECEIVERFID(new URL("接口URL地址"));
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }

你可能感兴趣的:(JAVA,java,WebService接口登录,登录验证,生成WebService调用)