| 36 | import java.util.List; |
| 37 | |
| 38 | public class App { |
| 39 | |
| 40 | public static void main(String[] args) throws IOException { |
| 41 | Path certificatePath = Paths.get("elasticsearch-with-ssl/elasticsearch-docker/ca.crt").normalize().toAbsolutePath(); |
| 42 | List<Certificate> certificates = CertificateUtils.loadCertificate(certificatePath); |
| 43 | SSLFactory sslFactory = SSLFactory.builder() |
| 44 | .withTrustMaterial(certificates) |
| 45 | .build(); |
| 46 | |
| 47 | CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
| 48 | credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", "PleaseChangeMe")); |
| 49 | |
| 50 | RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200, "https")) |
| 51 | .setHttpClientConfigCallback(httpClientBuilder -> |
| 52 | httpClientBuilder.setSSLContext(sslFactory.getSslContext()).setDefaultCredentialsProvider(credentialsProvider)) |
| 53 | .build(); |
| 54 | |
| 55 | ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper()); |
| 56 | ElasticsearchClient client = new ElasticsearchClient(transport); |
| 57 | |
| 58 | HealthResponse healthResponse = client.cluster().health(); |
| 59 | System.out.printf("Elasticsearch status is: [%s]", healthResponse.status()); |
| 60 | |
| 61 | restClient.close(); |
| 62 | } |
| 63 | |
| 64 | } |
nothing calls this directly
no outgoing calls
no test coverage detected