当前位置: 首页>>代码示例>>Java>>正文


Java HttpParams.setIntParameter方法代码示例

本文整理汇总了Java中org.apache.http.params.HttpParams.setIntParameter方法的典型用法代码示例。如果您正苦于以下问题:Java HttpParams.setIntParameter方法的具体用法?Java HttpParams.setIntParameter怎么用?Java HttpParams.setIntParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.params.HttpParams的用法示例。


在下文中一共展示了HttpParams.setIntParameter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: query

import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
/**
 * Execute Http request and response code
 * @param request - HTTP Request
 * @param expectedCode - expected response code
 * @return - response in JSONObject
 */
public JSON query(HttpRequestBase request, int expectedCode) throws IOException {
    log.info("Requesting: " + request);
    addRequiredHeader(request);

    HttpParams requestParams = request.getParams();
    requestParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT * 1000);
    requestParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT * 1000);

    synchronized (httpClient) {
        String response;
        try {
            HttpResponse result = httpClient.execute(request);

            int statusCode = result.getStatusLine().getStatusCode();

            response = getResponseEntity(result);

            if (statusCode != expectedCode) {

                notifier.notifyAbout("Response with code " + statusCode + ": " + extractErrorMessage(response));
                throw new IOException("API responded with wrong status code: " + statusCode);
            } else {
                log.debug("Response: " + response);
            }
        } finally {
            request.abort();
        }

        if (response == null || response.isEmpty()) {
            return JSONNull.getInstance();
        } else {
            return JSONSerializer.toJSON(response, new JsonConfig());
        }
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:42,代码来源:HttpUtils.java

示例2: setIntClientParameter

import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
/**
 * Sets an int parameter on the http client, use null to clear
 * 
 * @param timeout
 *            The new timeout
 */
protected void setIntClientParameter(final Integer timeout, final String parameter) {
    HttpParams params = httpClient.getParams();
    if (timeout != null) {
        params.setIntParameter(parameter, timeout);
    } else {
        params.removeParameter(parameter);
    }
    httpClient.setParams(params);
}
 
开发者ID:Hitachi-Data-Systems,项目名称:Open-DM,代码行数:16,代码来源:HCAPAdapter.java

示例3: setMaxTotalConnections

import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
/**
 * Sets the maximum number of connections allowed.
 *
 * @param params HTTP parameters
 * @param maxTotalConnections The maximum number of connections allowed.
 */
public static void setMaxTotalConnections(
        final HttpParams params,
        int maxTotalConnections) {
    if (params == null) {
        throw new IllegalArgumentException
            ("HTTP parameters must not be null.");
    }
    params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:ConnManagerParams.java

示例4: getHttpPostResponse

import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
public void getHttpPostResponse(String str, ArrayList<KVPair<String>> arrayList,
                                KVPair<String> kVPair, ArrayList<KVPair<String>> arrayList2,
                                ArrayList<KVPair<?>> arrayList3, HttpResponseCallback
                                        httpResponseCallback) throws Throwable {
    HttpUriRequest filePost;
    long currentTimeMillis = System.currentTimeMillis();
    Ln.i("httpPost: " + str, new Object[0]);
    if (kVPair == null || kVPair.value == null || !new File((String) kVPair.value).exists()) {
        Object textPost = getTextPost(str, arrayList);
    } else {
        ArrayList arrayList4 = new ArrayList();
        arrayList4.add(kVPair);
        filePost = getFilePost(str, arrayList, arrayList4);
    }
    if (arrayList2 != null) {
        Iterator it = arrayList2.iterator();
        while (it.hasNext()) {
            KVPair kVPair2 = (KVPair) it.next();
            filePost.setHeader(kVPair2.name, (String) kVPair2.value);
        }
    }
    HttpParams basicHttpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(basicHttpParams, connectionTimeout);
    HttpConnectionParams.setSoTimeout(basicHttpParams, readTimout);
    if (arrayList3 != null) {
        Iterator it2 = arrayList3.iterator();
        while (it2.hasNext()) {
            kVPair2 = (KVPair) it2.next();
            try {
                basicHttpParams.setIntParameter(kVPair2.name, R.parseInt(String.valueOf
                        (kVPair2.value)));
            } catch (Exception e) {
            }
        }
    }
    filePost.setParams(basicHttpParams);
    HttpClient sSLHttpClient = str.startsWith("https://") ? getSSLHttpClient() : new
            DefaultHttpClient();
    HttpResponse execute = sSLHttpClient.execute(filePost);
    if (httpResponseCallback != null) {
        httpResponseCallback.onResponse(execute);
    }
    sSLHttpClient.getConnectionManager().shutdown();
    Ln.i("use time: " + (System.currentTimeMillis() - currentTimeMillis), new Object[0]);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:46,代码来源:NetworkHelper.java

示例5: httpPost

import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
public void httpPost(String str, ArrayList<KVPair<String>> arrayList,
                     ArrayList<KVPair<String>> arrayList2, ArrayList<KVPair<String>>
                             arrayList3, ArrayList<KVPair<?>> arrayList4,
                     HttpResponseCallback httpResponseCallback) throws Throwable {
    HttpUriRequest filePost;
    long currentTimeMillis = System.currentTimeMillis();
    Ln.i("httpPost: " + str, new Object[0]);
    if (arrayList2 == null || arrayList2.size() <= 0) {
        Object textPost = getTextPost(str, arrayList);
    } else {
        filePost = getFilePost(str, arrayList, arrayList2);
    }
    if (arrayList3 != null) {
        Iterator it = arrayList3.iterator();
        while (it.hasNext()) {
            KVPair kVPair = (KVPair) it.next();
            filePost.setHeader(kVPair.name, (String) kVPair.value);
        }
    }
    HttpParams basicHttpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(basicHttpParams, connectionTimeout);
    HttpConnectionParams.setSoTimeout(basicHttpParams, readTimout);
    Ln.i("before set SO_TIMEOUT :" + basicHttpParams.getIntParameter("http.socket.timeout",
            readTimout), new Object[0]);
    Ln.i("before set CONNECTION_TIMEOUT :" + basicHttpParams.getIntParameter("http.connection" +
            ".timeout", connectionTimeout), new Object[0]);
    if (arrayList4 != null) {
        Iterator it2 = arrayList4.iterator();
        while (it2.hasNext()) {
            kVPair = (KVPair) it2.next();
            try {
                basicHttpParams.setIntParameter(kVPair.name, R.parseInt(String.valueOf(kVPair
                        .value)));
            } catch (Exception e) {
            }
        }
    }
    Ln.i("before set SO_TIMEOUT :" + basicHttpParams.getIntParameter("http.socket.timeout",
            readTimout), new Object[0]);
    Ln.i("before set CONNECTION_TIMEOUT :" + basicHttpParams.getIntParameter("http.connection" +
            ".timeout", connectionTimeout), new Object[0]);
    filePost.setParams(basicHttpParams);
    HttpClient sSLHttpClient = str.startsWith("https://") ? getSSLHttpClient() : new
            DefaultHttpClient();
    HttpResponse execute = sSLHttpClient.execute(filePost);
    if (httpResponseCallback != null) {
        try {
            httpResponseCallback.onResponse(execute);
        } catch (Throwable th) {
            sSLHttpClient.getConnectionManager().shutdown();
        }
    }
    sSLHttpClient.getConnectionManager().shutdown();
    Ln.i("use time: " + (System.currentTimeMillis() - currentTimeMillis), new Object[0]);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:56,代码来源:NetworkHelper.java

示例6: jsonPost

import org.apache.http.params.HttpParams; //导入方法依赖的package包/类
public String jsonPost(String str, ArrayList<KVPair<String>> arrayList,
                       ArrayList<KVPair<String>> arrayList2, ArrayList<KVPair<?>> arrayList3)
        throws Throwable {
    long currentTimeMillis = System.currentTimeMillis();
    Ln.i("jsonPost: " + str, new Object[0]);
    HttpUriRequest httpPost = new HttpPost(str);
    StringPart stringPart = new StringPart();
    if (arrayList != null) {
        HashMap hashMap = new HashMap();
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            KVPair kVPair = (KVPair) it.next();
            hashMap.put(kVPair.name, kVPair.value);
        }
        stringPart.append(new Hashon().fromHashMap(hashMap));
    }
    HttpEntity inputStreamEntity = stringPart.getInputStreamEntity();
    inputStreamEntity.setContentType("application/json");
    httpPost.setEntity(inputStreamEntity);
    if (arrayList2 != null) {
        Iterator it2 = arrayList2.iterator();
        while (it2.hasNext()) {
            kVPair = (KVPair) it2.next();
            httpPost.setHeader(kVPair.name, (String) kVPair.value);
        }
    }
    HttpParams basicHttpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(basicHttpParams, connectionTimeout);
    HttpConnectionParams.setSoTimeout(basicHttpParams, readTimout);
    if (arrayList3 != null) {
        Iterator it3 = arrayList3.iterator();
        while (it3.hasNext()) {
            kVPair = (KVPair) it3.next();
            try {
                basicHttpParams.setIntParameter(kVPair.name, R.parseInt(String.valueOf(kVPair
                        .value)));
            } catch (Exception e) {
            }
        }
    }
    httpPost.setParams(basicHttpParams);
    HttpClient sSLHttpClient = str.startsWith("https://") ? getSSLHttpClient() : new
            DefaultHttpClient();
    HttpResponse execute = sSLHttpClient.execute(httpPost);
    int statusCode = execute.getStatusLine().getStatusCode();
    if (statusCode == 200 || statusCode == 201) {
        String entityUtils = EntityUtils.toString(execute.getEntity(), Constants.UTF_8);
        sSLHttpClient.getConnectionManager().shutdown();
        Ln.i("use time: " + (System.currentTimeMillis() - currentTimeMillis), new Object[0]);
        return entityUtils;
    }
    entityUtils = EntityUtils.toString(execute.getEntity(), Constants.UTF_8);
    HashMap hashMap2 = new HashMap();
    hashMap2.put("error", entityUtils);
    hashMap2.put("status", Integer.valueOf(statusCode));
    sSLHttpClient.getConnectionManager().shutdown();
    throw new Throwable(new Hashon().fromHashMap(hashMap2));
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:59,代码来源:NetworkHelper.java


注:本文中的org.apache.http.params.HttpParams.setIntParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。