本文整理匯總了Java中org.eclipse.jetty.client.HttpClient類的典型用法代碼示例。如果您正苦於以下問題:Java HttpClient類的具體用法?Java HttpClient怎麽用?Java HttpClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpClient類屬於org.eclipse.jetty.client包,在下文中一共展示了HttpClient類的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);
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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 + "\"}]}");
}
示例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;
}
示例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;
}
示例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;
}
示例10: RpcClientIntegrationTest
import org.eclipse.jetty.client.HttpClient; //導入依賴的package包/類
public RpcClientIntegrationTest(String featureFlag) {
this.featureFlag = featureFlag;
TestInjectionModule module = new TestInjectionModule(featureFlag);
ServiceProperties props = new ServiceProperties();
props.addProperty(FeatureFlags.FLAG_EXPOSE_ERRORS_HTTP, featureFlag);
props.addProperty(FeatureFlags.DISABLE_RPC_INSTANCE_RETRY, "true");
props.addProperty(ServiceProperties.REGISTRY_SERVER_KEY, "localhost:65432");
props.addProperty("registry", "consul");
module.setServiceProperties(props);
Injector injector = Guice.createInjector(module, new ServiceRegistryModule(props), new TracingModule(props));
httpClient = (MockHttpClient)injector.getInstance(HttpClient.class);
clientFactory = injector.getInstance(RpcClientFactory.class);
loadBalancerFactory = injector.getInstance(LoadBalancerFactory.class);
rpcClient = clientFactory.newClient(serviceName, "testing", FrameworkTest.Foobar.class).build();
loadBalancer = (LoadBalancerImpl) loadBalancerFactory.getLoadBalancer(serviceName);
}
示例11: setup
import org.eclipse.jetty.client.HttpClient; //導入依賴的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");
}
示例12: createProducer
import org.eclipse.jetty.client.HttpClient; //導入依賴的package包/類
@Override
public Producer createProducer() throws Exception {
JettyHttpProducer answer = new JettyHttpProducer(this);
if (client != null) {
// use shared client, and ensure its started so we can use it
client.start();
answer.setSharedClient(client);
answer.setBinding(getJettyBinding(client));
} else {
HttpClient httpClient = createJettyHttpClient();
answer.setClient(httpClient);
answer.setBinding(getJettyBinding(httpClient));
}
if (isSynchronous()) {
return new SynchronousDelegateProducer(answer);
} else {
return answer;
}
}
示例13: createJettyHttpClient
import org.eclipse.jetty.client.HttpClient; //導入依賴的package包/類
protected HttpClient createJettyHttpClient() throws Exception {
// create a new client
// thread pool min/max from endpoint take precedence over from component
Integer min = httpClientMinThreads != null ? httpClientMinThreads : getComponent().getHttpClientMinThreads();
Integer max = httpClientMaxThreads != null ? httpClientMaxThreads : getComponent().getHttpClientMaxThreads();
HttpClient httpClient = getComponent().createHttpClient(this, min, max, sslContextParameters);
// set optional http client parameters
if (httpClientParameters != null) {
// copy parameters as we need to re-use them again if creating a new producer later
Map<String, Object> params = new HashMap<String, Object>(httpClientParameters);
// Can not be set on httpClient for jetty 9
params.remove("timeout");
IntrospectionSupport.setProperties(httpClient, params);
// validate we could set all parameters
if (params.size() > 0) {
throw new ResolveEndpointFailedException(getEndpointUri(), "There are " + params.size()
+ " parameters that couldn't be set on the endpoint."
+ " Check the uri if the parameters are spelt correctly and that they are properties of the endpoint."
+ " Unknown parameters=[" + params + "]");
}
}
return httpClient;
}
示例14: 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;
}
示例15: 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();
}
}