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

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

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

Request.bodyStream介绍

暂无

代码示例

代码示例来源: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.james/apache-james-mailbox-tika

@Override
public Optional<InputStream> recursiveMetaDataAsJson(InputStream inputStream, String contentType) {
  try {
    return Optional.ofNullable(
        Request.Put(recursiveMetaData)
          .socketTimeout(tikaConfiguration.getTimeoutInMillis())
          .bodyStream(inputStream, ContentType.create(contentType))
          .execute()
          .returnContent()
          .asStream());
  } catch (IOException e) {
    LOGGER.warn("Failing to call Tika for content type {}", contentType, e);
    return Optional.empty();
  }
}

代码示例来源:origin: codecentric/cxf-spring-boot-starter

public SoapRawClientResponse callSoapService(InputStream xmlFile) throws BootStarterCxfException {
  SoapRawClientResponse easyRawSoapResponse = new SoapRawClientResponse();
  
  LOGGER.debug("Calling SoapService with POST on Apache HTTP-Client and configured URL: {}", soapServiceUrl);
  
  try {
    Response httpResponseContainer = Request
        .Post(soapServiceUrl)
        .bodyStream(xmlFile, contentTypeTextXmlUtf8())
        .addHeader("SOAPAction", "\"" + soapAction + "\"")
        .execute();
    
    HttpResponse httpResponse = httpResponseContainer.returnResponse();            
    easyRawSoapResponse.setHttpStatusCode(httpResponse.getStatusLine().getStatusCode());
    easyRawSoapResponse.setHttpResponseBody(XmlUtils.parseFileStream2Document(httpResponse.getEntity().getContent()));
    
  } catch (Exception exception) {
    throw new BootStarterCxfException(ERROR_MESSAGE + exception.getMessage(), exception);
  }        
  return easyRawSoapResponse;
}

代码示例来源: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.phenotips/clinical-text-analysis-extension-generic-rest

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

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

.addHeader("Content-Encoding", "deflate")
  .addHeader("Content-MD5", DigestUtils.md5Hex(postBody))
  .bodyStream(deflated(postBody), ContentType.APPLICATION_JSON);
} else {
 request.bodyString(postBody, ContentType.APPLICATION_JSON);

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

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

@Given("^\"([^\"]*)\" is starting uploading a content$")
public void userStartUploadContent(String username) {
  AccessToken accessToken = userStepdefs.authenticate(username);
  CountDownLatch startSignal = new CountDownLatch(2);
  CountDownConsumeInputStream bodyStream = new CountDownConsumeInputStream(startSignal);
  Request request = Request.Post(uploadUri)
    .bodyStream(new BufferedInputStream(bodyStream, _1M), org.apache.http.entity.ContentType.DEFAULT_BINARY);
  if (accessToken != null) {
    request.addHeader("Authorization", accessToken.serialize());
  }
  async = Async.newInstance().execute(request, new FutureCallback<Content>() {
    
    @Override
    public void failed(Exception ex) {
    }
    
    @Override
    public void completed(Content result) {
    }
    
    @Override
    public void cancelled() {
      bodyStream.getStartSignal().countDown();
      if (bodyStream.getStartSignal().getCount() == 1) {
        isCanceled = true;
      }
    }
  });
}

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

inputStream = DistributionPackageUtils.createStreamWithHeader(distributionPackage);
req = req.bodyStream(inputStream, ContentType.APPLICATION_OCTET_STREAM);

相关文章