【发布时间】:2021-02-25 09:51:27
【问题描述】:
我正在尝试调用一个 SOAP 端点,该端点已使用 Java 11 / Spring / Gradle 的项目中的用户名/密码设置了基本身份验证。 我设法使用 JDK 8 使用 wsimport 生成了这些类,并找到了几种方法,但它们都不起作用。
第一种方法来自这里:https://mkyong.com/webservices/jax-ws/application-authentication-with-jax-ws/ 但我得到一个 java.lang.IllegalArgumentException: *当我尝试时,从方法引用的端口在类加载器中不可见
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
我尝试使用 Service 类和 HelloWorld 类作为由 wsimport 生成的类或由我编写的类,就像在这个例子中所做的那样:https://www.baeldung.com/spring-soap-web-service#1-generate-client-code
设置身份验证标头的第二种方法是使用
BindingProvider prov = (BindingProvider)tilwsPort;
prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pass");
我还尝试通过调用服务的生成方法来获取接口,例如:
HelloWorld hello = service.getHelloWorldPort();
有什么建议应该是正确的方法吗?谢谢!
【问题讨论】: