Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.stream.Collectors;
import javax.naming.Context;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
Expand Down Expand Up @@ -51,13 +53,19 @@ class JndiDnsResolver implements DnsResolver {
* @throws javax.naming.NameNotFoundException when the domain name did not resolve.
*/
@Override
@SuppressWarnings("JdkObsolete")
public Collection<String> resolveTxt(String domainName)
throws javax.naming.NameNotFoundException {
try {
// Notice: This is old Java 1.2 style code. It uses the ancient JNDI DNS Provider api.
// See https://docs.oracle.com/javase/7/docs/technotes/guides/jndi/jndi-dns.html

// Explicitly reference the JNDI DNS classes. This is required for GraalVM.
Hashtable contextProps = new Hashtable<>();
contextProps.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
contextProps.put(Context.OBJECT_FACTORIES, "com.sun.jndi.url.dns.dnsURLContextFactory");
Attribute attr =
new InitialDirContext()
new InitialDirContext(contextProps)
.getAttributes(jndiPrefix + domainName, new String[] {"TXT"})
.get("TXT");
// attr.getAll() returns a Vector containing strings, one for each record returned by dns.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ final class CloudSqlFeature implements Feature {
private static final String POSTGRES_SOCKET_CLASS = "com.google.cloud.sql.postgres.SocketFactory";

private static final String MYSQL_SOCKET_CLASS = "com.google.cloud.sql.mysql.SocketFactory";
private static final String JNDI_DNS_FACTORY = "com.sun.jndi.dns.DnsContextFactory";
private static final String JNDI_DNS_OBJECT_FACTORY = "com.sun.jndi.url.dns.dnsURLContextFactory";

@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
Expand All @@ -55,6 +57,10 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
// The Core Cloud SQL Socket
NativeImageUtils.registerClassForReflection(access, CLOUD_SQL_SOCKET_CLASS);

// The JNDI DNS factory for looking up DNS names.
NativeImageUtils.registerClassForReflection(access, JNDI_DNS_FACTORY);
NativeImageUtils.registerClassForReflection(access, JNDI_DNS_OBJECT_FACTORY);

// Register Hikari configs if used with Cloud SQL.
if (access.findClassByName("com.zaxxer.hikari.HikariConfig") != null) {
NativeImageUtils.registerClassForReflection(access, "com.zaxxer.hikari.HikariConfig");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@
"jnr.enxio.channels.Native$LibC",
"jnr.ffi.provider.LoadedLibrary"
]
},
{
"name": "com.sun.jndi.dns.DnsContextFactory",
"interfaces": [
"javax.naming.spi.InitialContextFactory"
]
},
{
"name": "com.sun.jndi.url.dns.dnsURLContextFactory",
"interfaces": [
"javax.naming.spi.ObjectFactory"
]
}
]
Loading