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

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

本文整理了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

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

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

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

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

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

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

/**
  * Runs the provided request and returns the response.
  */
 public Response execute(Request request) throws IOException {
  return executor.execute(request);
 }
}

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

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

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

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

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

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

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

/**
   * Issue a PUT to the given URL without a body.
   */
  public static HttpResp put(final String url) throws IOException {
    return Http.toHttpResp(executor.execute(Request.Put(url))
        .returnResponse()
    );
  }
}

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

@Override
public void run() {
  try {
    final Response response = this.executor.execute(this.request);
    final T result = response.handleResponse(this.handler);
    this.future.completed(result);
  } catch (final Exception ex) {
    this.future.failed(ex);
  }
}

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

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

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

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

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

public void run() {
  try {
    final Response response = this.executor.execute(this.request);
    final T result = response.handleResponse(this.handler);
    this.future.completed(result);
  } catch (final Exception ex) {
    this.future.failed(ex);
  }
}

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

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

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

/**
 * Executes Http Put request
 * 
 * @param resource REST API resource. E. g. issue/{issueId}
 * @param body message body
 * @return response status code and body
 * @throws ClientProtocolException
 * @throws IOException
 */
public JiraResponse put(String resource, String body) throws IOException {
  Request put = Request.Put(hostPort + resource).bodyString(body, contentType);
  for (Header header : headers) {
    put.addHeader(header);
  }
  executor.clearCookies();
  Response response = executor.execute(put);
  HttpResponse httpResponse = response.returnResponse();
  StatusLine statusLine = httpResponse.getStatusLine();
  int statusCode = statusLine.getStatusCode();
  HttpEntity entity = httpResponse.getEntity();
  String entityBody = "";
  if (entity != null && statusCode != SC_UNAUTHORIZED) {
    entityBody = EntityUtils.toString(entity);
  }
  return new JiraResponse(statusCode, entityBody);
}

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

/**
 * Executes Http Put request
 * 
 * @param resource REST API resource. E. g. issue/{issueId}
 * @param body message body
 * @return response status code and body
 * @throws ClientProtocolException
 * @throws IOException
 */
public JiraResponse put(String resource, String body) throws IOException {
  Request put = Request.Put(hostPort + resource).bodyString(body, contentType);
  for (Header header : headers) {
    put.addHeader(header);
  }
  executor.clearCookies();
  Response response = executor.execute(put);
  HttpResponse httpResponse = response.returnResponse();
  StatusLine statusLine = httpResponse.getStatusLine();
  int statusCode = statusLine.getStatusCode();
  HttpEntity entity = httpResponse.getEntity();
  String entityBody = "";
  if (entity != null && statusCode != SC_UNAUTHORIZED) {
    entityBody = EntityUtils.toString(entity);
  }
  return new JiraResponse(statusCode, entityBody);
}

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

/**
 * Executes Http Post request
 * 
 * @param resource REST API resource. E. g. issue/{issueId}
 * @param body message body
 * @return response status code and body
 * @throws ClientProtocolException
 * @throws IOException
 */
public JiraResponse post(String resource, String body) throws IOException {
  Request post = Request.Post(hostPort + resource).bodyString(body, contentType);
  for (Header header : headers) {
    post.addHeader(header);
  }
  executor.clearCookies();
  Response response = executor.execute(post);
  HttpResponse httpResponse = response.returnResponse();
  StatusLine statusLine = httpResponse.getStatusLine();
  int statusCode = statusLine.getStatusCode();
  HttpEntity entity = httpResponse.getEntity();
  String entityBody = "";
  if (entity != null && statusCode != SC_UNAUTHORIZED) {
    entityBody = EntityUtils.toString(entity);
  }
  return new JiraResponse(statusCode, entityBody);
}

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

public static InputStream fetchNextPackage(Executor executor, URI distributionURI, HttpConfiguration httpConfiguration)
    throws URISyntaxException, IOException {
  URI fetchUri = getFetchUri(distributionURI);
  Request fetchReq = Request.Post(fetchUri)
      .connectTimeout(httpConfiguration.getConnectTimeout())
      .socketTimeout(httpConfiguration.getSocketTimeout())
      .addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE)
      .useExpectContinue();
  HttpResponse httpResponse = executor.execute(fetchReq).returnResponse();
  if (httpResponse.getStatusLine().getStatusCode() != 200) {
    return null;
  }
  HttpEntity entity = httpResponse.getEntity();
  return entity.getContent();
}

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

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

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

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

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

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

相关文章

微信公众号

最新文章

更多