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

x33g5p2x  于2022-01-28 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(214)

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

Request.execute介绍

暂无

代码示例

代码示例来源:origin: twosigma/beakerx

@Override
public String update(String name, String json) {
 try {
  String reply = Request.Post(LOCALHOST + this.context.getPort() + AUTOTRANSLTION)
      .addHeader(AUTHORIZATION, auth())
      .bodyString(createBody(name, json), ContentType.APPLICATION_JSON)
      .execute().returnContent().asString();
  if (!reply.equals("ok")) {
   throw new RuntimeException(reply);
  }
 } catch (Exception e) {
  throw new RuntimeException(e);
 }
 return json;
}

代码示例来源:origin: twosigma/beakerx

private Map getResult(LinkedList<String> parts, String last) throws IOException {
 String uri = getUrl(parts, last);
 String valueString = Request
     .Get(uri)
     .execute()
     .returnContent()
     .asString();
 return fromJson(valueString);
}

代码示例来源:origin: twosigma/beakerx

@Override
public String get(String name) {
 String valueString = "";
 try {
  valueString = Request
      .Get(LOCALHOST + this.context.getPort() + AUTOTRANSLTION + this.context.getContextId() + "/" + name)
      .addHeader(AUTHORIZATION, auth())
      .execute()
      .returnContent()
      .asString();
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return valueString;
}

代码示例来源:origin: rancher/cattle

@Override
public void delete(long accountId, String value) throws IOException {
  Request.Post(SECRETS_URL.get() + PURGE_PATH).bodyString(value, ContentType.APPLICATION_JSON).execute().handleResponse((response) -> {
    int statusCode = response.getStatusLine().getStatusCode();
    if (statusCode >= 300 && statusCode != 404) {
      throw new IOException("Failed to delete secret :" + response.getStatusLine().getReasonPhrase());
    }
    return IOUtils.toString(response.getEntity().getContent());
  });
}

代码示例来源:origin: rancher/cattle

public HttpResponse getFromAzure(String azureAccessToken, String url) throws IOException {
  logger.trace("URL for Azure API call: "+ url);
  HttpResponse response = Request.Get(url).addHeader(AzureConstants.AUTHORIZATION, "Bearer " +
      "" + azureAccessToken).addHeader(AzureConstants.ACCEPT, AzureConstants.APPLICATION_JSON).execute().returnResponse();
  logger.debug("Response from Azure API: "+ response.getStatusLine());
  logger.trace("Complete Response from Azure: "+ EntityUtils.toString(response.getEntity()));
  return response;
}

代码示例来源:origin: rancher/cattle

protected TemplateCollection getTemplates(String url) throws IOException {
  return Request.Get(url).execute().handleResponse(new ResponseHandler<TemplateCollection>() {
    @Override
    public TemplateCollection handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
      if (response.getStatusLine().getStatusCode() != 200) {
        return null;
      }
      return jsonMapper.readValue(response.getEntity().getContent(), TemplateCollection.class);
    }
  });
}

代码示例来源:origin: com.github.lookout/metrics-datadog

public static String getEc2InstanceId() throws IOException {
  try {
   return Request.Get(url).execute().returnContent().asString();
  } catch (Throwable t) {
   throw new IOException(t);
  }
 }
}

代码示例来源:origin: org.coursera/metrics-datadog

public static String getEc2InstanceId() throws IOException {
  try {
   return Request.Get(url).execute().returnContent().asString();
  } catch (Throwable t) {
   throw new IOException(t);
  }
 }
}

代码示例来源:origin: org.streampipes/streampipes-connect

public FeatureCollection getCameraData() throws IOException {

  String response = Request
      .Get(Url)
      .addHeader("Authorization", "apiKey " +this.apiKey)
      .execute()
      .returnContent()
      .asString();

  return new Gson().fromJson(response, FeatureCollection.class);
 }
}

代码示例来源:origin: org.streampipes/streampipes-pipeline-management

public PipelineElementStatus invoke() {
 LOG.info("Invoking element: " + belongsTo);
 try {
     Response httpResp = Request.Post(belongsTo).bodyString(jsonLd(), ContentType.APPLICATION_JSON).connectTimeout(10000).execute();
  return handleResponse(httpResp);
 } catch (Exception e) {
  LOG.error(e.getMessage());
  return new PipelineElementStatus(belongsTo, payload.getName(), false, e.getMessage());
 }
}

代码示例来源:origin: org.streampipes/streampipes-pipeline-management

