spring
SOAP WS Consommation
Recherche…
Consommer un WS SOAP avec l'authentification de base
Créez votre propre WSMessageSender:
import java.io.IOException;
import java.net.HttpURLConnection;
import org.springframework.ws.transport.http.HttpUrlConnectionMessageSender;
import sun.misc.BASE64Encoder;
public class CustomWSMessageSender extends HttpUrlConnectionMessageSender{
@Override
protected void prepareConnection(HttpURLConnection connection)
throws IOException {
BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userpassword = "yourUser:yourPassword";
String encodedAuthorization = enc.encode( userpassword.getBytes() );
connection.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
super.prepareConnection(connection);
}
}
Dans votre classe de configuration WS, définissez le MessageSender que vous venez de créer:
myWSClient.setMessageSender(new CustomWSMessageSender());
Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow