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


Java HttpGet.releaseConnection方法代码示例

本文整理汇总了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);
}
 
开发者ID:Cinderpup,项目名称:RoboInsta,代码行数:20,代码来源:InstagramGetRequest.java

示例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);
    }
}
 
开发者ID:larscheid-schmitzhermes,项目名称:nexus3-github-oauth-plugin,代码行数:25,代码来源:GithubApiClient.java

示例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());
}
 
开发者ID:larscheid-schmitzhermes,项目名称:nexus3-github-oauth-plugin,代码行数:17,代码来源:GithubApiClient.java

示例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;
}
 
开发者ID:ApinautenGmbH,项目名称:integration-test-helper,代码行数:23,代码来源:AomHttpClient.java

示例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();
        }
    }
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:29,代码来源:HttpClientUtils.java

示例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();
  }
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:26,代码来源:SimpleGetRequestExecutor.java

示例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;
}
 
开发者ID:SnackMen,项目名称:DanmuChat,代码行数:20,代码来源:JsonObject.java

示例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);
}
 
开发者ID:brunocvcunha,项目名称:instagram4j,代码行数:21,代码来源:InstagramGetRequest.java

示例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);
}
 
开发者ID:brunocvcunha,项目名称:jiphy,代码行数:19,代码来源:JiphyGetRequest.java

示例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();
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:41,代码来源:WxCpServiceImpl.java

示例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;
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:24,代码来源:HttpCallSSL.java

示例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;
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:15,代码来源:HttpCallSSL.java

示例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;
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:29,代码来源:HttpCallSSL.java

示例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;
}
 
开发者ID:webmate-io,项目名称:webmate-sdk-java,代码行数:15,代码来源:WebmateApiClient.java

示例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;
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:40,代码来源:HttpCallImpl.java


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