本文整理汇总了Java中org.apache.http.util.EntityUtils.consume方法的典型用法代码示例。如果您正苦于以下问题:Java EntityUtils.consume方法的具体用法?Java EntityUtils.consume怎么用?Java EntityUtils.consume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.util.EntityUtils
的用法示例。
在下文中一共展示了EntityUtils.consume方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postRecommendationReaction
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
public static boolean postRecommendationReaction(@NotNull String lessonId, @NotNull String user, int reaction) {
final HttpPost post = new HttpPost(EduStepicNames.STEPIC_API_URL + EduStepicNames.RECOMMENDATION_REACTIONS_URL);
final String json = new Gson()
.toJson(new StepicWrappers.RecommendationReactionWrapper(new StepicWrappers.RecommendationReaction(reaction, user, lessonId)));
post.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
if (client == null) return false;
setTimeout(post);
try {
final CloseableHttpResponse execute = client.execute(post);
final int statusCode = execute.getStatusLine().getStatusCode();
final HttpEntity entity = execute.getEntity();
final String entityString = EntityUtils.toString(entity);
EntityUtils.consume(entity);
if (statusCode == HttpStatus.SC_CREATED) {
return true;
}
else {
LOG.warn("Stepic returned non-201 status code: " + statusCode + " " + entityString);
return false;
}
}
catch (IOException e) {
LOG.warn(e.getMessage());
return false;
}
}
示例2: parseResponse
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public JSONObject parseResponse(HttpResponse response) throws Exception {
JSONObject jobj = new JSONObject();
HttpEntity entity = response.getEntity();
String resp;
try {
if (entity != null) {
resp = EntityUtils.toString(entity);
jobj.put("res", resp);
jobj.put("status", response.getStatusLine().getStatusCode());
if (LOGIN_KEY == null) {
setLoginCookie(jobj, response);
}
EntityUtils.consume(entity);
}
} catch (Exception ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
return jobj;
}
示例3: doResponse
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* 处理返回结果数据
*
* @param unitTest
* @param response
* @throws IOException
*/
private static void doResponse(UnitTest unitTest, CloseableHttpResponse response) throws IOException {
int statusCode = response.getStatusLine().getStatusCode();
unitTest.setResponseCode(statusCode);
StringBuffer sb = new StringBuffer();
for (int loop = 0; loop < response.getAllHeaders().length; loop++) {
BufferedHeader header = (BufferedHeader) response
.getAllHeaders()[loop];
if (header.getName().equals("Accept-Charset")) {
continue;
}
sb.append(header.getName() + ":" + header.getValue() + "<br/>");
}
unitTest.setResponseHeader(sb.toString());
HttpEntity entity = response.getEntity();
String result;
if (entity != null) {
result = EntityUtils.toString(entity, "utf-8");
unitTest.setResponseSize(result.getBytes().length);
unitTest.setResponseBody(result);
}
EntityUtils.consume(entity);
response.close();
}
示例4: uncleByBlockNumberAndIndex
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* Returns information about a uncle by block number
* @param blockNumber Block number
* @param index Index
* @return Block information
*/
public Block uncleByBlockNumberAndIndex(BigInteger blockNumber, BigInteger index) {
HttpGet get = new HttpGet(PUBLIC_URL + "?module=proxy&action=eth_getUncleByBlockNumberAndIndex&tag=" + "0x" + blockNumber.toString(16) + "&index=" + "0x" + index.toString(16) + "&apikey=" + API_KEY);
String response = null;
try(CloseableHttpResponse httpResponse = httpClient.execute(get)) {
HttpEntity httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
} catch (IOException e) {
e.printStackTrace();
}
@SuppressWarnings("rawtypes")
ArrayList<CustomNameValuePair<String, CustomNameValuePair>> a = Utility.evaluateExpression(response);
Block current = new Block();
for(int j = 0; j < a.size(); j++)
current.addData(a.get(j));
return current;
}
示例5: lastEtherPrice
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* Returns the latest Ether price in Wei
* @return Latest Ether price in Wei
*/
public EtherPrice lastEtherPrice() {
HttpGet get = new HttpGet(PUBLIC_URL + "?module=stats&action=ethprice&apikey=" + API_KEY);
String response = null;
try(CloseableHttpResponse httpResponse = httpClient.execute(get)) {
HttpEntity httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
} catch (IOException e) {
e.printStackTrace();
}
@SuppressWarnings("rawtypes")
ArrayList<CustomNameValuePair<String, CustomNameValuePair>> a = Utility.evaluateExpression(response);
EtherPrice current = new EtherPrice();
for(int j = 0; j < a.size(); j++)
current.addData(a.get(j));
return current;
}
示例6: close
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
@Override
public void close() {
// Release underlying connection back to the connection manager
try {
try {
// Attempt to keep connection alive by consuming its remaining content
EntityUtils.consume(this.httpResponse.getEntity());
}
finally {
this.httpResponse.close();
}
}
catch (IOException ex) {
// Ignore exception on close...
}
}
示例7: jButtonDetenerActionPerformed
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
private void jButtonDetenerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDetenerActionPerformed
try {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://" + ip + ":8080/proyecto-gson/servidordetener?id=" + user.getId());
CloseableHttpResponse response = httpclient.execute(httppost);
System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);
response.close();
} catch (IOException ex) {
Logger.getLogger(VentanaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
}
user = null;
jLabel1.setForeground(Color.red);
url.setText("");
jlabelSQL.setText("");
this.setTitle("App [ID:?]");
}
示例8: doDownload
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* 通过httpClient get 下载文件
*
* @param url 网络文件全路径
* @param savePath 保存文件全路径
* @return 状态码 200表示成功
*/
public static int doDownload(String url, String savePath) {
// 创建默认的HttpClient实例.
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
HttpGet get = new HttpGet(url);
CloseableHttpResponse closeableHttpResponse = null;
try {
closeableHttpResponse = closeableHttpClient.execute(get);
HttpEntity entity = closeableHttpResponse.getEntity();
if (entity != null) {
InputStream in = entity.getContent();
FileOutputStream out = new FileOutputStream(savePath);
IOUtils.copy(in, out);
EntityUtils.consume(entity);
closeableHttpResponse.close();
}
int code = closeableHttpResponse.getStatusLine().getStatusCode();
closeableHttpClient.close();
return code;
} catch (IOException e) {
e.printStackTrace();
} finally {
closeSource(closeableHttpClient, closeableHttpResponse);
}
return 0;
}
示例9: getModSlug0
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
@Nullable
private String getModSlug0(int id)
{
try
{
log.debug("Getting mod slug from server...");
URI uri = getURI(CURSEFORGE_URL, String.format(PROJECT_PATH, id), null);
HttpGet request = new HttpGet(uri.toURL().toString());
HttpContext context = new BasicHttpContext();
HttpResponse response = http.execute(request, context);
EntityUtils.consume(response.getEntity());
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
HttpHost currentHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
String currentUrl = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString() : (currentHost.toURI() + currentReq.getURI());
Splitter splitter = Splitter.on('/').omitEmptyStrings();
List<String> pathParts = splitter.splitToList(currentUrl);
return pathParts.get(pathParts.size() - 1);
}
catch (Exception e)
{
log.error("Failed to perform request from CurseForge site.", e);
return null;
}
}
示例10: getConfFromHadoop
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* Get the job conf from hadoop name node
* @param hadoopJobId
* @return the lineage info
* @throws java.io.IOException
*/
public String getConfFromHadoop(String hadoopJobId)
throws Exception {
String url = this.serverURL + "/" + hadoopJobId + "/conf";
logger.debug("get job conf from : {}", url);
HttpUriRequest request = new HttpGet(url);
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
String confResult = EntityUtils.toString(entity);
EntityUtils.consume(entity);
return confResult;
}
示例11: getCheckResults
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
@NotNull
private static StepicWrappers.ResultSubmissionWrapper getCheckResults(@NotNull CloseableHttpClient client,
@NotNull StepicWrappers.ResultSubmissionWrapper wrapper,
int attemptId,
int userId) {
try {
while (wrapper.submissions.length == 1 && wrapper.submissions[0].status.equals("evaluation")) {
TimeUnit.MILLISECONDS.sleep(500);
final URI submissionURI = new URIBuilder(EduStepicNames.STEPIC_API_URL + EduStepicNames.SUBMISSIONS)
.addParameter("attempt", String.valueOf(attemptId))
.addParameter("order", "desc")
.addParameter("user", String.valueOf(userId))
.build();
final HttpGet httpGet = new HttpGet(submissionURI);
setTimeout(httpGet);
final CloseableHttpResponse httpResponse = client.execute(httpGet);
final HttpEntity entity = httpResponse.getEntity();
final String entityString = EntityUtils.toString(entity);
EntityUtils.consume(entity);
wrapper = new Gson().fromJson(entityString, StepicWrappers.ResultSubmissionWrapper.class);
}
}
catch (InterruptedException | URISyntaxException | IOException e) {
LOG.warn(e.getMessage());
}
return wrapper;
}
示例12: sendRawTransaction
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* Creates new message call transaction or a contract creation for signed transactions
* @param txHex Raw hex encoded transaction to send
* @return Error message or call result
*/
public String sendRawTransaction(String txHex) {
HttpGet get = new HttpGet(PUBLIC_URL + "?module=proxy&action=eth_sendRawTransaction&hex=" + txHex + "&apikey=" + API_KEY);
String response = null;
try(CloseableHttpResponse httpResponse = httpClient.execute(get)) {
HttpEntity httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
} catch (IOException e) {
e.printStackTrace();
}
@SuppressWarnings("rawtypes")
ArrayList<CustomNameValuePair<String, CustomNameValuePair>> a = Utility.evaluateExpression(response);
for(int j = 0; j < a.size(); j++) {
if(a.get(j).getName().toString().equals("message"))
return a.get(j).getValue().toString();
else if(a.get(j).getName().toString().equals("result"))
return a.get(j).getValue().toString();
}
return null; // Null should not be expected when API is functional
}
示例13: discardContent
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
public void discardContent(){
try {
if (entity != null) {
EntityUtils.consume(entity);
}
}catch (Exception e){
logger.warn("Unexpected error occurred while trying to discard content", e);
}
}
示例14: retrieveEventData
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
/**
* Retrieves event data.
*
* @param eventId
* event id which data will be retrieved
* @return event data.
* @throws UnsuccessfulOperationException
*/
public AsnDataDto retrieveEventData(String eventId) throws UnsuccessfulOperationException {
AsnDataDto result = null;
String retrieveEventDataPath = MessageFormat.format(RETRIEVE_EVENT_DATA_PATH, flowExtensionId, eventId);
Map<String, String> headers = new HashMap<String, String>();
headers.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
logger.debug(DEBUG_CALLING_URI_MESSAGE, retrieveEventDataPath);
try (CloseableHttpResponse retrieveEventDataResponse = openApiEndpoint.executeHttpGet(retrieveEventDataPath,
headers)) {
int retrieveEventDataResponseStatusCode = HttpResponseUtils
.validateHttpStatusResponse(retrieveEventDataResponse, HttpStatus.SC_OK);
logger.debug(DEBUG_CALLING_URI_RETURNED_STATUS_MESSAGE, retrieveEventDataPath,
retrieveEventDataResponseStatusCode);
HttpEntity retrieveEventDataResponseEntity = retrieveEventDataResponse.getEntity();
if (retrieveEventDataResponseEntity != null) {
try {
result = HttpResponseUtils.deserialize(retrieveEventDataResponseEntity, AsnDataDto.class);
} finally {
EntityUtils.consume(retrieveEventDataResponseEntity);
}
}
} catch (IOException | HttpResponseException e) {
String errorMessage = MessageFormat.format(ERROR_PROBLEM_OCCURED_WHILE_CALLING_URI_MESSAGE,
retrieveEventDataPath);
logger.error(errorMessage);
throw new UnsuccessfulOperationException(errorMessage, e);
}
logger.debug(DEBUG_CALLED_URI_SUCCESSFULLY_MESSAGE, retrieveEventDataPath);
return result;
}
开发者ID:SAP,项目名称:cloud-ariba-partner-flow-extension-ext,代码行数:44,代码来源:PartnerFlowExtensionApiFacade.java
示例15: getFromStepic
import org.apache.http.util.EntityUtils; //导入方法依赖的package包/类
static <T> T getFromStepic(String link, final Class<T> container, @NotNull final CloseableHttpClient client) throws IOException {
if (!link.startsWith("/")) link = "/" + link;
final HttpGet request = new HttpGet(EduStepicNames.STEPIC_API_URL + link);
final CloseableHttpResponse response = client.execute(request);
final StatusLine statusLine = response.getStatusLine();
final HttpEntity responseEntity = response.getEntity();
final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
EntityUtils.consume(responseEntity);
if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
throw new IOException("Stepic returned non 200 status code " + responseString);
}
return deserializeStepicResponse(container, responseString);
}