本文整理了Java中org.apache.http.client.fluent.Request.socketTimeout
方法的一些代码示例,展示了Request.socketTimeout
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.socketTimeout
方法的具体详情如下:
包路径:org.apache.http.client.fluent.Request
类名称:Request
方法名:socketTimeout
暂无
代码示例来源: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 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: 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.apache.taverna.osgi/taverna-download-impl
private void downloadToFile(URI source, Path destination) throws DownloadException {
try {
// We want to handle http/https with HTTPClient
if (source.getScheme().equalsIgnoreCase("http") || source.getScheme().equalsIgnoreCase("https")) {
Request.Get(source).userAgent(getUserAgent()).connectTimeout(TIMEOUT).socketTimeout(TIMEOUT).execute()
.saveContent(destination.toFile());
} else {
// Try as a supported Path, e.g. file: or relative path
try {
Path path = Paths.get(source);
Files.copy(path, destination, StandardCopyOption.REPLACE_EXISTING);
} catch (FileSystemNotFoundException e) {
throw new DownloadException("Unsupported URL scheme: " + source.getScheme());
}
}
} catch (IOException e) {
throw new DownloadException(String.format("Error downloading %1$s to %2$s.", source, destination), e);
}
}
代码示例来源: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: org.apache.taverna.osgi/taverna-download-impl
private String downloadHash(URI source) throws DownloadException {
try {
// We want to handle http/https with HTTPClient
if (source.getScheme().equalsIgnoreCase("http") || source.getScheme().equalsIgnoreCase("https")) {
logger.info("Downloading checksum " + source);
return Request.Get(source).userAgent(getUserAgent()).connectTimeout(TIMEOUT).socketTimeout(TIMEOUT).execute()
.returnContent().asString(StandardCharsets.ISO_8859_1);
} else {
// Try as a supported Path, e.g. file: or relative path
try {
Path path = Paths.get(source);
return Files.readAllLines(path, StandardCharsets.ISO_8859_1).get(0);
} catch (FileSystemNotFoundException e) {
throw new DownloadException("Unsupported URL scheme: " + source.getScheme());
}
}
} catch (IOException e) {
throw new DownloadException(String.format("Error downloading %1$s", source), e);
}
}
代码示例来源:origin: org.streampipes/streampipes-connect
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: 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);
}
内容来源于网络,如有侵权,请联系作者删除!