Saturday, December 5, 2015

Trust CA certificate in Java JDK on Mac OS X 10.11

Replace jdk1.8.0_66.jdk with your JDK version. You will need to run this for each major version you have installed (1.7, 1.8, etc.).

cd /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/jre/lib/security/
cp cacerts cacerts.bak
sudo keytool -importcert -file myca.crt -keystore cacerts

Thank http://blog.alwold.com/2011/06/30/how-to-trust-a-certificate-in-java-on-mac-os-x/

Thursday, November 19, 2015

Update Trusted CA Certificates for Eclipse Tomcat Debugger on OS X

If you run the debugger in Eclipse, it will use the Java certificate store for verifying the chain of trust of certificates. I had a problem where the Eclipse debugger wouldn't connect to a server whose certificate was signed by my CA, even though OS X trusted the CA in Keychain. Turns out you have to add it to the cacerts file in the Java folder using command line. Check it: http://blog.alwold.com/2011/06/30/how-to-trust-a-certificate-in-java-on-mac-os-x/

Thursday, November 5, 2015

Monday, November 2, 2015

Make your Windows domain controllers NTP servers

Thanks to the author! This works great on my Windows 2012 R2 servers for serving NTP to all the Cisco Collaboration / Contact Center components in the network.

http://htluo.blogspot.com/2009/02/ntp-network-time-protocol.html

Fix the Windows Time Service on domain controllers

Finally, a set of commands that fixes the time service on my Windows domain controllers:

http://blogs.msmvps.com/acefekay/2009/09/18/configuring-the-windows-time-service-for-windows-server/

Note that when you run the "net time /setsntp: " command, it will successfully clear the registry settings for the time service, but the console will print the command help text as though you had entered an incorrect command option.

Friday, September 4, 2015

Java ProcessBuilder has 32KB buffer, .waitFor() hangs if it isn't cleared

If you're running a simple Java ProcessBuilder, and it hangs and never returns when you start it and then run .waitFor() without running separate threads to make sure it finishes nicely, it may be because the ProcessBuilder is out of memory in its STDOUT buffer. The buffer is 32KB, so if your process returns more data than that and you're just trying to do a simple, synchronous .waitFor() call and just wait for it to return with all the data, it will never return if it hits this buffer limit. You must either consume the buffer, use threads, or redirect the output somewhere, like a temporary file. Kudos to "kjkoster" on this thread for the idead and code: http://java-monitor.com/forum/showthread.php?t=4067.

It goes something like this:
final File tmp = File.createTempFile("out", null);
try {
    tmp.deleteOnExit();

    final ProcessBuilder processBuilder = new ProcessBuilder();
    processBuilder.command("cat", filename).redirectErrorStream(true).redirectOutput(tmp);
    final Process process = processBuilder.start();
    final int exitCode = process.waitFor();

    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(tmp)));
    String line = "";   
    while ((line = reader.readLine())!= null) {
        System.out.println(line);
    }
    reader.close();
    tmp.delete();
} finally {
    tmp.delete();
}

Tuesday, August 11, 2015

Example context.xml for JNDI resource for MSSQL with Windows authentication

<Resource name="jdbc/mydb"
        auth="Container"
        driverClassName="net.sourceforge.jtds.jdbc.Driver"
        maxActive="100"
        maxIdle="30"
        maxWait="10000"
        removeAbandoned="true"
        removeAbandonedTimeout="60"
        autoReconnect="true"
        logAbandoned="true"
        username="username"
        password="password"
        type="javax.sql.DataSource"
        url="jdbc:jtds:sqlserver://myserver.mydomain.com:1433;databaseName=mydb;useNTLMv2=true;domain=mydomain;"
        validationQuery="SELECT 1"
        validationQueryTimeout="1000"
        testOnBorrow="true" />