org.apache.http.client.fluent.Executor.execute()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(273)

本文整理了Java中org.apache.http.client.fluent.Executor.execute()方法的一些代码示例,展示了Executor.execute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Executor.execute()方法的具体详情如下:
包路径:org.apache.http.client.fluent.Executor
类名称:Executor
方法名:execute

Executor.execute介绍

[英]Executes the request. Please Note that response content must be processed or discarded using Response#discardContent(), otherwise the connection used for the request might not be released to the pool.
[中]执行请求。请注意,必须使用response#discardContent()处理或丢弃响应内容,否则可能无法将用于请求的连接释放到池中。

代码示例

代码示例来源:origin: dreamhead/moco

  1. public HttpResponse execute(final Request request) throws IOException {
  2. return executor.execute(request).returnResponse();
  3. }

代码示例来源:origin: dreamhead/moco

  1. public String executeAsString(final Request request) throws IOException {
  2. return executor.execute(request).returnContent().asString();
  3. }

代码示例来源:origin: jooby-project/jooby

  1. public Response execute() throws Exception {
  2. this.rsp = executor.execute(req).returnResponse();
  3. return new Response(server, rsp);
  4. }

代码示例来源:origin: mesosphere/dcos-commons

  1. /**
  2. * Runs the provided request and returns the response.
  3. */
  4. public Response execute(Request request) throws IOException {
  5. return executor.execute(request);
  6. }
  7. }

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

  1. Request request = httpClientFactory.get("/speech-to-text/api/v1/recognitions/" + jobId);
  2. try {
  3. JsonObject json = (JsonObject) httpClientFactory.getExecutor().execute(request).handleResponse(HANDLER);

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

  1. @Override
  2. public String startTranscriptionJob(InputStream stream, String mimeType) {
  3. Request request = httpClientFactory.post("/speech-to-text/api/v1/recognitions?continuous=true&timestamps=true")
  4. .addHeader("Content-Type", mimeType)
  5. .bodyStream(stream);
  6. try {
  7. JsonObject json = (JsonObject) httpClientFactory.getExecutor().execute(request).handleResponse(HANDLER);
  8. Gson gson = new Gson();
  9. log.trace("content: {}", gson.toJson(json));
  10. return json.get("id").getAsString();
  11. } catch (IOException e) {
  12. log.error("error submitting job", e);
  13. return null;
  14. }
  15. }

代码示例来源:origin: org.apache.sling/org.apache.sling.distribution.core

  1. public static boolean deletePackage(Executor executor, URI distributionURI, String remotePackageId) throws URISyntaxException, IOException {
  2. URI deleteUri = getDeleteUri(distributionURI, remotePackageId);
  3. Request deleteReq = Request.Post(deleteUri).useExpectContinue();
  4. HttpResponse httpResponse = executor.execute(deleteReq).returnResponse();
  5. return httpResponse.getStatusLine().getStatusCode() == 200;
  6. }

代码示例来源:origin: com.github.dcshock/consul-rest-client

  1. /**
  2. * Issue a PUT to the given URL without a body.
  3. */
  4. public static HttpResp put(final String url) throws IOException {
  5. return Http.toHttpResp(executor.execute(Request.Put(url))
  6. .returnResponse()
  7. );
  8. }
  9. }

代码示例来源:origin: org.apache.httpcomponents/fluent-hc

  1. @Override
  2. public void run() {
  3. try {
  4. final Response response = this.executor.execute(this.request);
  5. final T result = response.handleResponse(this.handler);
  6. this.future.completed(result);
  7. } catch (final Exception ex) {
  8. this.future.failed(ex);
  9. }
  10. }

代码示例来源:origin: com.github.dcshock/consul-rest-client

  1. /**
  2. * Issue a GET to the given URL.
  3. */
  4. public static HttpResp get(final String url) throws IOException {
  5. return Http.toHttpResp(executor.execute(Request.Get(url))
  6. .returnResponse());
  7. }

代码示例来源:origin: com.github.dcshock/consul-rest-client

  1. /**
  2. * Issue a DELETE to the given URL.
  3. */
  4. public static HttpResp delete(final String url) throws IOException {
  5. return Http.toHttpResp(executor.execute(Request.Delete(url))
  6. .returnResponse());
  7. }

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpclient

  1. public void run() {
  2. try {
  3. final Response response = this.executor.execute(this.request);
  4. final T result = response.handleResponse(this.handler);
  5. this.future.completed(result);
  6. } catch (final Exception ex) {
  7. this.future.failed(ex);
  8. }
  9. }

代码示例来源:origin: com.github.dcshock/consul-rest-client

  1. /**
  2. * Issue a PUT to the given URL with a JSON body.
  3. */
  4. public static HttpResp put(final String url, final String body) throws IOException {
  5. return Http.toHttpResp(executor.execute(Request.Put(url)
  6. .bodyString(body, ContentType.APPLICATION_JSON))
  7. .returnResponse()
  8. );
  9. }

