本文整理匯總了Java中org.apache.http.client.methods.HttpGet.releaseConnection方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpGet.releaseConnection方法的具體用法?Java HttpGet.releaseConnection怎麽用?Java HttpGet.releaseConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.methods.HttpGet
的用法示例。
在下文中一共展示了HttpGet.releaseConnection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
@Override
public T execute() throws ClientProtocolException, IOException {
HttpGet get = new HttpGet(InstagramConstants.apiUrl + getUrl());
get.addHeader("Connection", "close");
get.addHeader("Accept", "*/*");
get.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
get.addHeader("Cookie2", "$Version=1");
get.addHeader("Accept-Language", "en-US");
get.addHeader("User-Agent", InstagramConstants.userAgent);
HttpResponse response = InstagramContextHolder.getContext().getHttpClient().execute(get);
int resultCode = response.getStatusLine().getStatusCode();
String content = EntityUtils.toString(response.getEntity());
get.releaseConnection();
return parseResult(resultCode, content);
}
示例2: retrieveGithubUser
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
private GithubUser retrieveGithubUser(String loginName, char[] token) throws GithubAuthenticationException {
try {
HttpGet userRequest = new HttpGet(configuration.getGithubUserUri());
userRequest.addHeader(constructGithubAuthorizationHeader(token));
HttpResponse userResponse = client.execute(userRequest);
if (userResponse.getStatusLine().getStatusCode() != 200) {
LOGGER.warn("Authentication failed, status code was {}",
userResponse.getStatusLine().getStatusCode());
userRequest.releaseConnection();
throw new GithubAuthenticationException("Authentication failed.");
}
GithubUser githubUser = mapper.readValue(new InputStreamReader(userResponse.getEntity().getContent()), GithubUser.class);
if (!loginName.equals(githubUser.getLogin())){
throw new GithubAuthenticationException("Given username does not match Github Username!");
}
return githubUser;
} catch (IOException e) {
throw new GithubAuthenticationException(e);
}
}
示例3: generateRolesFromGithubOrgMemberships
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
private Set<String> generateRolesFromGithubOrgMemberships(char[] token) throws GithubAuthenticationException{
HttpGet teamsRequest = new HttpGet(configuration.getGithubUserTeamsUri());
teamsRequest.addHeader(constructGithubAuthorizationHeader(token));
HttpResponse teamsResponse;
Set<GithubTeam> teams;
try {
teamsResponse = client.execute(teamsRequest);
teams = mapper.readValue(new InputStreamReader(teamsResponse.getEntity().getContent()), new TypeReference<Set<GithubTeam>>() {});
} catch (IOException e) {
teamsRequest.releaseConnection();
throw new GithubAuthenticationException(e);
}
return teams.stream().map(this::mapGithubTeamToNexusRole).collect(Collectors.toSet());
}
示例4: getVersion
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
/**
* Returns the ApIOmat version string
*
* @return version string
*/
public String getVersion( )
{
final HttpGet request = new HttpGet( this.yambasBase );
try
{
request.addHeader( "Accept", "application/json" );
final HttpResponse resp = this.client.execute( request );
final JSONObject json = new JSONObject( EntityUtils.toString( resp.getEntity( ) ) );
request.releaseConnection( );
return json.getString( "version" );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
示例5: getMethodGetContent
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
/**
* HttpClient get方法請求返回Entity
*
* @param address 地址
* @param headerParams 請求頭
* @return
* @throws Exception
*/
public static String getMethodGetContent(String address, Map<String, String> headerParams) throws Exception {
HttpGet get = new HttpGet(address);
for (Map.Entry<String, String> entry : headerParams.entrySet()) {
get.setHeader(entry.getKey(), entry.getValue());
}
try {
HttpResponse response = CLIENT.execute(get);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
int code = response.getStatusLine().getStatusCode();
throw new RuntimeException("HttpGet Access Fail , Return Code(" + code + ")");
}
response.getEntity().getContent();
byte[] bytes = convertEntityToBytes(response.getEntity());
return new String(bytes, "utf-8");
} finally {
if (get != null) {
get.releaseConnection();
}
}
}
示例6: execute
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
@Override
public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String queryParam) throws WxErrorException, IOException {
if (queryParam != null) {
if (uri.indexOf('?') == -1) {
uri += '?';
}
uri += uri.endsWith("?") ? queryParam : '&' + queryParam;
}
HttpGet httpGet = new HttpGet(uri);
if (httpProxy != null) {
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
httpGet.setConfig(config);
}
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
WxError error = WxError.fromJson(responseContent);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return responseContent;
} finally {
httpGet.releaseConnection();
}
}
示例7: doGetJson
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
public static JSONObject doGetJson(String url) {
JSONObject jsonObject = null;
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet= new HttpGet(url);
try {
HttpResponse response=httpClient.execute(httpGet);
HttpEntity enyity=response.getEntity();
if (enyity != null) {
String result=EntityUtils.toString(enyity,"UTF-8");
logger.info("JSONObject: {}",result);
jsonObject=JSONObject.fromObject(result);
}
httpGet.releaseConnection();
} catch (IOException e) {
logger.error("方法doGetJson失敗:{}", e.getMessage());
}
return jsonObject;
}
示例8: execute
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
@Override
public T execute() throws ClientProtocolException, IOException {
HttpGet get = new HttpGet(InstagramConstants.API_URL + getUrl());
get.addHeader("Connection", "close");
get.addHeader("Accept", "*/*");
get.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
get.addHeader("Cookie2", "$Version=1");
get.addHeader("Accept-Language", "en-US");
get.addHeader("User-Agent", InstagramConstants.USER_AGENT);
HttpResponse response = api.getClient().execute(get);
api.setLastResponse(response);
int resultCode = response.getStatusLine().getStatusCode();
String content = EntityUtils.toString(response.getEntity());
get.releaseConnection();
return parseResult(resultCode, content);
}
示例9: execute
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
@Override
public T execute() throws ClientProtocolException, IOException {
HttpGet get = new HttpGet(JiphyConstants.API_URL + getUrl());
get.addHeader("Connection", "close");
get.addHeader("Accept", "*/*");
get.addHeader("Content-Type", "application/json; charset=UTF-8");
get.addHeader("Accept-Language", "en-US");
HttpResponse response = api.getClient().execute(get);
api.setLastResponse(response);
int resultCode = response.getStatusLine().getStatusCode();
String content = EntityUtils.toString(response.getEntity());
get.releaseConnection();
return parseResult(resultCode, content);
}
示例10: getAccessToken
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
@Override
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
if (forceRefresh) {
this.configStorage.expireAccessToken();
}
if (this.configStorage.isAccessTokenExpired()) {
synchronized (this.globalAccessTokenRefreshLock) {
if (this.configStorage.isAccessTokenExpired()) {
String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"
+ "&corpid=" + this.configStorage.getCorpId()
+ "&corpsecret=" + this.configStorage.getCorpSecret();
try {
HttpGet httpGet = new HttpGet(url);
if (this.httpProxy != null) {
RequestConfig config = RequestConfig.custom()
.setProxy(this.httpProxy).build();
httpGet.setConfig(config);
}
String resultContent = null;
try (CloseableHttpClient httpclient = getHttpclient();
CloseableHttpResponse response = httpclient.execute(httpGet)) {
resultContent = new BasicResponseHandler().handleResponse(response);
} finally {
httpGet.releaseConnection();
}
WxError error = WxError.fromJson(resultContent);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
this.configStorage.updateAccessToken(
accessToken.getAccessToken(), accessToken.getExpiresIn());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
return this.configStorage.getAccessToken();
}
示例11: httpCall
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
/**
* 係統使用為外部提供接口 httpCall
*
* @param apiUrl
* url路徑
* @param method
* 提交方式 POST或GET 默認為get提交方式
* @return
*/
@Override
public String httpCall(String apiUrl, String method) {
String result = "";
if (method != null && "POST".equals(method.toUpperCase())) {
HttpPost httpPost = getHttpPost();
result = httpPostCall(apiUrl, httpPost);
httpPost.releaseConnection();
} else {
HttpGet httpGet = getHttpGet();
result = httpGetCall(apiUrl, httpGet);
httpGet.releaseConnection();
}
return result;
}
示例12: getResponse
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
@Override
public HttpCallObj getResponse(String apiUrl, String method) throws IOException {
HttpCallObj result = new HttpCallObj();
if (method != null && "POST".equals(method.toUpperCase())) {
HttpPost httpPost = getHttpPost();
result = responseBytes(getPostResponse(apiUrl, httpPost));
httpPost.releaseConnection();
} else {
HttpGet httpGet = getHttpGet();
result = responseBytes(getGetResponse(apiUrl, httpGet));
httpGet.releaseConnection();
}
return result;
}
示例13: downloadFile
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
@Override
public byte[] downloadFile(String fileUrl) throws IllegalStateException {
HttpResponse response = null;
HttpGet httpGet = new HttpGet(fileUrl);
try {
response = httpClient.execute(httpGet);
String statusCode = String.valueOf(response.getStatusLine().getStatusCode());
if (statusCode.indexOf("20") == 0) {
HttpEntity entity = response.getEntity();
InputStream fileStream = entity.getContent();
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[1024];
int rc = 0;
while ((rc = fileStream.read(buff, 0, 1024)) > 0) {
swapStream.write(buff, 0, rc);
}
swapStream.flush();
return swapStream.toByteArray();
} else {
throw new IllegalStateException("返回狀態碼:[" + statusCode + "]");
}
} catch (Exception e) {
LOG.error(e.getMessage());
} finally {
httpGet.releaseConnection();
}
return null;
}
示例14: sendGETUnchecked
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
protected HttpResponse sendGETUnchecked(UriTemplate schema, Map<String, String> params) {
HttpResponse httpResponse;
try {
HttpGet req = new HttpGet(schema.buildUri(environment.baseURI, params));
httpResponse = this.httpClient.execute(req);
// Buffer the response entity in memory so we can release the connection safely
HttpEntity old = httpResponse.getEntity();
EntityUtils.updateEntity(httpResponse, new StringEntity(EntityUtils.toString(old)));
req.releaseConnection();
} catch (IOException e) {
throw new WebmateApiClientException("Error sending GET to webmate API", e);
}
return httpResponse;
}
示例15: getResponse
import org.apache.http.client.methods.HttpGet; //導入方法依賴的package包/類
@Override
public HttpCallObj getResponse(String apiUrl, String method, Map<String, String> parameMap) throws IOException {
HttpCallObj result = new HttpCallObj();
if (parameMap != null) {
StringBuilder urlParame = new StringBuilder();
Iterator<String> parameKey = parameMap.keySet().iterator();
while (parameKey.hasNext()) {
String parameName = parameKey.next();
String parameVal = parameMap.get(parameName);
if (!StrUtil.isBlank(parameVal)) {
urlParame.append(parameName);
urlParame.append("=");
urlParame.append(parameVal);
urlParame.append("&");
}
}
if (urlParame.length() > 0) {
if (urlParame.lastIndexOf("&") == urlParame.length() - 1) {
urlParame.deleteCharAt(urlParame.length() - 1);
}
if (apiUrl.indexOf("?") != -1) {
apiUrl += "&" + urlParame.toString();
} else {
apiUrl += "?" + urlParame.toString();
}
}
}
if (method != null && "POST".equals(method.toUpperCase())) {
HttpPost httpPost = getHttpPost();
result = responseBytes(getPostResponse(apiUrl, httpPost));
httpPost.releaseConnection();
} else {
HttpGet httpGet = getHttpGet();
result = responseBytes(getGetResponse(apiUrl, httpGet));
httpGet.releaseConnection();
}
return result;
}