private EventSchema makeRequest() {
 String httpRequestBody = GsonSerializer.getGsonWithIds().toJson(dataProcessorInvocation);
 try {
  Response httpResp = Request.Post(dataProcessorInvocation.getBelongsTo() + "/output").bodyString(httpRequestBody,
      ContentType
      .APPLICATION_JSON).execute();
  return handleResponse(httpResp);
 } catch (Exception e) {
  e.printStackTrace();
  return new EventSchema();
 }
}

代码示例来源:origin: org.phenotips/clinical-text-analysis-extension-generic-rest

@Override
public InputStream getEmpty(String method) throws ServiceException
{
  try {
    URI uri = getAbsoluteURI(method);
    return Request.Get(uri).execute().returnContent().asStream();
  } catch (IOException | URISyntaxException e) {
    throw new ServiceException(e.getMessage(), e);
  }
}

代码示例来源:origin: com.cognifide.aet/client-core

private SuiteStatusResult getSuiteStatus(String statusUrl) throws IOException {
 return Request.Get(statusUrl)
   .connectTimeout(timeout)
   .socketTimeout(timeout)
   .execute()
   .handleResponse(suiteStatusResponseHandler);
}

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

@When("^\"(?:[^\"]*)\" downloads \"([^\"]*)\" without any authentication token$")
public void getDownloadWithoutToken(String attachmentId) throws Exception {
  String blobId = blobIdByAttachmentId.get(attachmentId);
  response = Request.Get(baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId).build())
    .execute()
    .returnResponse();
}

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

@When("^\"(?:[^\"]*)\" downloads \"([^\"]*)\" with a bad authentication token$")
public void getDownloadWithBadToken(String attachmentId) throws Exception {
  String blobId = blobIdByAttachmentId.get(attachmentId);
  response = Request.Get(
      baseUri(mainStepdefs.jmapServer)
        .setPath("/download/" + blobId)
        .addParameter("access_token", "bad")
        .build())
      .execute()
      .returnResponse();
}

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

@When("^\"(?:[^\"]*)\" downloads \"([^\"]*)\" with an empty authentication token$")
public void getDownloadWithEmptyToken(String attachmentId) throws Exception {
  String blobId = blobIdByAttachmentId.get(attachmentId);
  response = Request.Get(
      baseUri(mainStepdefs.jmapServer)
        .setPath("/download/" + blobId)
        .addParameter("access_token", "")
        .build())
      .execute()
      .returnResponse();
}

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

@Test
  public void containerShouldBeReachableOnExposedPort() throws IOException, URISyntaxException {
    Response response = Request.Get(new URIBuilder()
      .setScheme("http")
      .setHost(container.getHostIp())
      .setPort(container.getMappedPort(80)).build())
      .execute();

    assertThat(response.returnResponse().getStatusLine().getStatusCode())
      .isEqualTo(200);
  }
}

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

@When("^\"([^\"]*)\" downloads \"([^\"]*)\" without blobId parameter$")
public void getDownloadWithoutBlobId(String username, String attachmentId) throws Throwable {
  String blobId = blobIdByAttachmentId.get(attachmentId);
  URIBuilder uriBuilder = baseUri(mainStepdefs.jmapServer).setPath("/download/");
  trustForBlobId(blobId, username);
  AttachmentAccessTokenKey key = new AttachmentAccessTokenKey(username, blobId);
  uriBuilder.addParameter("access_token", attachmentAccessTokens.get(key).serialize());
  response = Request.Get(uriBuilder.build())
    .execute()
    .returnResponse();
}

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

@When("^\"([^\"]*)\" asks for a token for attachment \"([^\"]*)\"$")
public void postDownload(String username, String attachmentId) throws Throwable {
  String blobId = blobIdByAttachmentId.get(attachmentId);
  AccessToken accessToken = userStepdefs.authenticate(username);
  response = Request.Post(baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId).build())
      .addHeader("Authorization", accessToken.serialize())
      .execute()
      .returnResponse();
}

代码示例来源:origin: edu.jhuapl.dorset/dorset-core

private Response put(HttpRequest request) throws IOException {
  Request apacheRequest = Request.Put(request.getUrl());
  if (request.getBody() != null) {
    ContentType ct = ContentType.create(request.getContentType().getMimeType(),
            request.getContentType().getCharset());
    apacheRequest.bodyString(request.getBody(), ct);
  } else if (request.getBodyForm() != null) {
    apacheRequest.bodyForm(buildFormBody(request.getBodyForm()));
  }
  prepareRequest(apacheRequest);
  return apacheRequest.execute();
}

相关文章