Java URLConnection Create openConnection(URL url)

Here you can find the source of openConnection(URL url)

Description

open Connection

License

Open Source License

Declaration

public static URLConnection openConnection(URL url) 

Method Source Code

//package com.java2s;
/*//from www  . ja va 2  s  .com
 *Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *WSO2 Inc. licenses this file to you under the Apache License,
 *Version 2.0 (the "License"); you may not use this file except
 *in compliance with the License.
 *You may obtain a copy of the License at
 *
 *http://www.apache.org/licenses/LICENSE-2.0
 *
 *Unless required by applicable law or agreed to in writing,
 *software distributed under the License is distributed on an
 *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *KIND, either express or implied.  See the License for the
 *specific language governing permissions and limitations
 *under the License.
 */

import java.io.IOException;

import java.net.URL;
import java.net.URLConnection;

public class Main {
    private static final int WAIT_TIME = 500;

    public static URLConnection openConnection(URL url) {
        long timeoutExpiredMs = System.currentTimeMillis() + WAIT_TIME;
        URLConnection jaggeryServerConnection = null;
        try {
            jaggeryServerConnection = url.openConnection();
        } catch (IOException ignored) {
        }
        while ((jaggeryServerConnection == null)
                && (System.currentTimeMillis() <= timeoutExpiredMs)) {
            try {
                jaggeryServerConnection = url.openConnection();
            } catch (IOException ignored) {
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException ignored) {
            }
        }
        return jaggeryServerConnection;
    }
}

Related

  1. getURLConnection(URL url)
  2. openConnection(final URL url)
  3. openConnection(String urlPath)
  4. openConnection(URL localURL)
  5. openConnection(URL url)
  6. openConnection(URL url)
  7. openConnection(URL url)
  8. openConnectionForceNoProxy(URL url)
  9. openConnectionTo(URL descriptor)