Skip to content
Closed
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
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ allprojects {

withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.compilerArgs.addAll(listOf("-Xlint:deprecation,-options", "-Werror"))
}
withType<Test>().configureEach {
testLogging {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.calcite.avatica.ha.ShuffledRoundRobinLBStrategy;
import org.apache.calcite.avatica.remote.AvaticaHttpClientFactoryImpl;
import org.apache.calcite.avatica.remote.HostnameVerificationConfigurable.HostnameVerification;

import org.apache.hc.core5.util.Timeout;

Expand Down Expand Up @@ -92,8 +91,13 @@ public enum BuiltInConnectionProperty implements ConnectionProperty {
/** Password for the key inside keystore */
KEY_PASSWORD("key_password", Type.STRING, "", false),

HOSTNAME_VERIFICATION("hostname_verification", Type.ENUM, HostnameVerification.STRICT,
HostnameVerification.class, false),
@SuppressWarnings("deprecation")
HOSTNAME_VERIFICATION("hostname_verification", Type.ENUM,
org.apache.calcite.avatica.remote.
HostnameVerificationConfigurable.HostnameVerification.STRICT,
org.apache.calcite.avatica.remote.
HostnameVerificationConfigurable.HostnameVerification.class,
false),

TRANSPARENT_RECONNECTION("transparent_reconnection", Type.BOOLEAN, Boolean.FALSE, false),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.calcite.avatica.ha.LBStrategy;
import org.apache.calcite.avatica.remote.AvaticaHttpClientFactory;
import org.apache.calcite.avatica.remote.HostnameVerificationConfigurable.HostnameVerification;
import org.apache.calcite.avatica.remote.Service;

import java.io.File;
Expand Down Expand Up @@ -64,7 +63,9 @@ public interface ConnectionConfig {
/** @see BuiltInConnectionProperty#KEY_PASSWORD */
String keyPassword();
/** @see BuiltInConnectionProperty#HOSTNAME_VERIFICATION */
HostnameVerification hostnameVerification();
@SuppressWarnings("deprecation")
org.apache.calcite.avatica.remote.
HostnameVerificationConfigurable.HostnameVerification hostnameVerification();
/** @see BuiltInConnectionProperty#TRANSPARENT_RECONNECTION */
boolean transparentReconnectionEnabled();
/** @see BuiltInConnectionProperty#FETCH_SIZE */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.calcite.avatica.ha.LBStrategy;
import org.apache.calcite.avatica.remote.AvaticaHttpClientFactory;
import org.apache.calcite.avatica.remote.HostnameVerificationConfigurable.HostnameVerification;
import org.apache.calcite.avatica.remote.Service;

import java.io.File;
Expand Down Expand Up @@ -130,9 +129,12 @@ public String keyPassword() {

}

public HostnameVerification hostnameVerification() {
@SuppressWarnings("deprecation")
public org.apache.calcite.avatica.remote.
HostnameVerificationConfigurable.HostnameVerification hostnameVerification() {
return BuiltInConnectionProperty.HOSTNAME_VERIFICATION.wrap(properties)
.getEnum(HostnameVerification.class);
.getEnum(org.apache.calcite.avatica.remote.
HostnameVerificationConfigurable.HostnameVerification.class);
}

@Override public boolean transparentReconnectionEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.Credentials;
import org.apache.hc.client5.http.auth.CredentialsProvider;
import org.apache.hc.client5.http.auth.KerberosConfig;
import org.apache.hc.client5.http.auth.KerberosCredentials;
import org.apache.hc.client5.http.auth.StandardAuthScheme;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.classic.methods.HttpPost;
Expand All @@ -34,7 +32,6 @@
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
import org.apache.hc.client5.http.impl.auth.BasicSchemeFactory;
import org.apache.hc.client5.http.impl.auth.DigestSchemeFactory;
import org.apache.hc.client5.http.impl.auth.SPNegoSchemeFactory;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.classic.HttpClients;
Expand Down Expand Up @@ -78,8 +75,10 @@ public class AvaticaCommonsHttpClientImpl implements AvaticaHttpClient, HttpClie
private static final boolean USE_CANONICAL_HOSTNAME = Boolean
.parseBoolean(System.getProperty("avatica.http.spnego.use_canonical_hostname", "true"));
private static final boolean STRIP_PORT_ON_SERVER_LOOKUP = true;
private static final KerberosConfig KERBEROS_CONFIG =
KerberosConfig.custom().setStripPort(STRIP_PORT_ON_SERVER_LOOKUP)
@SuppressWarnings("deprecation")
private static final org.apache.hc.client5.http.auth.KerberosConfig KERBEROS_CONFIG =
org.apache.hc.client5.http.auth.KerberosConfig.custom()
.setStripPort(STRIP_PORT_ON_SERVER_LOOKUP)
.setUseCanonicalHostname(USE_CANONICAL_HOSTNAME)
.build();
private static AuthScope anyAuthScope = new AuthScope(null, -1);
Expand All @@ -98,10 +97,15 @@ public class AvaticaCommonsHttpClientImpl implements AvaticaHttpClient, HttpClie
protected long connectTimeout;
protected long responseTimeout;

@Deprecated
public AvaticaCommonsHttpClientImpl(URL url) {
this.uri = toURI(Objects.requireNonNull(url));
}

public AvaticaCommonsHttpClientImpl(URI uri) {
this.uri = uri;
}

protected void initializeClient(PoolingHttpClientConnectionManager pool,
ConnectionConfig config) {
this.authCache = new BasicAuthCache();
Expand All @@ -128,6 +132,7 @@ protected void initializeClient(PoolingHttpClientConnectionManager pool,
}

// This is needed because we initialize the client object too early.
@SuppressWarnings("deprecation")
private RequestConfig createRequestConfig() {
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
requestConfigBuilder
Expand Down Expand Up @@ -225,19 +230,23 @@ ClassicHttpResponse executeOpen(HttpHost httpHost, HttpPost post, HttpClientCont
context.setRequestConfig(createRequestConfig());
}

@SuppressWarnings("deprecation")
@Override public void setGSSCredential(GSSCredential credential) {

this.authRegistry = RegistryBuilder.<AuthSchemeFactory>create()
.register(StandardAuthScheme.SPNEGO,
new SPNegoSchemeFactory(KERBEROS_CONFIG, SystemDefaultDnsResolver.INSTANCE))
new org.apache.hc.client5.http.impl.auth.SPNegoSchemeFactory(
KERBEROS_CONFIG,
SystemDefaultDnsResolver.INSTANCE))
.build();

this.credentialsProvider = new BasicCredentialsProvider();
if (null != credential) {
// Non-null credential should be used directly with KerberosCredentials.
// This is never set by the JDBC driver, nor the tests
((BasicCredentialsProvider) this.credentialsProvider)
.setCredentials(anyAuthScope, new KerberosCredentials(credential));
.setCredentials(anyAuthScope,
new org.apache.hc.client5.http.auth.KerberosCredentials(credential));
} else {
// A null credential implies that the user is logged in via JAAS using the
// java.security.auth.login.config system property
Expand All @@ -255,6 +264,7 @@ ClassicHttpResponse executeOpen(HttpHost httpHost, HttpPost post, HttpClientCont
private static class EmptyCredentials implements Credentials {
public static final EmptyCredentials INSTANCE = new EmptyCredentials();

@Deprecated
@Override public char[] getPassword() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static AvaticaHttpClientFactoryImpl getInstance() {
return INSTANCE;
}

@SuppressWarnings("deprecation")
@Override public AvaticaHttpClient getClient(URL url, ConnectionConfig config,
KerberosConnection kerberosUtil) {
String className = config.httpClientClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.calcite.avatica.remote;

import org.apache.calcite.avatica.ConnectionConfig;
import org.apache.calcite.avatica.remote.HostnameVerificationConfigurable.HostnameVerification;

import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
Expand Down Expand Up @@ -128,11 +127,15 @@ private static void loadTrustStore(SSLContextBuilder sslContextBuilder, Connecti
* @throws IllegalArgumentException if the provided verification cannot be
* handled.
*/
private static HostnameVerifier getHostnameVerifier(HostnameVerification verification) {
@SuppressWarnings("deprecation")
private static HostnameVerifier getHostnameVerifier(
org.apache.calcite.avatica.remote.
HostnameVerificationConfigurable.HostnameVerification verification) {
// Normally, the configuration logic would give us a default of STRICT if it was
// not provided by the user. It's easy for us to do a double-check.
if (verification == null) {
verification = HostnameVerification.STRICT;
verification = org.apache.calcite.avatica.remote.
HostnameVerificationConfigurable.HostnameVerification.STRICT;
}
switch (verification) {
case STRICT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.slf4j.LoggerFactory;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.sql.Connection;
import java.sql.SQLException;
Expand Down Expand Up @@ -156,8 +158,8 @@ AvaticaHttpClient getHttpClient(AvaticaConnection connection, ConnectionConfig c
urlStr = config.url();
}
try {
url = new URL(urlStr);
} catch (MalformedURLException e) {
url = new URI(urlStr).toURL();
} catch (MalformedURLException | URISyntaxException e) {
throw new RuntimeException(e);
}

Expand Down
10 changes: 3 additions & 7 deletions core/src/main/java/org/apache/calcite/avatica/util/Sources.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public static Source file(File baseDirectory, String fileName) {

public static Source url(String url) {
try {
return of(new URL(url));
} catch (MalformedURLException | IllegalArgumentException e) {
return of(new URI(url).toURL());
} catch (MalformedURLException | IllegalArgumentException | URISyntaxException e) {
throw new RuntimeException("Malformed URL: '" + url + "'", e);
}
}
Expand Down Expand Up @@ -133,11 +133,7 @@ private static URL fileToUrl(File file) {
filePath += "/";
}
try {
// We need to encode path. For instance, " " should become "%20"
// That is why java.net.URLEncoder.encode(java.lang.String, java.lang.String) is not
// suitable because it replaces " " with "+".
String encodedPath = new URI(null, null, filePath, null).getRawPath();
return new URL("file", null, 0, encodedPath);
return new URI("file", filePath, null).toURL();
} catch (MalformedURLException | URISyntaxException e) {
throw new IllegalArgumentException("Unable to create URL for file " + filePath, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
import java.util.TimeZone;

import static org.hamcrest.CoreMatchers.isA;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
package org.apache.calcite.avatica;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.sql.Connection;
import java.sql.ResultSet;
Expand All @@ -27,6 +25,7 @@
import java.util.Properties;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

/**
Expand All @@ -36,9 +35,6 @@
*/
public class AvaticaResultSetThrowsSqlExceptionTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

/**
* A fake test driver for test.
*/
Expand Down Expand Up @@ -81,8 +77,7 @@ private ResultSet getResultSet() throws SQLException {
try (Connection connection = driver.connect("jdbc:test", properties);
ResultSet resultSet =
connection.createStatement().executeQuery("SELECT * FROM TABLE")) {
thrown.expect(SQLFeatureNotSupportedException.class);
resultSet.previous();
assertThrows(SQLFeatureNotSupportedException.class, resultSet::previous);
}
}

Expand All @@ -94,8 +89,7 @@ private ResultSet getResultSet() throws SQLException {
try (Connection connection = driver.connect("jdbc:test", properties);
ResultSet resultSet =
connection.createStatement().executeQuery("SELECT * FROM TABLE")) {
thrown.expect(SQLFeatureNotSupportedException.class);
resultSet.updateNull(1);
assertThrows(SQLFeatureNotSupportedException.class, () -> resultSet.updateNull(1));
}
}

Expand All @@ -119,8 +113,7 @@ private ResultSet getResultSet() throws SQLException {
assertTrue(resultSet.isClosed());

// once closed, next should fail
thrown.expect(SQLException.class);
resultSet.next();
assertThrows(SQLException.class, resultSet::next);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import java.nio.file.Paths;
import java.util.Properties;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

/**
* Test class for {@link ConnectionConfigImpl}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import java.util.Objects;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
* Test class for {@link ConnectionPropertiesImpl}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private static class MetaImplWithHardCodedResult extends MetaImpl {
return null;
}

@Deprecated
@Override public ExecuteResult prepareAndExecute(StatementHandle h, String sql,
long maxRowCount,
PrepareCallback callback) {
Expand Down Expand Up @@ -87,6 +88,7 @@ private static class MetaImplWithHardCodedResult extends MetaImpl {
return new Frame(offset, done, next);
}

@Deprecated
@Override public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues,
long maxRowCount)
throws NoSuchStatementException {
Expand Down
Loading