spring
Consumo WS SOAP
Ricerca…
Consumo di un SOAP SOAP con l'autenticazione di base
Crea il tuo 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);
}
}
Nella tua classe di configurazione WS imposta MessageSender che hai appena creato:
myWSClient.setMessageSender(new CustomWSMessageSender());
Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow