Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump httpclient to 4.5.13 and fix start with 'jdbc:' problem #235

Merged
merged 1 commit into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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