Is it possible to add a record to the dns cache from java? Or will I have to use the JNI?
Is it possible to add a record to the dns cache from java? Or will I have to use the JNI?
Assuming that you are talking about the DNS cache that Java applications use, the answer is No in both cases.
The cache is implemented in the java.net.InetAddress class; refer here for the source code. As you can see, the cache is implemented using private static attributes and all of the classes and methods involved are private or package private. In short, the only way you could get at the cache would be by using nasty reflection tricks to subvert the Java access rules.
Since this is implemented in pure Java, JNI won't help.
EDIT
Unfortunately, the link above no longer points to the OpenJDK code :-(.
Java DNS caching is implemented in a manner that should be mostly transparent to your code. You can read the javadoc of InetAddress to learn more about how you can configure the cache. But since it serves as a JVM-wide transparent proxy, the best way you have to add a cache entry would simply be to actually issue a request directed to the domain you want to cache the info for.
Out of curiosity, what's your use case?
Why don't you just configure java for using the proxy?
java -DproxySet=true -DproxyHost=proxy -DproxyPort=8080 MyApp
or
System.setProperty("proxyPort","8080");
System.setProperty("proxyHost","proxy");
will do it.