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

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

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

Request.connectTimeout介绍

暂无

代码示例

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

public PipelineElementStatus detach() {
 try {
  Response httpResp = Request.Delete(belongsTo).connectTimeout(10000).execute();
  return handleResponse(httpResp);
 } catch (Exception e) {
  LOG.error("Could not stop pipeline " + belongsTo, e.getMessage());
  return new PipelineElementStatus(belongsTo, payload.getName(), false, e.getMessage());
 }
}

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

public PipelineElementStatus detach() {
 try {
  Response httpResp = Request.Delete(belongsTo).connectTimeout(10000).execute();
  return handleResponse(httpResp);
 } catch (Exception e) {
  LOG.error("Could not stop pipeline " + belongsTo, e.getMessage());
  return new PipelineElementStatus(belongsTo, payload.getName(), false, e.getMessage());
 }
}

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

public static void main(String... args) throws IOException {
//        http://141.21.43.35/record/current.jpg
    InputStream result = Request.Get("https://upload.wikimedia.org/wikipedia/commons/9/95/KWF_Test.png")
          .connectTimeout(1000)
          .socketTimeout(100000)
          .execute()
          .returnContent()
          .asStream();

    byte[] b =  IOUtils.toByteArray(result);
    System.out.println(Base64.getEncoder().encodeToString(b));

    System.out.println("========k=======k=======k=======k=======k=======k=======k=======k=======k=======k=======k=======k=======k======k");
//        InputStream in  = IOUtils.toInputStream(result, "UTF-8");
//        byte[] a = IOUtils.toByteArray(in);

//        System.out.println(new String(a));
//        System.out.println(Base64.getEncoder().encodeToString(a));

//        System.out.println(in);
  }

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

public InputStream getDataFromEndpoint() {
  InputStream result = null;
  try {
    String s = Request.Get(url)
        .connectTimeout(1000)
        .socketTimeout(100000)
        .execute().returnContent().asString();
    if (s.startsWith("ï")) {
      s = s.substring(3);
    }
    result = IOUtils.toInputStream(s, "UTF-8");
  } catch (IOException e) {
    e.printStackTrace();
  }
  return result;
}

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

public static String stopPipeline(String url) {
  logger.info("Send stopAdapter pipeline request on URL: " + url);
  String result = "";
  try {
    result = Request.Get(url)
        .connectTimeout(1000)
        .socketTimeout(100000)
        .execute().returnContent().asString();
  } catch (IOException e) {
    e.printStackTrace();
    result = e.getMessage();
  }
  logger.info("Successfully stopped pipeline");
  return result;
}

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

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: streampipes/streampipes-ce

protected static String getDataFromEndpointString(String url) throws AdapterException {
  String result = null;
  logger.info("Started Request to open sensemap endpoint: " + url);
  try {
    result = Request.Get(url)
        .connectTimeout(1000)
        .socketTimeout(100000)
        .execute().returnContent().asString();
    if (result.startsWith("ï")) {
      result = result.substring(3);
    }
    logger.info("Received data from request");
  } catch (Exception e) {
    String errorMessage = "Error while connecting to the open sensemap api";
    logger.error(errorMessage, e);
    throw new AdapterException(errorMessage);
  }
  return result;
}

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

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

代码示例来源: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: edu.jhuapl.dorset/dorset-core

private void prepareRequest(Request apacheRequest) {
  if (getUserAgent() != null) {
    apacheRequest.userAgent(getUserAgent());
  }
  if (getConnectTimeout() != null) {
    apacheRequest.connectTimeout(getConnectTimeout());
  }
  if (getReadTimeout() != null) {
    apacheRequest.socketTimeout(getReadTimeout());
  }
  if (!requestHeaders.isEmpty()) {
    for (Map.Entry<String, String> entry : requestHeaders.entrySet()) {
      apacheRequest.addHeader(entry.getKey(), entry.getValue());
    }
  }
}

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

public InputStream getDataFromEndpoint() {
    InputStream result = null;

    try {
      result = Request.Get(url)
          .connectTimeout(1000)
          .socketTimeout(100000)
          .execute().returnContent().asStream();

//            if (s.startsWith("ï")) {
//                s = s.substring(3);
//            }

//            result = IOUtils.toInputStream(s, "UTF-8");

    } catch (IOException e) {
      e.printStackTrace();
    }

    return result;
  }

代码示例来源:origin: jenkinsci/jira-plugin

private Request buildGetRequest(URI uri) {
  return Request.Get(uri)
      .connectTimeout(timeoutInMilliseconds())
      .socketTimeout(timeoutInMilliseconds())
      .addHeader("Authorization", authHeader)
      .addHeader("Content-Type", "application/json");
}

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

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: 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: org.mule.services/mule-service-http

@Test
public void executingRequestsFinishesOnDispose() throws Exception {
 try {
  Request.Get(format("http://localhost:%s/%s", port.getValue(), "test"))
    .connectTimeout(TIMEOUT).socketTimeout(TIMEOUT).execute();
  fail();
 } catch (SocketTimeoutException ste) {
  // Expected
 }
 server.stop();
 Future<?> disposeTask = newSingleThreadExecutor().submit(() -> {
  server.dispose();
  server = null;
 });
 requestLatch.countDown();
 disposeTask.get(TIMEOUT, MILLISECONDS);
 responseLatch.await(TIMEOUT, MILLISECONDS);
}

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

相关文章