Tabnine Logo
HttpURLConnection.setReadTimeout
Code IndexAdd Tabnine to your IDE (free)

How to use
setReadTimeout
method
in
java.net.HttpURLConnection

Best Java code snippets using java.net.HttpURLConnection.setReadTimeout (Showing top 20 results out of 7,533)

Refine searchRefine arrow

  • HttpURLConnection.setConnectTimeout
  • URL.openConnection
  • HttpURLConnection.setRequestMethod
  • URL.<init>
  • HttpURLConnection.setDoOutput
  • HttpURLConnection.setRequestProperty
origin: jenkinsci/jenkins

/**
 * Connects to the given HTTP URL and configure time out, to avoid infinite hang.
 */
private static HttpURLConnection open(URL url) throws IOException {
  HttpURLConnection c = (HttpURLConnection)url.openConnection();
  c.setReadTimeout(TIMEOUT);
  c.setConnectTimeout(TIMEOUT);
  return c;
}
origin: ACRA/acra

@SuppressWarnings("WeakerAccess")
protected void configureTimeouts(@NonNull HttpURLConnection connection, int connectionTimeOut, int socketTimeOut) {
  connection.setConnectTimeout(connectionTimeOut);
  connection.setReadTimeout(socketTimeOut);
}
origin: spring-projects/spring-framework

/**
 * Template method for preparing the given {@link HttpURLConnection}.
 * <p>The default implementation prepares the connection for input and output, and sets the HTTP method.
 * @param connection the connection to prepare
 * @param httpMethod the HTTP request method ({@code GET}, {@code POST}, etc.)
 * @throws IOException in case of I/O errors
 */
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
  if (this.connectTimeout >= 0) {
    connection.setConnectTimeout(this.connectTimeout);
  }
  if (this.readTimeout >= 0) {
    connection.setReadTimeout(this.readTimeout);
  }
  connection.setDoInput(true);
  if ("GET".equals(httpMethod)) {
    connection.setInstanceFollowRedirects(true);
  }
  else {
    connection.setInstanceFollowRedirects(false);
  }
  if ("POST".equals(httpMethod) || "PUT".equals(httpMethod) ||
      "PATCH".equals(httpMethod) || "DELETE".equals(httpMethod)) {
    connection.setDoOutput(true);
  }
  else {
    connection.setDoOutput(false);
  }
  connection.setRequestMethod(httpMethod);
}
origin: bumptech/glide

 urlConnection.addRequestProperty(headerEntry.getKey(), headerEntry.getValue());
urlConnection.setConnectTimeout(timeout);
urlConnection.setReadTimeout(timeout);
urlConnection.setUseCaches(false);
urlConnection.setDoInput(true);
  throw new HttpException("Received empty or null redirect url");
 URL redirectUrl = new URL(url, redirectUrlString);
origin: ctripcorp/apollo

/**
 * ping the url, return true if ping ok, false otherwise
 */
public static boolean pingUrl(String address) {
 try {
  URL urlObj = new URL(address);
  HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
  connection.setRequestMethod("GET");
  connection.setUseCaches(false);
  connection.setConnectTimeout(DEFAULT_TIMEOUT_IN_SECONDS);
  connection.setReadTimeout(DEFAULT_TIMEOUT_IN_SECONDS);
  int statusCode = connection.getResponseCode();
  cleanUpConnection(connection);
  return (200 <= statusCode && statusCode <= 399);
 } catch (Throwable ignore) {
 }
 return false;
}
origin: spring-projects/spring-security-oauth

/**
 * Open a connection to the given URL.
 *
 * @param requestTokenURL The request token URL.
 * @return The HTTP URL connection.
 */
protected HttpURLConnection openConnection(URL requestTokenURL) {
 try {
  HttpURLConnection connection = (HttpURLConnection) requestTokenURL.openConnection(selectProxy(requestTokenURL));
  connection.setConnectTimeout(getConnectionTimeout());
  connection.setReadTimeout(getReadTimeout());
  return connection;
 }
 catch (IOException e) {
  throw new OAuthRequestFailedException("Failed to open an OAuth connection.", e);
 }
}
origin: apache/incubator-dubbo

  @Override
  protected void prepareConnection(HttpURLConnection con,
                   int contentLength) throws IOException {
    super.prepareConnection(con, contentLength);
    con.setReadTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
    con.setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
  }
};
origin: aws/aws-sdk-java

