Answer the question
In order to leave comments, you need to log in
Java SOAP. Authorization. Can't figure out how to do it?
Good afternoon!
I want to connect to the sletat.ru service ( module.sletat.ru/XmlGate.svc?singlewsdl)
I wrote the following code:
URL url = new URL("http://module.sletat.ru/XmlGate.svc?singlewsdl");
QName qname = new QName("urn:SletatRu:Contracts:Soap11Gate:v1", "Soap11Gate");
Service service = Service.create(url, qname);
Soap11Gate soap = service.getPort(Soap11Gate.class);
AuthData auth = new AuthData();
auth.setLogin(new JAXBElement<String>(qname, String.class, "******"));
auth.setPassword(new JAXBElement<String>(qname, String.class, "*******"));
QName qname = new QName("urn:SletatRu:Contracts:Soap11Gate:v1", "Soap11Gate");
Service service = Service.create(url, qname);
Soap11Gate soap = service.getPort(Soap11Gate.class);
AuthData auth = new AuthData();
auth.setLogin(new JAXBElement<String>(qname, String.class, "*******"));
auth.setPassword(new JAXBElement<String>(qname, String.class, "*********"));
System.out.println(soap.getCountries(6));
Answer the question
In order to leave comments, you need to log in
Try doing something like this before client initialization:
// ...
import java.net.Authenticator;
import java.net.PasswordAuthentication;
// ...
Authenticator myAuth = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
};
Authenticator.setDefault(myAuth);
// ...
This article helped me.
chrisdail.com/2008/08/13/http-basic-authentication...
But I am using cxf apache.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question