org.apache.http.client.fluent.Request类的使用及代码示例

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

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

Request介绍

暂无

代码示例

代码示例来源: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: 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: dreamhead/moco

@Override
  public void run() throws Exception {
    org.apache.http.client.fluent.Request request = Post(root()).bodyForm(of(new BasicNameValuePair("name", "表单")), Charset.forName("GBK"));
    assertThat(helper.executeAsString(request), is("foobar"));
  }
});

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

public HttpResponse postForResponse(final String url, final String content, final String contentType)
    throws IOException {
  return execute(Request.Post(url)
      .addHeader(CONTENT_TYPE, contentType)
      .bodyByteArray(content.getBytes()));
}

代码示例来源: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.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: Kurento/kurento-java

@Override
public void connect() throws IOException {
 try {
  org.apache.http.client.fluent.Request.Post(url).bodyString("", ContentType.APPLICATION_JSON)
  .execute();
 } catch (ClientProtocolException e) {
  // Silence http connection exception. This indicate that server is
  // reachable and running
 }
}

代码示例来源:origin: denger/sendcloud4j

private String requestSend(String uri, Email email) throws IOException {
  Request request = Request.Post(uri)
      .connectTimeout(connectTimeout)
      .socketTimeout(socketTimeout);
  if (proxy != null) {
    request.viaProxy(proxy);
  }
  if (email.hasAttachment()) {
    request.body(getMultipartEmailHttpEntity(email));
  } else {
    request.bodyForm(convertFrom(email.getParameters()).build(), UTF_8);
  }
  return request.execute().returnContent().asString(UTF_8);
}

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

private SuiteExecutionResult retrieveSuiteExecutionResult(HttpEntity entity, int httpTimeout) {
 SuiteExecutionResult result;
 try {
  Response response = Request.Post(getSuiteUrl())
    .body(entity)
    .connectTimeout(httpTimeout)
    .socketTimeout(httpTimeout)
    .execute();
  result = response.handleResponse(suiteExecutionResponseHandler);
 } catch (HttpResponseException re) {
  String msg = String.format("[Status: %d] %s", re.getStatusCode(), re.getMessage()
  );
  result = SuiteExecutionResult.createErrorResult(msg);
 } catch (IOException ioe) {
  String msg = "Error while checking suite execution status: " + ioe.getMessage();
  result = SuiteExecutionResult.createErrorResult(msg);
 }
 return result;
}

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

public static String requestProbabilitiesString(Object[] objects) {
  String httpRequestBody = GsonSerializer.getGsonWithIds()
        .toJson(objects);
  String httpResp = "{\"result\": []}";
  try {
    httpResp = Request.Post("http://localhost:" + port +"/predict")
          .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
          .bodyForm(Form.form().add("X", httpRequestBody).build()).execute().returnContent().asString();
  } catch (IOException e) {
    e.printStackTrace();
  }
  return httpResp;
}

代码示例来源: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: org.apache.james/james-server-jmap-integration-testing

private static Response postAuthenticate(URIBuilder uriBuilder, String password, String continuationToken) throws ClientProtocolException, IOException, URISyntaxException {
  return Request.Post(uriBuilder.setPath("/authentication").build())
      .bodyString("{\"token\": \"" + continuationToken + "\", \"method\": \"password\", \"password\": \"" + password + "\"}", 
          ContentType.APPLICATION_JSON)
      .setHeader("Accept", ContentType.APPLICATION_JSON.getMimeType())
      .execute();
}

代码示例来源:origin: streampipes/streampipes-ce

public boolean installDataSource(String requestUrl, String elementIdUrl) throws AdapterException {
  try {
    String responseString = Request.Post(requestUrl)
        .bodyForm(
            Form.form()
                .add("uri", elementIdUrl)
                .add("publicElement", "true").build())
        .connectTimeout(1000)
        .socketTimeout(100000)
        .execute().returnContent().asString();
    logger.info(responseString);
  } catch (IOException e) {
    logger.error("Error while installing data source: " + requestUrl, e);
    throw new AdapterException();
  }
  return true;
}

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

private Request getRequest(final String url, final ImmutableMultimap<String, String> headers) {
  Request request = Request.Get(url);
  for (Map.Entry<String, String> entry : headers.entries()) {
    request = request.addHeader(entry.getKey(), entry.getValue());
  }
  return request;
}

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

private Response post(HttpRequest request) throws IOException {
  Request apacheRequest = Request.Post(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();
}

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

private Integer createConsumer(String kafkaRestUrl, String consumerInstance, String topic) throws IOException {
 String createConsumerUrl = kafkaRestUrl + "/consumers/" + getConsumerGroupId(topic);
 return Request.Post(createConsumerUrl)
     .addHeader(HttpHeaders.CONTENT_TYPE, KAFKA_REST_CONTENT_TYPE)
     .addHeader(HttpHeaders.ACCEPT, KAFKA_REST_CONTENT_TYPE)
     .body(new StringEntity(makeCreateConsumerBody(consumerInstance), Charsets.UTF_8))
     .execute()
     .returnResponse()
     .getStatusLine()
     .getStatusCode();
}

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

@When("^\"([^\"]*)\" upload a too big content$")
public void userUploadTooBigContent(String username) throws Throwable {
  AccessToken accessToken = userStepdefs.authenticate(username);
  Request request = Request.Post(uploadUri)
      .bodyStream(new BufferedInputStream(new ZeroedInputStream(_10M), _10M), org.apache.http.entity.ContentType.DEFAULT_BINARY);
  if (accessToken != null) {
    request.addHeader("Authorization", accessToken.serialize());
  }
  response = request.execute().returnResponse();
}

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

@When("^\"([^\"]*)\" upload a content without content type$")
public void userUploadContentWithoutContentType(String username) throws Throwable {
  AccessToken accessToken = userStepdefs.authenticate(username);
  Request request = Request.Post(uploadUri)
      .bodyByteArray("some text".getBytes(StandardCharsets.UTF_8));
  if (accessToken != null) {
    request.addHeader("Authorization", accessToken.serialize());
  }
  response = request.execute().returnResponse();
}

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

private void trustForBlobId(String blobId, String username) throws Exception {
  Response tokenGenerationResponse = Request.Post(baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId).build())
    .addHeader("Authorization", userStepdefs.authenticate(username).serialize())
    .execute();
  String serializedAttachmentAccessToken = tokenGenerationResponse.returnContent().asString();
  attachmentAccessTokens.put(
      new AttachmentAccessTokenKey(username, blobId),
      AttachmentAccessToken.from(
        serializedAttachmentAccessToken,
        blobId));
}

代码示例来源: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();
}

相关文章