0

I set my Java System Properties for my secure SSL Connection like this:

System.setProperty("https.protocols", "TLSv1.2")
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12")
System.setProperty("javax.net.ssl.keyStore",keyStore)
System.setProperty("javax.net.ssl.keyStorePassword", keyStorePW)
System.setProperty("javax.net.ssl.trustStore",trustStore)
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePW) 

Now I do Something like this:

  • send SOAP request 1
  • doing other stuff
  • send SOAP request 2

If "doing other stuff" takes longer then 5 sec, the whole SSL Handshake (Server Hello, Client hello etc.) will we done again. If "doing other stuff" takes less then 5 sec, the request will be send immediately

--> How Can I set this duration longer then 5 sec?

EDIT:

This is how I do my SOAP call:

static String callSoap() {

       SOAPMessage request = //..creating request
        
       SOAPMessage response=dispatch.invoke(request)

       SOAPBody responseBody=response.getSOAPBody()

   .......
   
   return....
  }
conryyy
  • 127
  • 1
  • 9

1 Answers1

1

When you call socket.connect(), you can specify there the desired timeout. F.e:

int timeout = 5000 * 3;
socket.setSoTimeout(timeout);
socket.connect(new InetSocketAddress(hostAddress, port), timeout);

SoTimeout may not be needed; This timeout is the time a read() call will block before throwing a exception. You can set it to 0 if you don't wish any timeout reading, and you accept just waiting until a byte is read.

This should only try to reconnect when it takes more than 15 seconds to finish the process.


Ok, int the SOAP world,something like this should do the trick:

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);

Take a look here for more info, may be helpful.

aran
  • 10,978
  • 5
  • 39
  • 69
  • I tried to build your suggestion in my Lib. I still have the same problem: If the duration after the 1. SOAP call is more than 4 sec - the whole handshake stuff will be made again at the 2. SOAP call. Is it really a Timeout problem here? – conryyy Jul 13 '20 at 07:52
  • I think it is not Problem of the Read Timeout. It seems to be more a Problem of the Http Session. I moved this to a new [question](https://stackoverflow.com/questions/62875355/example-for-a-java-soap-client-that-maintains-http-session) – conryyy Jul 13 '20 at 11:58