Java Code Examples for java.net.httpurlconnection#getReadTimeout()

The following examples show how to use java.net.httpurlconnection#getReadTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpsUtil.java    From xnx3 with Apache License 2.0 5 votes vote down vote up
/**
 * 得到响应对象
 * @param urlConnection
 * @param content 网页内容
 * @return 响应对象
 * @throws IOException
 */ 
private HttpResponse makeContent(String urlString, HttpURLConnection urlConnection, String content) throws IOException { 
    HttpResponse httpResponser = new HttpResponse(); 
    try { 
        httpResponser.contentCollection = new Vector<String>(); 
        String ecod = urlConnection.getContentEncoding(); 
        if (ecod == null) 
            ecod = this.encode; 
        httpResponser.urlString = urlString; 
        this.cookies=urlConnection.getHeaderField("Set-Cookie");
        httpResponser.cookie=this.cookies;
        httpResponser.defaultPort = urlConnection.getURL().getDefaultPort(); 
        httpResponser.file = urlConnection.getURL().getFile(); 
        httpResponser.host = urlConnection.getURL().getHost(); 
        httpResponser.path = urlConnection.getURL().getPath(); 
        httpResponser.port = urlConnection.getURL().getPort(); 
        httpResponser.protocol = urlConnection.getURL().getProtocol(); 
        httpResponser.query = urlConnection.getURL().getQuery(); 
        httpResponser.ref = urlConnection.getURL().getRef(); 
        httpResponser.userInfo = urlConnection.getURL().getUserInfo(); 
        httpResponser.content = content;
        httpResponser.contentEncoding = ecod; 
        httpResponser.code = urlConnection.getResponseCode(); 
        httpResponser.message = urlConnection.getResponseMessage(); 
        httpResponser.contentType = urlConnection.getContentType(); 
        httpResponser.method = urlConnection.getRequestMethod(); 
        httpResponser.connectTimeout = urlConnection.getConnectTimeout(); 
        httpResponser.readTimeout = urlConnection.getReadTimeout(); 
        httpResponser.headerFields = urlConnection.getHeaderFields();
        return httpResponser; 
    } catch (IOException e) { 
        throw e; 
    } finally { 
        if (urlConnection != null) 
            urlConnection.disconnect(); 
    } 
}
 
Example 2
Source File: HttpRequester.java    From metrics with Apache License 2.0 4 votes vote down vote up
/**
 * 得到响应对象
 *
 * @param urlConnection
 * @return 响应对象
 * @throws IOException
 */
private HttpRespons makeContent(String urlString,
        HttpURLConnection urlConnection) throws IOException {
    HttpRespons httpResponser = new HttpRespons();
    try {
        InputStream in = urlConnection.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(in));
        httpResponser.contentCollection = new Vector<String>();
        StringBuffer temp = new StringBuffer();
        String line = bufferedReader.readLine();
        while (line != null) {
            httpResponser.contentCollection.add(line);
            temp.append(line).append("\r\n");
            line = bufferedReader.readLine();
        }
        bufferedReader.close();

        String ecod = urlConnection.getContentEncoding();
        if (ecod == null)
            ecod = this.defaultContentEncoding;

        httpResponser.urlString = urlString;

        httpResponser.defaultPort = urlConnection.getURL().getDefaultPort();
        httpResponser.file = urlConnection.getURL().getFile();
        httpResponser.host = urlConnection.getURL().getHost();
        httpResponser.path = urlConnection.getURL().getPath();
        httpResponser.port = urlConnection.getURL().getPort();
        httpResponser.protocol = urlConnection.getURL().getProtocol();
        httpResponser.query = urlConnection.getURL().getQuery();
        httpResponser.ref = urlConnection.getURL().getRef();
        httpResponser.userInfo = urlConnection.getURL().getUserInfo();

        httpResponser.content = new String(temp.toString().getBytes(), ecod);
        httpResponser.contentEncoding = ecod;
        httpResponser.code = urlConnection.getResponseCode();
        httpResponser.message = urlConnection.getResponseMessage();
        httpResponser.contentType = urlConnection.getContentType();
        httpResponser.method = urlConnection.getRequestMethod();
        httpResponser.connectTimeout = urlConnection.getConnectTimeout();
        httpResponser.readTimeout = urlConnection.getReadTimeout();

        return httpResponser;
    } catch (IOException e) {
        throw e;
    } finally {
        if (urlConnection != null)
            urlConnection.disconnect();
    }
}
 
Example 3
Source File: HttpUtil.java    From xnx3 with Apache License 2.0 4 votes vote down vote up
/**
 * 得到响应对象
 * @param urlConnection
 * @return 响应对象
 * @throws IOException
 */ 
