当前位置: 首页>>代码示例>>Java>>正文


Java Request类代码示例

本文整理汇总了Java中org.eclipse.jetty.client.api.Request的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Request类属于org.eclipse.jetty.client.api包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRetry

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
@Test
public void testRetry() throws Exception {
    SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
    String accessToken = sf.getSession().getAccessToken();

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext(context));
    HttpClient httpClient = new HttpClient(sslContextFactory);
    httpClient.setConnectTimeout(60000);
    httpClient.start();

    String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
    Request logoutGet = httpClient.newRequest(uri)
        .method(HttpMethod.GET)
        .timeout(1, TimeUnit.MINUTES);

    ContentResponse response = logoutGet.send();
    assertEquals(HttpStatus.OK_200, response.getStatus());

    JobInfo jobInfo = new JobInfo();
    jobInfo.setOperation(OperationEnum.INSERT);
    jobInfo.setContentType(ContentType.CSV);
    jobInfo.setObject(Merchandise__c.class.getSimpleName());
    createJob(jobInfo);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:BulkApiIntegrationTest.java

示例2: newRequest

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
@Override
public Request newRequest(String uri) {
    Request retval = mock(Request.class);
    try {
        if (requestsTimeout || (isFirstRequestTimeout && requests.isEmpty())) {
            when(retval.send()).thenThrow(new TimeoutException());
        } else {
            when(retval.send()).thenReturn(httpResponse);
        }
        if (requestsFail && featureFlag.equals("true")) {
            when(httpResponse.getStatus()).thenReturn(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        } else if (responseException != null) {
            when(httpResponse.getStatus()).thenReturn(responseException.getCategory().getHttpStatus());
        } else {
            when(httpResponse.getStatus()).thenReturn(HttpServletResponse.SC_OK);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    when(retval.method(anyString())).thenReturn(retval);
    when(retval.content(any(ContentProvider.class))).thenReturn(retval);
    when(retval.timeout(anyLong(), any(TimeUnit.class))).thenReturn(retval);
    requests.add(uri);
    return retval;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:26,代码来源:RpcClientIntegrationTest.java

示例3: setup

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
@Before
public void setup() throws Exception {
    HttpClient httpClient = mock(HttpClient.class);
    response = mock(ContentResponse.class);
    when(response.getStatus()).thenReturn(200);
    when(response.getContentAsString()).thenReturn(healthInfo);
    HttpFields headers = new HttpFields();
    headers.add(CONSUL_INDEX, "42");
    when(response.getHeaders()).thenReturn(headers);
    Request request = mock(Request.class);
    when(httpClient.newRequest(anyString())).thenReturn(request);
    when(request.send()).thenReturn(response);
    props = new ServiceProperties();
    props.addProperty(ServiceProperties.REGISTRY_SERVER_KEY, "localhost:1234");
    worker = new RegistrationMonitorWorker(httpClient, props);
    worker.setServiceName("foobar");
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:18,代码来源:RegistrationMonitorWorkerIntegrationTest.java

示例4: 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

示例5: addProxyHeaders

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
@Override
protected void addProxyHeaders(final HttpServletRequest clientRequest, final Request proxyRequest) {
	super.addProxyHeaders(clientRequest, proxyRequest);

	// Forward security identifier if defined
	proxyRequest.header("SM_UNIVERSALID", clientRequest.getUserPrincipal() == null
			? StringUtils.trimToNull(clientRequest.getParameter(apiUserParameter)) : clientRequest.getUserPrincipal().getName());

	// Forward original SESSIONID
	proxyRequest.header("SM_SESSIONID", clientRequest.getSession(false) == null ? null : clientRequest.getSession(false).getId());

	// Forward API key, if defined.
	proxyRequest.header(apiKeyHeader, StringUtils.trimToNull(clientRequest.getParameter(apiKeyParameter)));

	// Forward all cookies but JSESSIONID.
	final String cookies = clientRequest.getHeader(HEADER_COOKIE);
	if (cookies != null) {
		proxyRequest.header(HEADER_COOKIE, StringUtils.trimToNull(
				Arrays.stream(cookies.split("; ")).filter(cookie -> !cookie.split("=")[0].equals(COOKIE_JEE)).collect(Collectors.joining("; "))));
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:22,代码来源:BackendProxyServlet.java

示例6: addProxyHeadersCookie

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
@Test
public void addProxyHeadersCookie() {
	final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
	final Request exchange = Mockito.mock(Request.class);
	final HttpSession session = Mockito.mock(HttpSession.class);
	final Principal principal = Mockito.mock(Principal.class);
	Mockito.when(request.getSession(false)).thenReturn(session);
	Mockito.when(request.getHeader("cookie")).thenReturn("JSESSIONID=value1; OTHER1=value2; OTHER2=value3");
	Mockito.when(session.getId()).thenReturn("J_SESSIONID");
	Mockito.when(request.getUserPrincipal()).thenReturn(principal);
	Mockito.when(principal.getName()).thenReturn("junit");
	servlet.addProxyHeaders(request, exchange);
	Mockito.verify(exchange, Mockito.times(1)).header("SM_UNIVERSALID", "junit");
	Mockito.verify(exchange, Mockito.times(1)).header("SM_SESSIONID", "J_SESSIONID");
	Mockito.verify(exchange, Mockito.times(1)).header("cookie", "OTHER1=value2; OTHER2=value3");
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:17,代码来源:BackendProxyServletTest.java

示例7: getTransactions

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
public Map<String, Transaction> getTransactions(String accountId, int offset, int transactionsPerRequest, boolean ignoreException)
{
  Map<String, Transaction> transactionLookup = null;
  try
  {
    InputStreamResponseListener listener = new InputStreamResponseListener();

    Request request = httpClient.POST(BURST_API_URL)
      .param("requestType", "getAccountTransactions")
      .param("firstIndex", String.valueOf(offset))
      .param("lastIndex", String.valueOf(offset + transactionsPerRequest))
      .param("account", accountId);
    request.send(listener);

    Response response = listener.get(BurstcoinFaucetProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS);
    transactionLookup = handleGetTransactionsResponse(listener, response, ignoreException);
  }
  catch(Exception e)
  {
    LOG.warn("Error: Failed to 'getAccountTransactions' for accountId '" + accountId + "' : " + e.getMessage());
  }
  return transactionLookup;
}
 
开发者ID:de-luxe,项目名称:burstcoin-faucet,代码行数:24,代码来源:NetworkComponent.java

示例8: executeRequest

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, String body) {
	Request httpRequest = this.httpClient.newRequest(url).method(method);
	addHttpHeaders(httpRequest, headers);
	if (body != null) {
		httpRequest.content(new StringContentProvider(body));
	}
	ContentResponse response;
	try {
		response = httpRequest.send();
	}
	catch (Exception ex) {
		throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
	}
	HttpStatus status = HttpStatus.valueOf(response.getStatus());
	HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders());
	return (response.getContent() != null ?
		new ResponseEntity<String>(response.getContentAsString(), responseHeaders, status) :
		new ResponseEntity<String>(responseHeaders, status));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:JettyXhrTransport.java

示例9: rawRequest

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
protected String rawRequest(String url, Map<String, String> params) throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
    Request req = httpClient.newRequest(new String(url.getBytes("UTF-8"), "UTF-8"))
            .header(HttpHeader.CONTENT_ENCODING, "UTF-8")
            .method(HttpMethod.GET)
            .header(HttpHeader.ACCEPT_ENCODING, "UTF-8");
    req = req.param("app_token", APIKeys.getAPPKey());
    if (params != null) {
        for (String key : params.keySet()) {
            req = req.param(key, params.get(key));
        }
    }
    Main.log.info("GET {}, {}, {}", req, req.getQuery(), req.getParams());
    ContentResponse resp = req.send();
    if (resp.getStatus() != HttpStatus.OK_200) {
        throw new HttpRequestException(
                "Request ended with non-OK status: "
                + HttpStatus.getMessage(resp.getStatus()),
                resp.getRequest()
        );
    }
    return resp.getContentAsString();
}
 
开发者ID:psyriccio,项目名称:VoteFlow,代码行数:23,代码来源:LawAPI.java

示例10: sendMessageToHyVarRec

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
protected String sendMessageToHyVarRec(String message, URI uri) throws UnresolvedAddressException, ExecutionException, InterruptedException, TimeoutException {
	HttpClient hyvarrecClient = new HttpClient();
	try {
		hyvarrecClient.start();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return null;
	}
	URI hyvarrecUri = uri;
	Request hyvarrecRequest = hyvarrecClient.POST(hyvarrecUri);
	hyvarrecRequest.header(HttpHeader.CONTENT_TYPE, "application/json");
	hyvarrecRequest.content(new StringContentProvider(message), "application/json");
	ContentResponse hyvarrecResponse;
	String hyvarrecAnswerString = "";
	hyvarrecResponse = hyvarrecRequest.send();
	hyvarrecAnswerString = hyvarrecResponse.getContentAsString();

	// Only for Debug
	System.err.println("HyVarRec Answer: "+hyvarrecAnswerString);
	
	return hyvarrecAnswerString;
}
 
开发者ID:DarwinSPL,项目名称:DarwinSPL,代码行数:24,代码来源:DwAnalysesClient.java

示例11: setHeaderAndQueryInfo

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
private static Request setHeaderAndQueryInfo(Request request, ResponseInfo responseInfo) {
    Map<String, String> requestHeaders = responseInfo.getHeaders();

    for ( String headerKey : requestHeaders.keySet() ) {
        request.header(headerKey, requestHeaders.get(headerKey));
    }

    request.method(request.getMethod());
    request.accept(responseInfo.getRequestAccept());

    Map<String, String> requestQueryParams = responseInfo.getQueryStringMap();
    for ( String queryKey : requestQueryParams.keySet() ) {
        request.param(queryKey, requestQueryParams.get(queryKey));
    }

    return request;
}
 
开发者ID:longcoding,项目名称:undefined-gateway,代码行数:18,代码来源:ProxyServiceImpl.java

示例12: testGenerateX509CertificateInvalidStatus

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
@Test
public void testGenerateX509CertificateInvalidStatus() throws Exception {

    HttpClient httpClient = Mockito.mock(HttpClient.class);

    HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
    HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
    certSigner.setHttpClient(httpClient);

    Request request = Mockito.mock(Request.class);
    Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);

    ContentResponse response = Mockito.mock(ContentResponse.class);
    Mockito.when(request.send()).thenReturn(response);
    Mockito.when(response.getStatus()).thenReturn(400);

    assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
 
开发者ID:yahoo,项目名称:athenz,代码行数:19,代码来源:HttpCertSignerTest.java

示例13: testGenerateX509CertificateResponseNull

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
@Test
public void testGenerateX509CertificateResponseNull() throws Exception {

    HttpClient httpClient = Mockito.mock(HttpClient.class);

    HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
    HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
    certSigner.setHttpClient(httpClient);

    Request request = Mockito.mock(Request.class);
    Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);

    ContentResponse response = Mockito.mock(ContentResponse.class);
    Mockito.when(request.send()).thenReturn(response);
    Mockito.when(response.getStatus()).thenReturn(201);
    Mockito.when(response.getContentAsString()).thenReturn(null);

    assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
 
开发者ID:yahoo,项目名称:athenz,代码行数:20,代码来源:HttpCertSignerTest.java

示例14: testGenerateX509CertificateResponseEmpty

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
@Test
public void testGenerateX509CertificateResponseEmpty() throws Exception {

    HttpClient httpClient = Mockito.mock(HttpClient.class);

    HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
    HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
    certSigner.setHttpClient(httpClient);

    Request request = Mockito.mock(Request.class);
    Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);

    ContentResponse response = Mockito.mock(ContentResponse.class);
    Mockito.when(request.send()).thenReturn(response);
    Mockito.when(response.getStatus()).thenReturn(201);
    Mockito.when(response.getContentAsString()).thenReturn("");

    assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
 
开发者ID:yahoo,项目名称:athenz,代码行数:20,代码来源:HttpCertSignerTest.java

示例15: testGenerateX509Certificate

import org.eclipse.jetty.client.api.Request; //导入依赖的package包/类
@Test
public void testGenerateX509Certificate() throws Exception {

    HttpClient httpClient = Mockito.mock(HttpClient.class);

    HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
    HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
    certSigner.setHttpClient(httpClient);

    Request request = Mockito.mock(Request.class);
    Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);

    ContentResponse response = Mockito.mock(ContentResponse.class);
    Mockito.when(request.send()).thenReturn(response);
    Mockito.when(response.getStatus()).thenReturn(201);
    Mockito.when(response.getContentAsString()).thenReturn("{\"pem\": \"pem-value\"}");

    String pem = certSigner.generateX509Certificate("csr", null, 0);
    assertEquals(pem, "pem-value");
}
 
开发者ID:yahoo,项目名称:athenz,代码行数:21,代码来源:HttpCertSignerTest.java


注:本文中的org.eclipse.jetty.client.api.Request类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。