有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何设置JAVA SSL连接的持续时间

我为安全SSL连接设置Java系统属性,如下所示:

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) 

现在我做了这样的事情:

  • 发送SOAP请求1
  • 做其他事情
  • 发送SOAP请求2

如果“做其他事情”花费的时间超过5秒,那么整个SSL握手(服务器Hello、客户端Hello等)将再次完成。 如果“做其他事情”所需时间少于5秒,则会立即发送请求

——>;如何将此持续时间设置为大于5秒

编辑:

这是我如何进行SOAP调用的:

static String callSoap() {

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

       SOAPBody responseBody=response.getSOAPBody()

   .......
   
   return....
  }

共 (1) 个答案

  1. # 1 楼答案

    调用socket.connect()时,可以在那里指定所需的超时。F.e.:

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

    SoTimeout可能不需要;此超时是read()调用在引发异常之前将阻塞的时间。如果您不希望任何超时读取,可以将其设置为0,并且您接受只等待读取一个字节

    仅当完成此过程所需时间超过15秒时,才应尝试重新连接


    好的,在SOAP世界中,类似这样的东西应该可以做到:

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

    查看here了解更多信息,可能会有所帮助