HTTP :connect timeout and read timeout for URLStreamHandler with SAAJ working for windows but not working on linux sytem

ⅰ亾dé卋堺 提交于 2019-12-04 02:30:09

问题


I'm a beginner when it comes to HTTP connections. Currently i'm working with SAAJ api to have my soap based client, where to handle timeouts i ended up using URLStreamHandler for HTTP connection properties with the endpoints.

Problem is that this timeout works for my windows based system, however it isn't working for the Linux server it is going to go live on.

below is the code for fetching endpoint with set properties. It is a HTTP POST connection.

    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;

for the SAAJ API part, below is the implementation, pretty basic one

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

Is it that system properties would affect connect or read timeout. If so please let me know what could cause this behavior.

来源:https://stackoverflow.com/questions/47861767/http-connect-timeout-and-read-timeout-for-urlstreamhandler-with-saaj-working-fo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!