你必须创建自己的URLStreamHandler,让您可以设置URLConnection参数,如连接超时和读取超时。
SOAPConnection connection = SOAPConnectionFactory.newInstance().createConnection();
URL endpoint =
new URL(new URL("http://yourserver.yourdomain.com/"),
"/path/to/webservice",
new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL url) throws IOException {
URL target = new URL(url.toString());
URLConnection connection = target.openConnection();
// Connection settings
connection.setConnectTimeout(10000); // 10 sec
connection.setReadTimeout(60000); // 1 min
return(connection);
}
});
SOAPMessage result = connection.call(soapMessage, endpoint);
为了清晰起见,我删除了一些try/catch。
嗨塞缪尔 请看下面的问题,因为它与你的问题有相同的上下文。 希望你能在这里提出建议 https://stackoverflow.com/questions/47861767/http-connect-timeout-and-read-timeout-for-urlstreamhandler-with-saaj-working-fo – 2017-12-21 07:00:02