public HttpURLConnection connectToEndpoint(URI endpoint, Map<String, String> headers) throws IOException {
  HttpURLConnection connection = (HttpURLConnection) endpoint.toURL().openConnection(Proxy.NO_PROXY);
  connection.setConnectTimeout(1000 * 2);
  connection.setReadTimeout(1000 * 5);
  connection.setRequestMethod("GET");
  connection.setDoOutput(true);
  for (Map.Entry<String, String> header : headers.entrySet()) {
    connection.addRequestProperty(header.getKey(), header.getValue());
  }
  // TODO should we autoredirect 3xx
  // connection.setInstanceFollowRedirects(false);
  connection.connect();
  return connection;
}
origin: apache/incubator-dubbo

  @Override
  protected void prepareConnection(HttpURLConnection con,
                   int contentLength) throws IOException {
    super.prepareConnection(con, contentLength);
    con.setReadTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
    con.setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
  }
};
origin: nostra13/Android-Universal-Image-Loader

/**
 * Create {@linkplain HttpURLConnection HTTP connection} for incoming URL
 *
 * @param url   URL to connect to
 * @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
 *              DisplayImageOptions.extraForDownloader(Object)}; can be null
 * @return {@linkplain HttpURLConnection Connection} for incoming URL. Connection isn't established so it still configurable.
 * @throws IOException if some I/O error occurs during network request or if no InputStream could be created for
 *                     URL.
 */
protected HttpURLConnection createConnection(String url, Object extra) throws IOException {
  String encodedUrl = Uri.encode(url, ALLOWED_URI_CHARS);
  HttpURLConnection conn = (HttpURLConnection) new URL(encodedUrl).openConnection();
  conn.setConnectTimeout(connectTimeout);
  conn.setReadTimeout(readTimeout);
  return conn;
}
origin: alipay/sofa-rpc

private HttpURLConnection createConnection(URL url, String method, boolean doOutput) {
  HttpURLConnection con;
  try {
    con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod(method);
    con.setConnectTimeout(connectTimeout);
    con.setReadTimeout(readTimeout);
    con.setDoOutput(doOutput);
    con.setDoInput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type", "text/plain");
    return con;
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  }
}
origin: alipay/sofa-rpc

private HttpURLConnection createConnection(URL url, String method, boolean doOutput) {
  HttpURLConnection con;
  try {
    con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod(method);
    con.setConnectTimeout(connectTimeout);
    con.setReadTimeout(readTimeout);
    con.setDoOutput(doOutput);
    con.setDoInput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type", "text/plain");
    return con;
  } catch (IOException e) {
    e.printStackTrace();
    return null;
  }
}
origin: jmxtrans/jmxtrans

public void configure(HttpURLConnection httpURLConnection) throws ProtocolException {
  httpURLConnection.setRequestMethod(requestMethod);
  httpURLConnection.setDoInput(true);
  httpURLConnection.setDoOutput(true);
  httpURLConnection.setReadTimeout(readTimeoutInMillis);
  if (contentType != null) httpURLConnection.setRequestProperty("Content-Type", contentType);
  if (authorization != null) httpURLConnection.setRequestProperty("Authorization", authorization);
  httpURLConnection.setRequestProperty("User-Agent", userAgent);
}
origin: graphhopper/graphhopper

public HttpURLConnection createConnection(String urlStr) throws IOException {
  URL url = new URL(urlStr);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  // Will yield in a POST request: conn.setDoOutput(true);
  conn.setDoInput(true);
  conn.setUseCaches(true);
  conn.setRequestProperty("Referrer", referrer);
  conn.setRequestProperty("User-Agent", userAgent);
  // suggest respond to be gzipped or deflated (which is just another compression)
  // http://stackoverflow.com/q/3932117
  conn.setRequestProperty("Accept-Encoding", acceptEncoding);
  conn.setReadTimeout(timeout);
  conn.setConnectTimeout(timeout);
  return conn;
}
origin: pwittchen/ReactiveNetwork

 protected HttpURLConnection createHttpUrlConnection(final String host, final int port,
   final int timeoutInMs) throws IOException {
  URL initialUrl = new URL(host);
  URL url = new URL(initialUrl.getProtocol(), initialUrl.getHost(), port, initialUrl.getFile());
  HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  urlConnection.setConnectTimeout(timeoutInMs);
  urlConnection.setReadTimeout(timeoutInMs);
  urlConnection.setInstanceFollowRedirects(false);
  urlConnection.setUseCaches(false);
  return urlConnection;
 }
}
origin: jfinal/jfinal

private static HttpURLConnection getHttpConnection(String url, String method, Map<String, String> headers) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
  URL _url = new URL(url);
  HttpURLConnection conn = (HttpURLConnection)_url.openConnection();
  if (conn instanceof HttpsURLConnection) {
    ((HttpsURLConnection)conn).setSSLSocketFactory(sslSocketFactory);
    ((HttpsURLConnection)conn).setHostnameVerifier(trustAnyHostnameVerifier);
  }
  
  conn.setRequestMethod(method);
  conn.setDoOutput(true);
  conn.setDoInput(true);
  
  conn.setConnectTimeout(19000);
  conn.setReadTimeout(19000);
  
  conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
  conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36");
  
  if (headers != null && !headers.isEmpty()) {
    for (Entry<String, String> entry : headers.entrySet()) {
      conn.setRequestProperty(entry.getKey(), entry.getValue());
    }
  }
  
  return conn;
}
 
