URLConnection setConnectTimeout - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for URLConnection setConnectTimeout method.

This code example shows how to use the following methods:getInputStream, setConnectTimeout, setReadTimeout, setUseCaches
      return getWildcardStreamLocator().locateStream(uri, new File(URLDecoder.decode(url.getFile(), "UTF-8")));
    } 
    final URL url = new URL(uri);
    final URLConnection connection = url.openConnection();
    // avoid jar file locking on Windows. 
    connection.setUseCaches(false);
 
    // setting these timeouts ensures the client does not deadlock indefinitely 
    // when the server has problems. 
    connection.setConnectTimeout(timeout);
    connection.setReadTimeout(timeout);
 
    return new BufferedInputStream(connection.getInputStream());
  } 
 
  /** 
   * The read & connect timeout value (in milliseconds) used to limit wait period to a reasonable value. By default 
   * {@value WroConfiguration#DEFAULT_CONNECTION_TIMEOUT} ms is used. 
   */ 
  public void setTimeout(int timeout) {
7
CodeRank
This code example shows how to use the following methods:getInputStream, setConnectTimeout, setReadTimeout
    try { 
      if (URIMETHOD.matcher(query).find()) url = new URL(query);
      else url = new URL(baseUrl + query);
      LOG.debug("Accessing URL: " + url.toString());
      URLConnection conn = url.openConnection();
      conn.setConnectTimeout(connectionTimeout);
      conn.setReadTimeout(readTimeout);
      return conn.getInputStream();
    } catch (Exception e) {
      LOG.error("Exception thrown while getting data", e);
      wrapAndThrow (SEVERE, e, "Exception in invoking url " + url);
      return null;//unreachable 
    } 
  } 
 
  @Override 
  public void close() { } 
 
  private String getInitPropWithReplacements(String propertyName) {
    final String expr = initProps.getProperty(propertyName);
7
CodeRank
This code example shows how to use the following methods:setRequestMethod, getHeaderField, setConnectTimeout, setReadTimeout
		return this.connection.getContentEncoding();
	} 
	 
	public String getHeaderField(String name) throws IOException {
		connect(); 
		return this.connection.getHeaderField(name);
	} 
	 
	public String getHeaderField(int n) throws IOException {
		connect(); 
		return this.connection.getHeaderField(n);
	} 
	 
	public int getResponseCode()  throws IOException { 
		connect(); 
		int responseCode = this.connection.getResponseCode();
		return responseCode;
	} 
	 
	public String getResponseMessage() throws IOException {
7
CodeRank
This code example shows how to use the following methods:setRequestMethod, setConnectTimeout, setDoInput, setDoOutput, setReadTimeout
    } 
 
    private HttpURLConnection openConnection(URL targetUrl) throws IOException {
        HttpURLConnection conn = (HttpURLConnection) targetUrl.openConnection();
        if (0 < getTimeoutMillis()) { 
            conn.setConnectTimeout(getTimeoutMillis());
            conn.setReadTimeout(getTimeoutMillis());
        } 
        if (isTryGzip()) { 
            conn.setRequestProperty("Accept-Encoding", "gzip");
        } 
 
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.setDoInput(true);
        return conn;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:addRequestProperty, connect, setConnectTimeout, setReadTimeout, setRequestProperty
        URLConnection connection = openConnection(url);
        if(connection instanceof HttpURLConnection){
            ((HttpURLConnection) connection).setRequestMethod("GET");
        } 
 
        connection.connect();
 
        return new SimpleHTTPResponse(connection);
    } 
 
    /** 
     * @see org.geotools.data.ows.HTTPClient#post(java.net.URL, java.io.InputStream, 
     *      java.lang.String) 
     */ 
    public HTTPResponse post(final URL url, final InputStream postContent,
            final String postContentType) throws IOException {
 
        URLConnection connection = openConnection(url);
        if (connection instanceof HttpURLConnection) {
            ((HttpURLConnection) connection).setRequestMethod("POST");

7
CodeRank
This code example shows how to use the following methods:setInstanceFollowRedirects, getInputStream, setConnectTimeout, setReadTimeout
            try { 
                Bitmap bitmap = null;
                final HttpURLConnection conn = (HttpURLConnection) url
                        .openConnection(mProxy);
                if (mIgnoreSSLError) {
                    Util.setIgnoreSSLError(conn);
                } 
                conn.setConnectTimeout(30000);
                conn.setReadTimeout(30000);
                conn.setInstanceFollowRedirects(true);
                final InputStream is = conn.getInputStream();
                final OutputStream os = new FileOutputStream(f);
                copyStream(is, os);
                os.close();
                bitmap = decodeFile(f);
                return bitmap;
            } catch (final FileNotFoundException e) {
                // Storage state may changed, so call FileCache.init() again. 
                // e.printStackTrace(); 
                mFileCache.init();
8
CodeRank
This code example shows how to use the following methods:setRequestMethod, setConnectTimeout, setDoInput, setReadTimeout
        AndroidUtils.disableConnectionReuseIfNecessary(); 
 
        URL url = new URL(urlString);
 
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(10000 /* milliseconds */);
        conn.setConnectTimeout(15000 /* milliseconds */);
        conn.setDoInput(true);
        conn.setRequestMethod("GET");
        return conn;
    } 
 
    /** 
     * Prior to Android 2.2 (Froyo), {@link HttpURLConnection} had some 
     * frustrating bugs. In particular, calling close() on a readable 
     * InputStream could poison the connection pool. Work around this by 
     * disabling connection pooling. 
     */ 
    public static void disableConnectionReuseIfNecessary() { 
        // HTTP connection reuse which was buggy pre-froyo 
8
CodeRank
This code example shows how to use the following methods:disconnect, setRequestMethod, connect, getInputStream, setConnectTimeout
6
CodeRank
This code example shows how to use the following methods:getResponseCode, getResponseMessage, setAllowUserInteraction, setConnectTimeout, setReadTimeout
    boolean success = false;
    try { 
      Log.info("Job end notification trying " + urlToNotify);
      HttpURLConnection conn =
        (HttpURLConnection) urlToNotify.openConnection(proxyToUse);
      conn.setConnectTimeout(timeout);
      conn.setReadTimeout(timeout);
      conn.setAllowUserInteraction(false);
      if(conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
        Log.warn("Job end notification to " + urlToNotify +" failed with code: "
        + conn.getResponseCode() + " and message \"" + conn.getResponseMessage()
        +"\""); 
      } 
      else { 
        success = true;
        Log.info("Job end notification to " + urlToNotify + " succeeded");
      } 
    } catch(IOException ioe) {
      Log.warn("Job end notification to " + urlToNotify + " failed", ioe);
    } 
8
CodeRank
This code example shows how to use the following methods:connect, getInputStream, setConnectTimeout
        URL url = new URL(urlString);
        URLConnection connection = null;
 
        try { 
            connection = url.openConnection();
            connection.setConnectTimeout(5000);
            connection.connect();
        } catch (Exception e) {
            throw new Exception("Cannot connect to " + urlString, e);
        } 
 
        InputStream inputStream = null;
        try { 
            inputStream = connection.getInputStream();
        } catch (Exception e) {
            throw new Exception("Cannot retrieve content from " + url, e);
        } 
 
        try { 
            ProjectManager.singleton.importProject(projectID, inputStream, !urlString.endsWith(".tar"));
7
CodeRank

Related URLConnection setConnectTimeout Questions & Answers:

Other URLConnection setConnectTimeout Examples

67:	            URL imageUrl = new URL(url);
68:	            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
69:	            conn.setConnectTimeout(30000);
70:	            conn.setReadTimeout(30000);
71:	            conn.setInstanceFollowRedirects(true);

Read More

66:	            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
67:	            conn.setConnectTimeout(30000);
68:	            conn.setReadTimeout(30000);
69:	            conn.setInstanceFollowRedirects(true);
70:	            InputStream is=conn.getInputStream();

Read More

setConnectTimeout Method Overview
Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection.
See Code Examples for other Java 8 URLConnection Methods: