Java源码示例:com.ecwid.consul.v1.ConsulRawClient
示例1
@Test
public void verifyDefaultUrl() throws Exception {
// Given
HttpClient httpClient = mock(HttpClient.class);
ConsulRawClient client = ConsulRawClient.Builder.builder()
.setHttpClient(httpClient)
.setHost(HOST)
.setPort(PORT)
.build();
// When
client.makeGetRequest(ENDPOINT, EMPTY_QUERY_PARAMS);
// Then
ArgumentCaptor<HttpUriRequest> calledUri = ArgumentCaptor.forClass(HttpUriRequest.class);
verify(httpClient).execute(calledUri.capture(), any(ResponseHandler.class));
assertEquals(EXPECTED_AGENT_ADDRESS_NO_PATH, calledUri.getValue().getURI().toString());
}
示例2
@Test
public void verifyUrlWithPath() throws Exception {
// Given
HttpClient httpClient = mock(HttpClient.class);
ConsulRawClient client = ConsulRawClient.Builder.builder()
.setHttpClient(httpClient)
.setHost(HOST)
.setPort(PORT)
.setPath(PATH)
.build();
// When
client.makeGetRequest(ENDPOINT, EMPTY_QUERY_PARAMS);
// Then
ArgumentCaptor<HttpUriRequest> calledUri = ArgumentCaptor.forClass(HttpUriRequest.class);
verify(httpClient).execute(calledUri.capture(), any(ResponseHandler.class));
assertEquals(EXPECTED_AGENT_ADDRESS, calledUri.getValue().getURI().toString());
}
示例3
@Bean
@Primary
public ConsulClient consulClient(ConsulProperties consulProperties,
ConsulConfigProperties consulConfigProperties) {
final int agentPort = consulProperties.getPort();
final String agentHost = !StringUtils.isEmpty(consulProperties.getScheme())
? consulProperties.getScheme() + "://" + consulProperties.getHost()
: consulProperties.getHost();
logger.info("Init consul host: " + agentHost + " port: " + agentPort);
if (consulProperties.getTls() != null) {
ConsulProperties.TLSConfig tls = consulProperties.getTls();
TLSConfig tlsConfig = new TLSConfig(
tls.getKeyStoreInstanceType(),
tls.getCertificatePath(),
tls.getCertificatePassword(),
tls.getKeyStorePath(),
tls.getKeyStorePassword()
);
return new ConsulClient(agentHost, agentPort, tlsConfig);
}
HttpRequestInterceptor httpRequestInterceptor = new BmsCommonInterceptor();
BmsHttpTransport httpTransport = new BmsHttpTransport(httpRequestInterceptor);
ConsulRawClient rawClient = new ConsulRawClient(httpTransport.getHttpClient(),
agentHost, agentPort, consulConfigProperties.getPath());
return new ConsulClient(rawClient);
}
示例4
@Test
public void tlsConfigured() {
CatalogConsulClient client = (CatalogConsulClient) ReflectionTestUtils
.getField(this.consulClient, "catalogClient");
ConsulRawClient rawClient = (ConsulRawClient) ReflectionTestUtils.getField(client,
"rawClient");
HttpTransport httpTransport = (HttpTransport) ReflectionTestUtils
.getField(rawClient, "httpTransport");
assertThat(httpTransport).isInstanceOf(DefaultHttpsTransport.class);
}
示例5
public static ConsulClient createClient(String apiAddress, int apiPort, TlsConfiguration tlsConfiguration) throws Exception {
HttpClient httpClient = createHttpClient(tlsConfiguration.getClientCert(), tlsConfiguration.getClientKey(), tlsConfiguration.getServerCert());
ConsulRawClient rawClient = new ConsulRawClient("https://" + apiAddress + ':' + apiPort, httpClient);
Field agentAddress = ReflectionUtils.findField(ConsulRawClient.class, "agentAddress");
ReflectionUtils.makeAccessible(agentAddress);
ReflectionUtils.setField(agentAddress, rawClient, "https://" + apiAddress + ':' + apiPort + "/consul");
return new ConsulClient(rawClient);
}
示例6
public AclConsulClient(ConsulRawClient rawClient) {
this.rawClient = rawClient;
}
示例7
public AclConsulClient() {
this(new ConsulRawClient());
}
示例8
public AclConsulClient(TLSConfig tlsConfig) {
this(new ConsulRawClient(tlsConfig));
}
示例9
public AclConsulClient(String agentHost) {
this(new ConsulRawClient(agentHost));
}
示例10
public AclConsulClient(String agentHost, TLSConfig tlsConfig) {
this(new ConsulRawClient(agentHost, tlsConfig));
}
示例11
public AclConsulClient(String agentHost, int agentPort) {
this(new ConsulRawClient(agentHost, agentPort));
}
示例12
public AclConsulClient(String agentHost, int agentPort, TLSConfig tlsConfig) {
this(new ConsulRawClient(agentHost, agentPort, tlsConfig));
}
示例13
public StatusConsulClient(ConsulRawClient rawClient) {
this.rawClient = rawClient;
}
示例14
public StatusConsulClient() {
this(new ConsulRawClient());
}
示例15
public StatusConsulClient(TLSConfig tlsConfig) {
this(new ConsulRawClient(tlsConfig));
}
示例16
public StatusConsulClient(String agentHost) {
this(new ConsulRawClient(agentHost));
}
示例17
public StatusConsulClient(String agentHost, TLSConfig tlsConfig) {
this(new ConsulRawClient(agentHost, tlsConfig));
}
示例18
public StatusConsulClient(String agentHost, int agentPort) {
this(new ConsulRawClient(agentHost, agentPort));
}
示例19
public StatusConsulClient(String agentHost, int agentPort, TLSConfig tlsConfig) {
this(new ConsulRawClient(agentHost, agentPort, tlsConfig));
}
示例20
public QueryConsulClient(String agentHost) {
this(new ConsulRawClient(agentHost));
}
示例21
public QueryConsulClient(String agentHost, TLSConfig tlsConfig) {
this(new ConsulRawClient(agentHost, tlsConfig));
}
示例22
public QueryConsulClient(String agentHost, int agentPort) {
this(new ConsulRawClient(agentHost, agentPort));
}
示例23
public QueryConsulClient(String agentHost, int agentPort, TLSConfig tlsConfig) {
this(new ConsulRawClient(agentHost, agentPort, tlsConfig));
}
示例24
public SessionConsulClient(ConsulRawClient rawClient) {
this.rawClient = rawClient;
}
示例25
public SessionConsulClient() {
this(new ConsulRawClient());
}
示例26
public SessionConsulClient(String agentHost) {
this(new ConsulRawClient(agentHost));
}
示例27
public SessionConsulClient(String agentHost, int agentPort) {
this(new ConsulRawClient(agentHost, agentPort));
}
示例28
public AgentConsulClient(ConsulRawClient rawClient) {
this.rawClient = rawClient;
}
示例29
public AgentConsulClient() {
this(new ConsulRawClient());
}
示例30
public AgentConsulClient(TLSConfig tlsConfig) {
this(new ConsulRawClient(tlsConfig));
}