HTTP:连接超时和URLStreamHandler的读取超时,SAAJ适用于Windows,但不适用于Linux系统

时间:2017-12-18 03:27:26

标签: linux http timeout connect saaj

在HTTP连接方面,我是初学者。 目前我正在使用SAAJ api来使用基于soap的客户端,在哪里处理超时我最终使用URLStreamHandler来获取与端点的HTTP连接属性。

问题是这个超时适用于我的基于Windows的系统,但它不适用于它将要运行的Linux服务器。

下面是使用set属性获取端点的代码。这是一个HTTP POST连接。

    URL endpoint = new URL (null, url, new URLStreamHandler () {
        protected URLConnection openConnection (URL url) throws IOException {
            // The url is the parent of this stream handler, so must create clone
            URL clone = new URL (url.toString ());
            HttpURLConnection connection = (HttpURLConnection) clone.openConnection();
            connection.setRequestProperty("Content-Type",
                    "text/xml");

            connection.setRequestProperty("Accept",
                    "application/soap+xml, text/*");

            // If we cast to HttpURLConnection, we can set redirects
            // connection.setInstanceFollowRedirects (false);
            connection.setDoOutput(true);
            connection.setConnectTimeout(3 * 1000);
            connection.setReadTimeout(3 * 1000);
            return connection;

对于SAAJ API部分,下面是实现,非常基本的

    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
            .newInstance();
    soapConnection = soapConnectionFactory.createConnection();

    is = new ByteArrayInputStream(command.getBytes());

    SOAPMessage request = MessageFactory.newInstance(
            SOAPConstants.SOAP_1_1_PROTOCOL).createMessage(
                    new MimeHeaders(), is);

    MimeHeaders headers = request.getMimeHeaders();
    headers.addHeader("Content-Type", "text/xml");

    request.saveChanges();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    request.writeTo(out);

    soapResponse = soapConnection.call(request, endpoint);

系统属性是否会影响连接或读取超时。如果是这样,请告诉我可能导致此行为的原因。

0 个答案:

没有答案