當前位置: 首頁>>代碼示例>>Java>>正文


Java Request.timeout方法代碼示例

本文整理匯總了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;
}
 
開發者ID:Xianguang-Zhou,項目名稱:smartqq-client,代碼行數:14,代碼來源:SmartQQClient.java

示例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;
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:40,代碼來源:DLinkHNAPCommunication.java

示例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);
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:35,代碼來源:ProxyServlet.java

示例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;
}
 
開發者ID:yahoo,項目名稱:athenz,代碼行數:38,代碼來源:HttpCertSigner.java

示例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;
}
 
開發者ID:yahoo,項目名稱:athenz,代碼行數:32,代碼來源:HttpCertSigner.java

示例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));
}
 
開發者ID:DemandCube,項目名稱:Scribengin,代碼行數:50,代碼來源:CommandProxyServlet.java


注:本文中的org.eclipse.jetty.client.api.Request.timeout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。