private HttpResponse makeContent(String urlString, HttpURLConnection urlConnection) throws IOException { 
	urlConnection.setConnectTimeout(this.timeout);
	urlConnection.setReadTimeout(this.timeout);
    HttpResponse httpResponser = new HttpResponse(); 
    try { 
        InputStream in = urlConnection.getInputStream(); 
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in)); 
        httpResponser.contentCollection = new Vector<String>(); 
        StringBuffer temp = new StringBuffer(); 
        String line = bufferedReader.readLine(); 
        while (line != null) { 
            httpResponser.contentCollection.add(line); 
            temp.append(line).append("\r\n"); 
            line = bufferedReader.readLine(); 
        } 
        bufferedReader.close(); 
        String ecod = urlConnection.getContentEncoding(); 
        if (ecod == null) 
            ecod = this.encode; 
        httpResponser.urlString = urlString; 
        //urlConnection.getHeaderField("Set-Cookie");获取到的COOKIES不全,会将JSESSIONID漏掉,故而采用此中方式
        if(this.cookies == null || this.cookies.equals("")){
        	if(urlConnection.getHeaderFields().get("Set-Cookie") != null){
        		List<String> listS = urlConnection.getHeaderFields().get("Set-Cookie");
        		String cookie = "";
            	if(listS != null){
                    for (int i = 0; i < listS.size(); i++) {
        				cookie = cookie + (cookie.equals("")? "":", ") + listS.get(i);
        			}
            	}else{
            		cookie = urlConnection.getHeaderField("Set-Cookie");
            	}
            	this.cookies=cookie;
            	httpResponser.cookie=this.cookies;
        	}
        }
        httpResponser.defaultPort = urlConnection.getURL().getDefaultPort(); 
        httpResponser.file = urlConnection.getURL().getFile(); 
        httpResponser.host = urlConnection.getURL().getHost(); 
        httpResponser.path = urlConnection.getURL().getPath(); 
        httpResponser.port = urlConnection.getURL().getPort(); 
        httpResponser.protocol = urlConnection.getURL().getProtocol(); 
        httpResponser.query = urlConnection.getURL().getQuery(); 
        httpResponser.ref = urlConnection.getURL().getRef(); 
        httpResponser.userInfo = urlConnection.getURL().getUserInfo(); 
        httpResponser.content = new String(temp.toString().getBytes(), ecod); 
        httpResponser.contentEncoding = ecod; 
        httpResponser.code = urlConnection.getResponseCode(); 
        httpResponser.message = urlConnection.getResponseMessage(); 
        httpResponser.contentType = urlConnection.getContentType(); 
        httpResponser.method = urlConnection.getRequestMethod(); 
        httpResponser.connectTimeout = urlConnection.getConnectTimeout(); 
        httpResponser.readTimeout = urlConnection.getReadTimeout(); 
        httpResponser.headerFields = urlConnection.getHeaderFields();
    } catch (IOException e) { 
    	httpResponser.code = 404;
    } finally { 
        if (urlConnection != null) 
            urlConnection.disconnect(); 
    } 
    return httpResponser; 
}
 
Example 4
Source File: HttpRequester.java    From jfinal-api-scaffold with MIT License 4 votes vote down vote up
/**
 * 处理响应
 *
 * @param urlConnection
 * @return 响应对象
 * @throws java.io.IOException
 */
private HttpResponse makeContent(String urlString,
                                 HttpURLConnection urlConnection) throws IOException {
    HttpResponse httpResponser = new HttpResponse();
    try {
        InputStream in = urlConnection.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(in));
        httpResponser.contentCollection = new Vector<String>();
        StringBuffer temp = new StringBuffer();
        String line = bufferedReader.readLine();
        while (line != null) {
            httpResponser.contentCollection.add(line);
            temp.append(line).append("\r\n");
            line = bufferedReader.readLine();
        }
        bufferedReader.close();

        String ecod = urlConnection.getContentEncoding();
        if (ecod == null)
            ecod = this.defaultContentEncoding;

        httpResponser.urlString = urlString;

        httpResponser.defaultPort = urlConnection.getURL().getDefaultPort();
        httpResponser.file = urlConnection.getURL().getFile();
        httpResponser.host = urlConnection.getURL().getHost();
        httpResponser.path = urlConnection.getURL().getPath();
        httpResponser.port = urlConnection.getURL().getPort();
        httpResponser.protocol = urlConnection.getURL().getProtocol();
        httpResponser.query = urlConnection.getURL().getQuery();
        httpResponser.ref = urlConnection.getURL().getRef();
        httpResponser.userInfo = urlConnection.getURL().getUserInfo();

        httpResponser.content = new String(temp.toString().getBytes(), ecod);
        httpResponser.contentEncoding = ecod;
        httpResponser.code = urlConnection.getResponseCode();
        httpResponser.message = urlConnection.getResponseMessage();
        httpResponser.contentType = urlConnection.getContentType();
        httpResponser.method = urlConnection.getRequestMethod();
        httpResponser.connectTimeout = urlConnection.getConnectTimeout();
        httpResponser.readTimeout = urlConnection.getReadTimeout();

        return httpResponser;
    } catch (IOException e) {
        throw e;
    } finally {
        if (urlConnection != null)
            urlConnection.disconnect();
    }
}