本文整理汇总了Java中org.eclipse.jetty.client.api.Request.timeout方法的典型用法代码示例。如果您正苦于以下问题:Java Request.timeout方法的具体用法?Java Request.timeout怎么用?Java Request.timeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.client.api.Request
的用法示例。
在下文中一共展示了Request.timeout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postRequest
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
private Request postRequest(ApiURL url, JsonObject r, Timeout timeout) {
Fields fields = new Fields();
fields.add("r", GsonUtil.gson.toJson(r));
Request request = httpClient.newRequest(url.getUrl()).method(HttpMethod.POST).agent(ApiURL.USER_AGENT)
.header("Origin", url.getOrigin()).content(new FormContentProvider(fields));
if (url.getReferer() != null) {
request.header(HttpHeader.REFERER, url.getReferer());
}
if (timeout != null) {
request.timeout(timeout.getTime(), timeout.getUnit());
}
return request;
}
示例2: sendReceive
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
/**
* Send the SOAP message using Jetty HTTP client. Jetty is used in preference to
* HttpURLConnection which can result in the HNAP interface becoming unresponsive.
*
* @param action - SOAP Action to send
* @param timeout - Connection timeout in milliseconds
* @return The result
* @throws IOException
* @throws SOAPException
* @throws SAXException
* @throws ExecutionException
* @throws TimeoutException
* @throws InterruptedException
*/
protected Document sendReceive(final SOAPMessage action, final int timeout) throws IOException, SOAPException,
SAXException, InterruptedException, TimeoutException, ExecutionException {
Document result;
final Request request = httpClient.POST(uri);
request.timeout(timeout, TimeUnit.MILLISECONDS);
final Iterator<?> it = action.getMimeHeaders().getAllHeaders();
while (it.hasNext()) {
final MimeHeader header = (MimeHeader) it.next();
request.header(header.getName(), header.getValue());
}
try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
action.writeTo(os);
request.content(new BytesContentProvider(os.toByteArray()));
final ContentResponse response = request.send();
try (final ByteArrayInputStream is = new ByteArrayInputStream(response.getContent())) {
result = parser.parse(is);
}
}
return result;
}
示例3: service
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
@Override
protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
final int requestId = getRequestId(request);
String rewrittenTarget = rewriteTarget(request);
if (_log.isDebugEnabled()) {
StringBuffer uri = request.getRequestURL();
if (request.getQueryString() != null)
uri.append("?").append(request.getQueryString());
if (_log.isDebugEnabled())
_log.debug("{} rewriting: {} -> {}", requestId, uri, rewrittenTarget);
}
if (rewrittenTarget == null) {
onProxyRewriteFailed(request, response);
return;
}
final Request proxyRequest = getHttpClient().newRequest(rewrittenTarget).method(request.getMethod()).version(HttpVersion.fromString(request.getProtocol()));
copyRequestHeaders(request, proxyRequest);
addProxyHeaders(request, proxyRequest);
// final AsyncContext asyncContext = request.startAsync();
// We do not timeout the continuation, but the proxy request
// asyncContext.setTimeout(0);
proxyRequest.timeout(getTimeout(), TimeUnit.MILLISECONDS);
if (hasContent(request))
proxyRequest.content(proxyRequestContent(request, response, proxyRequest));
sendProxyRequest(request, response, proxyRequest);
}
示例4: processX509CertRequest
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
ContentResponse processX509CertRequest(final String csr, final String keyUsage,
int expiryTime, int retryCount) {
ContentResponse response = null;
try {
Request request = httpClient.POST(x509CertUri);
request.header(HttpHeader.ACCEPT, CONTENT_JSON);
request.header(HttpHeader.CONTENT_TYPE, CONTENT_JSON);
X509CertSignObject csrCert = new X509CertSignObject()
.setPem(csr).setExtusage(keyUsage);
if (expiryTime > 0) {
csrCert.setExpire(expiryTime);
}
request.content(new StringContentProvider(JSON.string(csrCert)), CONTENT_JSON);
// our max timeout is going to be 30 seconds. By default
// we're picking a small value to quickly recognize when
// our idle connections are disconnected by certsigner but
// we won't allow any connections taking longer than 30 secs
long timeout = retryCount * requestTimeout;
if (timeout > 30) {
timeout = 30;
}
request.timeout(timeout, TimeUnit.SECONDS);
response = request.send();
} catch (Exception ex) {
String msg = ex.getMessage();
if (msg == null) {
msg = ex.getClass().getName();
}
LOGGER.error("Unable to fetch requested uri '{}': {}",
x509CertUri, msg);
}
return response;
}
示例5: processSSHKeyRequest
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
ContentResponse processSSHKeyRequest(String sshKeyReq, int retryCount) {
ContentResponse response = null;
try {
Request request = httpClient.POST(sshCertUri);
request.header(HttpHeader.ACCEPT, CONTENT_JSON);
request.header(HttpHeader.CONTENT_TYPE, CONTENT_JSON);
request.content(new StringContentProvider(sshKeyReq), CONTENT_JSON);
// our max timeout is going to be 30 seconds. By default
// we're picking a small value to quickly recognize when
// our idle connections are disconnected by signer but
// we won't allow any connections taking longer than 30 secs
long timeout = retryCount * requestTimeout;
if (timeout > 30) {
timeout = 30;
}
request.timeout(timeout, TimeUnit.SECONDS);
response = request.send();
} catch (Exception ex) {
String msg = ex.getMessage();
if (msg == null) {
msg = ex.getClass().getName();
}
LOGGER.error("processSSHKeyRequest: Unable to fetch requested uri '{}': {}",
sshCertUri, msg);
}
return response;
}
示例6: onResponseFailure
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
@Override
protected void onResponseFailure(HttpServletRequest request, HttpServletResponse response,
Response proxyResponse, Throwable failure){
//System.err.println("Response Failure!");
this.setForwardingUrl();
HttpClient c = null;
try {
c = this.createHttpClient();
} catch (ServletException e1) {
e1.printStackTrace();
}
final Request proxyRequest = c.newRequest(this.forwardingUrl)
.method(request.getMethod())
.version(HttpVersion.fromString(request.getProtocol()));
boolean hasContent = request.getContentLength() > 0 || request.getContentType() != null;
for (Enumeration<String> headerNames = request.getHeaderNames(); headerNames.hasMoreElements();){
String headerName = headerNames.nextElement();
if (HttpHeader.TRANSFER_ENCODING.is(headerName))
hasContent = true;
for (Enumeration<String> headerValues = request.getHeaders(headerName); headerValues.hasMoreElements();){
String headerValue = headerValues.nextElement();
if (headerValue != null)
proxyRequest.header(headerName, headerValue);
}
}
// Add proxy headers
addViaHeader(proxyRequest);
addXForwardedHeaders(proxyRequest, request);
final AsyncContext asyncContext = request.getAsyncContext();
// We do not timeout the continuation, but the proxy request
asyncContext.setTimeout(0);
proxyRequest.timeout(getTimeout(), TimeUnit.MILLISECONDS);
if (hasContent)
try {
proxyRequest.content(proxyRequestContent(proxyRequest, request));
} catch (IOException e) {
e.printStackTrace();
}
customizeProxyRequest(proxyRequest, request);
proxyRequest.send(new ProxyResponseListener(request, response));
}