Showing posts with label commons. Show all posts
Showing posts with label commons. Show all posts

Sunday, September 08, 2013

Apache Commons IO File Monitoring Example

Here is another example from the archives of the mythical archana on File monitoring using Apache Commons I/O for file monitoring. I remember working on this to see if we could come up with a solution since we could not upgrade the application to Java SE 7. So this proof of concept was to try out a couple of different file monitoring options.

This example uses a FileAlterationListener to monitor file changes. It is simple to implement.

The code for the project can be found here: file-monitor

Thursday, July 05, 2012

Exporting Trusted Certificates in Java

I was trying to export some trusted certificates in Java, and I discovered that the default Java keytool will not do it much to my dismay. So I decided to write a little utility class to export the certificates into PEM files from X509 certificates so it would be easier to move them around.

I thought I would clean up my little tool, and share it with the world.

It requires the GlassFish webservices-osgi.jar which is located in the glassfish-3.1.2/glassfish/modules/ directory along with Apache commons-cli-1.2 and commons-io-2.1.

The application takes a couple of command line arguments to work. It has usages, but the project properties also shows all of them in action. You will need to set that up to match your environment in the IDE. Here is an example.

java -jar certificate-manager.jar -f /Applications/NetBeans/jboss-5.0.1.GA/server/default/conf/server.keystore -i "CN=John Yeary, OU=Development, O=Blue Lotus Software, L=Greenville, ST=South Carolina, C=US" -s 4f2ac2cf -p changeit -e

-----BEGIN CERTIFICATE-----
MIICgTCCAeqgAwIBAgIETyrCzzANBgkqhkiG9w0BAQUFADCBhDELMAkGA1UEBhMCVVMxFzAVBgNV
BAgTDlNvdXRoIENhcm9saW5hMRMwEQYDVQQHEwpHcmVlbnZpbGxlMRwwGgYDVQQKExNCbHVlIExv
dHVzIFNvZnR3YXJlMRQwEgYDVQQLEwtEZXZlbG9wbWVudDETMBEGA1UEAxMKSm9obiBZZWFyeTAe
Fw0xMjAyMDIxNzA3MjdaFw0xMjA1MDIxNzA3MjdaMIGEMQswCQYDVQQGEwJVUzEXMBUGA1UECBMO
U291dGggQ2Fyb2xpbmExEzARBgNVBAcTCkdyZWVudmlsbGUxHDAaBgNVBAoTE0JsdWUgTG90dXMg
U29mdHdhcmUxFDASBgNVBAsTC0RldmVsb3BtZW50MRMwEQYDVQQDEwpKb2huIFllYXJ5MIGfMA0G
CSqGSIb3DQEBAQUAA4GNADCBiQKBgQCa564RyVtq+i+L+BsA0YzmpY4WMkfEn++3s10AbUv/IidT
25TixYqc7ghOkA5HI0z893Gy/ozzB6sGJ6gk8W28VjlU0Y4r0NUhUALuDYnkReWeUiUp4ubPoj/G
71WWu8FFQul+DJWAL7c/963rui812HofQuEWnyZjenrXQMvAUwIDAQABMA0GCSqGSIb3DQEBBQUA
A4GBAECXGuLB/ZB33nGauRsW4kqjiPwpkUoc8N7h44JBVATGx210HzNufixYSqq+AQhW86X2DYJ0
yyBGawVQvpUWoBHCVmmNmu6XdYDfSaCUsPeEt0RoFezruTMz6kaedRwK4zP3H3gp6fHYyiq/mD2M
jTna0zCi4o25E3eiOGKvGBd9
-----END CERTIFICATE-----

The project was developed with NetBeans and GlassFish 3.1.2.

The NetBeans project files can be downloaded here: certificate-manager.zip

TrustedCertificatePEMExportUtility.java


Wednesday, October 27, 2010

Disabling Apache POI Logging

Jakarta POI LogoImage via Wikipedia
In order to effectively disable the logging functionality in Apache POI you must use an alternative logger. This is accomplished by providing a property to the POILogFactory to override the default logger. Examining the partial code from the POILogFactory, we see that we can pass a logger name into it.

public static POILogger getLogger(final String cat)
    {
        POILogger logger = null;
        
        // If we haven't found out what logger to use yet,
        //  then do so now
        // Don't look it up until we're first asked, so
        //  that our users can set the system property
        //  between class loading and first use
        if(_loggerClassName == null) {
         try {
          _loggerClassName = System.getProperty("org.apache.poi.util.POILogger");//<<---------- Logger Name
         } catch(Exception e) {}
         
         // Use the default logger if none specified,
         //  or none could be fetched
         if(_loggerClassName == null) {
          _loggerClassName = _nullLogger.getClass().getName();
         }
        }
...
So we need to simply set the Logger property which can be accomplished from the command line. We will use the Apache Commons Logging Library to accomplish it.
-Dorg.apache.poi.util.POILogger=org.apache.commons.logging.impl.NoOpLog
Enhanced by Zemanta

Disabling Logging on Apache Commons Logger

I was looking for a quick way to disable logging on Apache Commons Logger so that I could do some testing without overhead. Here is a command line option for setting the logger to a no-op logger.

-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog

Popular Posts