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


Java HttpClient.start方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.client.HttpClient.start方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClient.start方法的具體用法?Java HttpClient.start怎麽用?Java HttpClient.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.client.HttpClient的用法示例。


在下文中一共展示了HttpClient.start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testRetry

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的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: getHttpClient

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
/**
 * Create a jetty http client capable to speak http/2.
 *
 * @return the client
 */
@Bean
public static HttpClient getHttpClient() {

  HTTP2Client http2Client = new HTTP2Client();
  HttpClientTransportOverHTTP2 transport = new HttpClientTransportOverHTTP2(
      http2Client);

  HttpClient httpClient = new HttpClient(transport, getSslContextFactory());
  httpClient.setFollowRedirects(true);
  try {
    httpClient.start();
  } catch (Exception e) {
    LOG.error("Could not start http client", e);
  }

  return httpClient;
}
 
開發者ID:janweinschenker,項目名稱:servlet4-demo,代碼行數:23,代碼來源:ApplicationConfig.java

示例3: sentRequest

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
public static int sentRequest(final String url, final String method, final String content) throws Exception {
    HttpClient httpClient = new HttpClient();
    try {
        httpClient.start();
        ContentExchange contentExchange = new ContentExchange();
        contentExchange.setMethod(method);
        contentExchange.setRequestContentType(MediaType.APPLICATION_JSON);
        contentExchange.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
        httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
        contentExchange.setURL(url);
        httpClient.send(contentExchange);
        contentExchange.waitForDone();
        return contentExchange.getResponseStatus();
    } finally {
        httpClient.stop();
    }
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:18,代碼來源:RestfulTestsUtil.java

示例4: sentGetRequest

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
public static String sentGetRequest(final String url) throws Exception {
    HttpClient httpClient = new HttpClient();
    try {
        httpClient.start();
        ContentExchange contentExchange = new ContentExchange();
        contentExchange.setMethod("GET");
        contentExchange.setRequestContentType(MediaType.APPLICATION_JSON);
        httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
        contentExchange.setURL(url);
        httpClient.send(contentExchange);
        contentExchange.waitForDone();
        return contentExchange.getResponseContent();
    } finally {
        httpClient.stop();
    }
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:17,代碼來源:RestfulTestsUtil.java

示例5: sentRequest

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
private static ContentExchange sentRequest(final String content) throws Exception {
    HttpClient httpClient = new HttpClient();
    try {
        httpClient.start();
        ContentExchange result = new ContentExchange();
        result.setMethod("POST");
        result.setRequestContentType(MediaType.APPLICATION_JSON);
        result.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
        httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
        result.setURL(URL);
        httpClient.send(result);
        result.waitForDone();
        return result;
    } finally {
        httpClient.stop();
    }
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:18,代碼來源:RestfulServerTest.java

示例6: testHealthCheckOutputFormat

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
@Test
public void testHealthCheckOutputFormat() throws Exception {
    String failureMessage = "I'm a failure!";
    SetHealthCheckStatusCommand command = SetHealthCheckStatusCommand.newBuilder()
            .setStatus(HealthCheck.Status.FAIL.toString()).setMessage(failureMessage).build();
    //we have to work around the normal communication channels, as the load-balancer
    //won't let us talk to a failing instance
    LoadBalancer loadBalancer = ServiceIntegrationTestSuite.testService.getLoadBalancer();
    ServiceIntegrationTestSuite.testService.sendRequest("TestService.SetHealthCheckStatus", command);
    ServiceEndpoint endpoint = loadBalancer.getHealthyInstance();
    String url = "http://" + endpoint.getHostAndPort() + "/health";
    HttpClient httpClient = new HttpClient();
    httpClient.start();
    String response = httpClient.GET(url).getContentAsString();
    assertThat(response).isEqualTo("{\"summary\":\"CRITICAL\",\"details\":[" +
            "{\"name\":\"database_migration\",\"status\":\"OK\",\"reason\":\"\"}," +
            "{\"name\":\"test_servlet\",\"status\":\"CRITICAL\",\"reason\":\"" + failureMessage + "\"}]}");
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:19,代碼來源:RandomServiceIntegrationTest.java

示例7: createHttpClient

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
private HttpClient createHttpClient() {
    //Allow ssl by default
    SslContextFactory sslContextFactory = new SslContextFactory();
    //Don't exclude RSA because Sixt needs them, dammit!
    sslContextFactory.setExcludeCipherSuites("");
    HttpClient client = new HttpClient(sslContextFactory);
    client.setFollowRedirects(false);
    client.setMaxConnectionsPerDestination(16);
    client.setConnectTimeout(FeatureFlags.getHttpConnectTimeout(serviceProperties));
    client.setAddressResolutionTimeout(FeatureFlags.getHttpAddressResolutionTimeout(serviceProperties));
    //You can set more restrictive timeouts per request, but not less, so
    //  we set the maximum timeout of 1 hour here.
    client.setIdleTimeout(60 * 60 * 1000);
    try {
        client.start();
    } catch (Exception e) {
        logger.error("Error building http client", e);
    }
    return client;
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:21,代碼來源:InjectionModule.java

示例8: createHttpClient

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
private HttpClient createHttpClient() {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setExcludeCipherSuites("");
    HttpClient client = new HttpClient(sslContextFactory);
    client.setFollowRedirects(false);
    client.setMaxConnectionsPerDestination(2);
    //You can set more restrictive timeouts per request, but not less, so
    //  we set the maximum timeout of 1 hour here.
    client.setIdleTimeout(60 * 60 * 1000);
    try {
        client.start();
    } catch (Exception e) {
        logger.error("Error building http client", e);
    }
    return client;
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:17,代碼來源:ServiceImpersonatorLoadBalancer.java

示例9: getHttpClient

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
@Provides
public HttpClient getHttpClient() {
	HttpClient client = new HttpClient();
	client.setFollowRedirects(false);
	client.setMaxConnectionsPerDestination(32);
	client.setConnectTimeout(100);
	client.setAddressResolutionTimeout(100);
	//You can set more restrictive timeouts per request, but not less, so
	//  we set the maximum timeout of 1 hour here.
	client.setIdleTimeout(60 * 60 * 1000);
	try {
		client.start();
	} catch (Exception e) {
		logger.error("Error building http client", e);
	}
	return client;
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:18,代碼來源:TestInjectionModule.java

示例10: sendMessageToHyVarRec

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的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: initializeNettyClient

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
@PostConstruct
private void initializeNettyClient() {

    int THREAD_POOL_COUNT = messageManager.getIntProperty("undefined.netty.thread.count");
    int NETTY_MAX_CONNECTION = messageManager.getIntProperty("undefined.netty.max.connection");
    long NETTY_HTTP_TIMEOUT = messageManager.getLongProperty("undefined.netty.http.timeout");

    executor = Executors.newFixedThreadPool(THREAD_POOL_COUNT);
    httpClient = new HttpClient();
    try {
        httpClient.setMaxConnectionsPerDestination(NETTY_MAX_CONNECTION);
        httpClient.setConnectTimeout(NETTY_HTTP_TIMEOUT);
        httpClient.setExecutor(executor);
        httpClient.start();
    } catch(Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:longcoding,項目名稱:undefined-gateway,代碼行數:19,代碼來源:NettyClientFactory.java

示例12: testRetry

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的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());

    doTestGetGlobalObjects("");
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:RestApiIntegrationTest.java

示例13: prepare

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
public void prepare(Handler handler) throws Exception {
    QueuedThreadPool serverThreads = new QueuedThreadPool();
    serverThreads.setName("server");
    server = new Server(serverThreads);
    connector = new ServerConnector(server);
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();

    QueuedThreadPool clientThreads = new QueuedThreadPool();
    clientThreads.setName("client");
    httpClient = new HttpClient();
    httpClient.setExecutor(clientThreads);
    httpClient.start();
}
 
開發者ID:jetty-project,項目名稱:jetty-reactive-httpclient,代碼行數:16,代碼來源:Usage.java

示例14: setUp

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    client = new HttpClient();
    client.start();
    response = client.newRequest("http://localhost:8080/request/")
            .method(HttpMethod.GET)
            .header("LOREM", "IpSuM")
            .header("hello", "world 1")
            .header("hello", "world 2")
            .header("connection", "upgrade")
            .header("upgrade", "HTTP/2.0")
            .send();
}
 
開發者ID:galop-proxy,項目名稱:galop,代碼行數:14,代碼來源:RequestHeadersTest.java

示例15: setUp

import org.eclipse.jetty.client.HttpClient; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
	registry = spy(new MetricRegistry());
	client = new HttpClient();
	server = new Server();
	when(registry.getNanos()).thenAnswer(i -> now += 123456789);
	ServerConnector connector = new ServerConnector(server);
	InstrumentedHandler handler = new InstrumentedHandler(registry);
	handler.setHandler(new HelloWorldHandler());
	server.addConnector(connector);
	server.setHandler(handler);
	server.start();
	client.start();
	url = "http://localhost:" + connector.getLocalPort();
}
 
開發者ID:mevdschee,項目名稱:tqdev-metrics,代碼行數:16,代碼來源:InstrumentedHandlerTest.java


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