代码示例来源:origin: org.talend.components/components-jira

  1. /**
  2. * Executes Http Put request
  3. *
  4. * @param resource REST API resource. E. g. issue/{issueId}
  5. * @param body message body
  6. * @return response status code and body
  7. * @throws ClientProtocolException
  8. * @throws IOException
  9. */
  10. public JiraResponse put(String resource, String body) throws IOException {
  11. Request put = Request.Put(hostPort + resource).bodyString(body, contentType);
  12. for (Header header : headers) {
  13. put.addHeader(header);
  14. }
  15. executor.clearCookies();
  16. Response response = executor.execute(put);
  17. HttpResponse httpResponse = response.returnResponse();
  18. StatusLine statusLine = httpResponse.getStatusLine();
  19. int statusCode = statusLine.getStatusCode();
  20. HttpEntity entity = httpResponse.getEntity();
  21. String entityBody = "";
  22. if (entity != null && statusCode != SC_UNAUTHORIZED) {
  23. entityBody = EntityUtils.toString(entity);
  24. }
  25. return new JiraResponse(statusCode, entityBody);
  26. }

代码示例来源:origin: Talend/components

  1. /**
  2. * Executes Http Put request
  3. *
  4. * @param resource REST API resource. E. g. issue/{issueId}
  5. * @param body message body
  6. * @return response status code and body
  7. * @throws ClientProtocolException
  8. * @throws IOException
  9. */
  10. public JiraResponse put(String resource, String body) throws IOException {
  11. Request put = Request.Put(hostPort + resource).bodyString(body, contentType);
  12. for (Header header : headers) {
  13. put.addHeader(header);
  14. }
  15. executor.clearCookies();
  16. Response response = executor.execute(put);
  17. HttpResponse httpResponse = response.returnResponse();
  18. StatusLine statusLine = httpResponse.getStatusLine();
  19. int statusCode = statusLine.getStatusCode();
  20. HttpEntity entity = httpResponse.getEntity();
  21. String entityBody = "";
  22. if (entity != null && statusCode != SC_UNAUTHORIZED) {
  23. entityBody = EntityUtils.toString(entity);
  24. }
  25. return new JiraResponse(statusCode, entityBody);
  26. }

代码示例来源:origin: org.talend.components/components-jira

  1. /**
  2. * Executes Http Post request
  3. *
  4. * @param resource REST API resource. E. g. issue/{issueId}
  5. * @param body message body
  6. * @return response status code and body
  7. * @throws ClientProtocolException
  8. * @throws IOException
  9. */
  10. public JiraResponse post(String resource, String body) throws IOException {
  11. Request post = Request.Post(hostPort + resource).bodyString(body, contentType);
  12. for (Header header : headers) {
  13. post.addHeader(header);
  14. }
  15. executor.clearCookies();
  16. Response response = executor.execute(post);
  17. HttpResponse httpResponse = response.returnResponse();
  18. StatusLine statusLine = httpResponse.getStatusLine();
  19. int statusCode = statusLine.getStatusCode();
  20. HttpEntity entity = httpResponse.getEntity();
  21. String entityBody = "";
  22. if (entity != null && statusCode != SC_UNAUTHORIZED) {
  23. entityBody = EntityUtils.toString(entity);
  24. }
  25. return new JiraResponse(statusCode, entityBody);
  26. }

代码示例来源:origin: org.apache.sling/org.apache.sling.distribution.core

  1. public static InputStream fetchNextPackage(Executor executor, URI distributionURI, HttpConfiguration httpConfiguration)
  2. throws URISyntaxException, IOException {
  3. URI fetchUri = getFetchUri(distributionURI);
  4. Request fetchReq = Request.Post(fetchUri)
  5. .connectTimeout(httpConfiguration.getConnectTimeout())
  6. .socketTimeout(httpConfiguration.getSocketTimeout())
  7. .addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE)
  8. .useExpectContinue();
  9. HttpResponse httpResponse = executor.execute(fetchReq).returnResponse();
  10. if (httpResponse.getStatusLine().getStatusCode() != 200) {
  11. return null;
  12. }
  13. HttpEntity entity = httpResponse.getEntity();
  14. return entity.getContent();
  15. }

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

  1. @Override
  2. public String startTranscriptionJob(InputStream stream, String mimeType) {
  3. Request request = httpClientFactory.post("/speech-to-text/api/v1/recognitions?continuous=true&timestamps=true").
  4. addHeader("Content-Type", mimeType).
  5. bodyStream(stream);
  6. try {
  7. JSONObject json = httpClientFactory.getExecutor().execute(request).handleResponse(HANDLER);
  8. log.trace("content: {}", json.toString(2));
  9. return json.getString("id");
  10. } catch (Exception e) {
  11. log.error("error submitting job", e);
  12. return null;
  13. }
  14. }

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

  1. @When("^someone upload a content without authentification$")
  2. public void userUploadContentWithoutAuthentification() throws Throwable {
  3. Request request = Request.Post(uploadUri)
  4. .bodyStream(new BufferedInputStream(new ZeroedInputStream(_1M), _1M), org.apache.http.entity.ContentType.DEFAULT_BINARY);
  5. response = Executor.newInstance(HttpClientBuilder.create().disableAutomaticRetries().build()).execute(request).returnResponse();
  6. }

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

  1. @When("^\"([^\"]*)\" upload a content$")
  2. public void userUploadContent(String username) throws Throwable {
  3. AccessToken accessToken = userStepdefs.authenticate(username);
  4. Request request = Request.Post(uploadUri)
  5. .bodyStream(new BufferedInputStream(new ZeroedInputStream(_1M), _1M), org.apache.http.entity.ContentType.DEFAULT_BINARY);
  6. request.addHeader("Authorization", accessToken.serialize());
  7. response = Executor.newInstance(HttpClientBuilder.create().disableAutomaticRetries().build()).execute(request).returnResponse();
  8. }

相关文章