You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/09/10 01:05:10 UTC
[iotdb] branch master updated: [IOTDB-4384] Add influxdb and rest modules to the pom file of the example module and rename inflxudb-protocol-example to influxdb-protocol-example (#7288)
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 7ba099a074 [IOTDB-4384] Add influxdb and rest modules to the pom file of the example module and rename inflxudb-protocol-example to influxdb-protocol-example (#7288)
7ba099a074 is described below
commit 7ba099a07440b09366b1b8d48bcfc394c1038346
Author: Zhang Jian <38...@users.noreply.github.com>
AuthorDate: Sat Sep 10 09:05:02 2022 +0800
[IOTDB-4384] Add influxdb and rest modules to the pom file of the example module and rename inflxudb-protocol-example to influxdb-protocol-example (#7288)
---
.../pom.xml | 4 +-
.../org/apache/iotdb/influxdb/InfluxDBExample.java | 0
example/pom.xml | 2 +
.../main/java/org/apache/iotdb/HttpExample.java | 7 +--
.../main/java/org/apache/iotdb/HttpsExample.java | 16 +++---
.../src/main/java/org/apache/iotdb/SSLClient.java | 65 +++++++++++++---------
6 files changed, 53 insertions(+), 41 deletions(-)
diff --git a/example/inflxudb-protocol-example/pom.xml b/example/influxdb-protocol-example/pom.xml
similarity index 94%
rename from example/inflxudb-protocol-example/pom.xml
rename to example/influxdb-protocol-example/pom.xml
index 01892bcb1e..ef1b109118 100644
--- a/example/inflxudb-protocol-example/pom.xml
+++ b/example/influxdb-protocol-example/pom.xml
@@ -27,8 +27,8 @@
<version>0.14.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
- <artifactId>inflxudb-protocol-example</artifactId>
- <name>inflxudb-protocol-example</name>
+ <artifactId>influxdb-protocol-example</artifactId>
+ <name>influxdb-protocol-example</name>
<dependencies>
<dependency>
<groupId>org.apache.iotdb</groupId>
diff --git a/example/inflxudb-protocol-example/src/main/java/org/apache/iotdb/influxdb/InfluxDBExample.java b/example/influxdb-protocol-example/src/main/java/org/apache/iotdb/influxdb/InfluxDBExample.java
similarity index 100%
rename from example/inflxudb-protocol-example/src/main/java/org/apache/iotdb/influxdb/InfluxDBExample.java
rename to example/influxdb-protocol-example/src/main/java/org/apache/iotdb/influxdb/InfluxDBExample.java
diff --git a/example/pom.xml b/example/pom.xml
index 53d5c9e087..0f84881949 100644
--- a/example/pom.xml
+++ b/example/pom.xml
@@ -47,6 +47,8 @@
<module>udf</module>
<module>trigger</module>
<module>rabbitmq</module>
+ <module>rest-java-example</module>
+ <module>influxdb-protocol-example</module>
</modules>
<build>
<pluginManagement>
diff --git a/example/rest-java-example/src/main/java/org/apache/iotdb/HttpExample.java b/example/rest-java-example/src/main/java/org/apache/iotdb/HttpExample.java
index 532a266594..2ace9032c8 100644
--- a/example/rest-java-example/src/main/java/org/apache/iotdb/HttpExample.java
+++ b/example/rest-java-example/src/main/java/org/apache/iotdb/HttpExample.java
@@ -44,9 +44,9 @@ public class HttpExample {
public static void main(String[] args) {
HttpExample httpExample = new HttpExample();
- httpExample.ping();
- httpExample.insertTablet();
- httpExample.query();
+ httpExample.ping();
+ httpExample.insertTablet();
+ httpExample.query();
}
public void ping() {
@@ -76,7 +76,6 @@ public class HttpExample {
}
}
-
private HttpPost getHttpPost(String url) {
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-type", "application/json; charset=utf-8");
diff --git a/example/rest-java-example/src/main/java/org/apache/iotdb/HttpsExample.java b/example/rest-java-example/src/main/java/org/apache/iotdb/HttpsExample.java
index d9932dc9e4..c29545f7df 100644
--- a/example/rest-java-example/src/main/java/org/apache/iotdb/HttpsExample.java
+++ b/example/rest-java-example/src/main/java/org/apache/iotdb/HttpsExample.java
@@ -22,11 +22,6 @@ package org.apache.iotdb;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.Base64;
-import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
@@ -35,6 +30,12 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.Map;
+
public class HttpsExample {
private String getAuthorization(String username, String password) {
@@ -43,11 +44,10 @@ public class HttpsExample {
}
public static void main(String[] args) throws Exception {
- HttpsExample httpsExample=new HttpsExample();
+ HttpsExample httpsExample = new HttpsExample();
httpsExample.pingHttps();
httpsExample.insertTablet();
httpsExample.query();
-
}
public void pingHttps() throws Exception {
@@ -74,7 +74,6 @@ public class HttpsExample {
}
} catch (IOException e) {
e.printStackTrace();
-
}
}
}
@@ -140,5 +139,4 @@ public class HttpsExample {
}
}
}
-
}
diff --git a/example/rest-java-example/src/main/java/org/apache/iotdb/SSLClient.java b/example/rest-java-example/src/main/java/org/apache/iotdb/SSLClient.java
index faad2866cc..ed707ab0a6 100644
--- a/example/rest-java-example/src/main/java/org/apache/iotdb/SSLClient.java
+++ b/example/rest-java-example/src/main/java/org/apache/iotdb/SSLClient.java
@@ -19,11 +19,6 @@
package org.apache.iotdb;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
@@ -36,12 +31,18 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.ssl.SSLContextBuilder;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
public class SSLClient {
private static SSLConnectionSocketFactory sslConnectionSocketFactory = null;
private static PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = null;
private static SSLContextBuilder sslContextBuilder = null;
- private static ConnectionSocketFactory plainsf=null;
+ private static ConnectionSocketFactory plainsf = null;
private static class SSLClientInstance {
private static final SSLClient instance = new SSLClient();
@@ -50,34 +51,46 @@ public class SSLClient {
public static SSLClient getInstance() {
return SSLClientInstance.instance;
}
+
private SSLClient() {
try {
- sslContextBuilder = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
- @Override
- public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
- return true;
- }
- });
- plainsf = PlainConnectionSocketFactory
- .getSocketFactory();
- sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContextBuilder.build(), new String[]{"TLSv1.3"}, null, NoopHostnameVerifier.INSTANCE);
- Registry<ConnectionSocketFactory> registryBuilder = RegistryBuilder.<ConnectionSocketFactory>create()
- .register("http", plainsf)
- .register("https", sslConnectionSocketFactory)
- .build();
+ sslContextBuilder =
+ new SSLContextBuilder()
+ .loadTrustMaterial(
+ null,
+ new TrustStrategy() {
+ @Override
+ public boolean isTrusted(X509Certificate[] x509Certificates, String s)
+ throws CertificateException {
+ return true;
+ }
+ });
+ plainsf = PlainConnectionSocketFactory.getSocketFactory();
+ sslConnectionSocketFactory =
+ new SSLConnectionSocketFactory(
+ sslContextBuilder.build(),
+ new String[] {"TLSv1.3"},
+ null,
+ NoopHostnameVerifier.INSTANCE);
+ Registry<ConnectionSocketFactory> registryBuilder =
+ RegistryBuilder.<ConnectionSocketFactory>create()
+ .register("http", plainsf)
+ .register("https", sslConnectionSocketFactory)
+ .build();
poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(registryBuilder);
poolingHttpClientConnectionManager.setMaxTotal(10);
- } catch (NoSuchAlgorithmException|KeyStoreException|KeyManagementException e) {
+ } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
e.printStackTrace();
}
}
-
- public CloseableHttpClient getHttpClient() {
- CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory)
- .setConnectionManager(poolingHttpClientConnectionManager)
- .setConnectionManagerShared(true)
- .build();
+ public CloseableHttpClient getHttpClient() {
+ CloseableHttpClient httpClient =
+ HttpClients.custom()
+ .setSSLSocketFactory(sslConnectionSocketFactory)
+ .setConnectionManager(poolingHttpClientConnectionManager)
+ .setConnectionManagerShared(true)
+ .build();
return httpClient;
}
}