Skip to content

Commit

Permalink
Bump httpclient to 4.5.13 and fix start with 'jdbc:' problem
Browse files Browse the repository at this point in the history
  • Loading branch information
coderzc committed Dec 22, 2021
1 parent 21e0c8f commit 566b456
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.tukaani</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

package com.baidu.hugegraph.loader.source.jdbc;

import java.net.URISyntaxException;

import org.apache.http.client.utils.URIBuilder;

import com.baidu.hugegraph.loader.constant.Constants;
import com.baidu.hugegraph.loader.reader.line.Line;
import com.baidu.hugegraph.loader.exception.LoadException;
import com.baidu.hugegraph.loader.reader.jdbc.JDBCUtil;
import com.baidu.hugegraph.loader.reader.line.Line;
import com.baidu.hugegraph.util.E;

public enum JDBCVendor {
Expand Down Expand Up @@ -283,6 +286,8 @@ public String checkSchema(JDBCSource source) {
return schema == null ? this.defaultSchema(source) : schema;
}

private static final String JDBC_PREFIX = "jdbc:";

public String buildUrl(JDBCSource source) {
String url = source.url();
if (url.endsWith("/")) {
Expand All @@ -291,14 +296,23 @@ public String buildUrl(JDBCSource source) {
url = String.format("%s/%s", url, source.database());
}

URIBuilder uriBuilder = new URIBuilder();
uriBuilder.setPath(url)
.setParameter("useSSL", "false")
E.checkArgument(url.startsWith(JDBC_PREFIX),
"The url must start with '%s': '%s'",
JDBC_PREFIX, url);
String urlWithoutJdbc = url.substring(JDBC_PREFIX.length());

URIBuilder uriBuilder;
try {
uriBuilder = new URIBuilder(urlWithoutJdbc);
} catch (URISyntaxException e) {
throw new LoadException("Invalid url '%s'", e, url);
}
uriBuilder.setParameter("useSSL", "false")
.setParameter("characterEncoding", Constants.CHARSET.name())
.setParameter("rewriteBatchedStatements", "true")
.setParameter("useServerPrepStmts", "false")
.setParameter("autoReconnect", "true");
return uriBuilder.toString();
return JDBC_PREFIX + uriBuilder.toString();
}

public abstract String buildGetHeaderSql(JDBCSource source);
Expand Down

0 comments on commit 566b456

Please sign in to comment.