origin: Netflix/eureka

  public static String readEc2MetadataUrl(MetaDataKey metaDataKey, URL url, int connectionTimeoutMs, int readTimeoutMs) throws IOException {
    HttpURLConnection uc = (HttpURLConnection) url.openConnection();
    uc.setConnectTimeout(connectionTimeoutMs);
    uc.setReadTimeout(readTimeoutMs);
    uc.setRequestProperty("User-Agent", "eureka-java-client");

    if (uc.getResponseCode() != HttpURLConnection.HTTP_OK) {  // need to read the error for clean connection close
      BufferedReader br = new BufferedReader(new InputStreamReader(uc.getErrorStream()));
      try {
        while (br.readLine() != null) {
          // do nothing but keep reading the line
        }
      } finally {
        br.close();
      }
    } else {
      return metaDataKey.read(uc.getInputStream());
    }

    return null;
  }
}
origin: sohutv/cachecloud

private static HttpURLConnection sendPost(String reqUrl,
    Map<String, String> parameters, String encoding, int connectTimeout, int readTimeout) {
  HttpURLConnection urlConn = null;
  try {
    String params = generatorParamString(parameters, encoding);
    URL url = new URL(reqUrl);
    urlConn = (HttpURLConnection) url.openConnection();
    urlConn.setRequestMethod("POST");
    // urlConn
    // .setRequestProperty(
    // "User-Agent",
    // "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3");
    urlConn.setConnectTimeout(connectTimeout);// (单位:毫秒)jdk
    urlConn.setReadTimeout(readTimeout);// (单位:毫秒)jdk 1.5换成这个,读操作超时
    urlConn.setDoOutput(true);
    // String按照字节处理是一个好方法
    byte[] b = params.getBytes(encoding);
    urlConn.getOutputStream().write(b, 0, b.length);
    urlConn.getOutputStream().flush();
    urlConn.getOutputStream().close();
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
  }
  return urlConn;
}
origin: apache/flume

 /**
  * Creates an HTTP connection to the configured endpoint address. This
  * connection is setup for a POST request, and uses the content type and
  * accept header values in the configuration.
  *
  * @return the connection object
  * @throws IOException on any connection error
  */
 public HttpURLConnection getConnection() throws IOException {
  HttpURLConnection connection = (HttpURLConnection)
    endpointUrl.openConnection();
  connection.setRequestMethod("POST");
  connection.setRequestProperty("Content-Type", contentTypeHeader);
  connection.setRequestProperty("Accept", acceptHeader);
  connection.setConnectTimeout(connectTimeout);
  connection.setReadTimeout(requestTimeout);
  connection.setDoOutput(true);
  connection.setDoInput(true);
  connection.connect();
  return connection;
 }
}
origin: Javen205/IJPay

private static HttpURLConnection getHttpConnection(String url, String method, Map<String, String> headers) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
  URL _url = new URL(url);
  HttpURLConnection conn = (HttpURLConnection)_url.openConnection();
  if (conn instanceof HttpsURLConnection) {
    ((HttpsURLConnection)conn).setSSLSocketFactory(sslSocketFactory);
    ((HttpsURLConnection)conn).setHostnameVerifier(trustAnyHostnameVerifier);
  }
  
  conn.setRequestMethod(method);
  conn.setDoOutput(true);
  conn.setDoInput(true);
  
  conn.setConnectTimeout(19000);
  conn.setReadTimeout(19000);
  
  conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
  conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36");
  
  if (headers != null && !headers.isEmpty())
    for (Entry<String, String> entry : headers.entrySet())
      conn.setRequestProperty(entry.getKey(), entry.getValue());
  
  return conn;
}

java.netHttpURLConnectionsetReadTimeout

Popular methods of HttpURLConnection

  • getInputStream
  • getResponseCode
    Returns the response code returned by the remote HTTP server.
  • setRequestMethod
    Sets the request command which will be sent to the remote HTTP server. This method can only be calle
  • setRequestProperty
  • setDoOutput
  • getOutputStream
  • disconnect
    Releases this connection so that its resources may be either reused or closed. Unlike other Java imp
  • setConnectTimeout
  • connect
  • getErrorStream
    Returns an input stream from the server in the case of an error such as the requested file has not b
  • setDoInput
  • getResponseMessage
    Returns the response message returned by the remote HTTP server.
  • setDoInput,
  • getResponseMessage,
  • getHeaderField,
  • setUseCaches,
  • setInstanceFollowRedirects,
  • getHeaderFields,
  • addRequestProperty,
  • getContentLength,
  • getURL

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • putExtra (Intent)
  • runOnUiThread (Activity)
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Path (java.nio.file)
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • JComboBox (javax.swing)
  • JLabel (javax.swing)
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now