I am trying to call a SOAP endpoint which has set up a basic authentication with username/password from a project with Java 11 / Spring / Gradle. I managed to generate with wsimport using a JDK 8 the classes and found a couple of approaches, but none of them work.
1st approach was from here: https://mkyong.com/webservices/jax-ws/application-authentication-with-jax-ws/ but I get an java.lang.IllegalArgumentException: *Port referenced from a method is not visible from class loader when I try
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
I tried both with the Service class and the HelloWorld class being the classes generated by wsimport or being written by me, as it is done in this example: https://www.baeldung.com/spring-soap-web-service#1-generate-client-code
The second approach for setting the auth headers was with
BindingProvider prov = (BindingProvider)tilwsPort;
prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pass");
I also tried to get the Interface by calling the generated method for the service, like:
HelloWorld hello = service.getHelloWorldPort();
Any advice which should be the right approach? Thank you!