If you are using the Beans Validation framework (JSR 349), you may encounter this obscure exception when doing your validation.
java.lang.ExceptionInInitializerError
Caused by: javax.el.ELException: Provider com.sun.el.ExpressionFactoryImpl not found
Caused by: java.lang.ClassNotFoundException: com.sun.el.ExpressionFactoryImpl
This exception is caused by a missing key lookup in the ValidationMessages.properties file. Make sure you have the the key in the properties file.
Enjoy!
November 24, 2014
November 17, 2014
DOS equivalent of Unix/Linux alias
The Unix/Linux alias command is great. But now you are stuck in a DOS environment. What do you do? Use doskey!
The doskey command can be used in a DOS environment to simulate the kinds of things which alias does. Here is an example from my alias.bat file:
As you can see, doskey is very similar to alias. When on a DOS prompt, all you need to do is type tw or twr and that command will be executed. Of course make your own doskey values.
All of my doskey commands are in an alias.bat file. This means anytime you open a new DOS prompt you need to execute alias.bat to load all the doskey command. Unacceptable! Instead, create a shortcut for either your desktop or toolbar and you edit the shortcut to execute the alias.bat file for you. The shortcut will look something like this.
That's it.
Enjoy!
The doskey command can be used in a DOS environment to simulate the kinds of things which alias does. Here is an example from my alias.bat file:
doskey cdhome=cd c:\Users\michael doskey tw=cd C:\Users\michael\workspace\ferris-tweial\ferris-tweial\ferris-tweial-app\target\unziped\ferris-tweial-app-1.0.0.0-SNAPSHOT doskey twr=c:\Applications\java\jdk1.7.0_11\bin\java.exe -jar ferris-tweial-app-1.0.0.0-SNAPSHOT.jar
As you can see, doskey is very similar to alias. When on a DOS prompt, all you need to do is type tw or twr and that command will be executed. Of course make your own doskey values.
All of my doskey commands are in an alias.bat file. This means anytime you open a new DOS prompt you need to execute alias.bat to load all the doskey command. Unacceptable! Instead, create a shortcut for either your desktop or toolbar and you edit the shortcut to execute the alias.bat file for you. The shortcut will look something like this.
cmd.exe /K "c:\Users\Michael\alias.bat"
That's it.
Enjoy!
November 13, 2014
Remember PreparedStatement?
Simple example using PreparedStatement
Miss the good ole' days when interacting with the database was simple, easy to understand SQL statements and a few lines of code?
Select
Insert
Enjoy!
Miss the good ole' days when interacting with the database was simple, easy to understand SQL statements and a few lines of code?
Select
public static void main(String[] args) throws Exception { String driver = "org.apache.derby.jdbc.EmbeddedDriver"; String dbLocation = String.format("./db/Sample"); String connectionUrl = String.format("jdbc:derby:%s;create=true;user=sample;password=elpmas",dbLocation); Class.forName(driver); Connection conn = DriverManager.getConnection(connectionUrl); StringBuilder sp = new StringBuilder(); sp.append("select \n"); sp.append(" integer_value \n"); sp.append(" , decimal_value \n"); sp.append(" , varchar_value \n"); sp.append(" , timestamp_value \n"); sp.append("from example \n"); PreparedStatement stmt = conn.prepareStatement(sp.toString()); ResultSet rs = stmt.executeQuery(); System.out.printf("ResultSet\n"); while (rs.next()) { int i = rs.getInt(1); BigDecimal bd = rs.getBigDecimal(2); String s = rs.getString(3); Timestamp ts = rs.getTimestamp(4); System.out.printf("%d\t%f\t%s\t%s\n",i,bd,s, ts.toString()); } conn.commit(); conn.close(); System.out.printf("Goodbye\n"); }
Insert
public static void main(String[] args) throws Exception { String driver = "org.apache.derby.jdbc.EmbeddedDriver"; String dbLocation = String.format("./db/Sample"); String connectionUrl = String.format("jdbc:derby:%s;create=true;user=sample;password=elpmas",dbLocation); Class.forName(driver); Connection conn = DriverManager.getConnection(connectionUrl); StringBuilder sp = new StringBuilder(); sp.append("insert into example ( \n"); sp.append(" integer_value \n"); sp.append(" , decimal_value \n"); sp.append(" , varchar_value \n"); sp.append(" , timestamp_value \n"); sp.append(" ) values ( \n"); sp.append(" ? \n"); sp.append(" , ? \n"); sp.append(" , ? \n"); sp.append(" , ? \n"); sp.append(" ) \n"); PreparedStatement stmt = conn.prepareStatement(sp.toString()); stmt.setInt(1, 19); stmt.setBigDecimal(2, new BigDecimal("100.45")); stmt.setString(3, "Hello"); stmt.setTimestamp(4, new Timestamp(System.currentTimeMillis())); int cnt = stmt.executeUpdate(); System.out.printf("count = %d\n", cnt); conn.commit(); conn.close(); System.out.printf("Goodbye\n"); }
Enjoy!
November 08, 2014
SSL JNDI Realm for Tomcat Catalina
Using JNDI as an authentication realm for Tomcat is quite common. What's also quite common is communication with the server needs to happen over SSL. In production, certificates are not a problem. In non-production (and especially development) environments, expired, self-signed, and untrusted SSL certificates are the norm. This project is an JNDI Realm for Tomcat Catalina which is designed to accept any SSL certificate, basically bypassing all security provided by certificates. So only use in development environments.
end
November 07, 2014
Servlet Info WebApp
Ferris Servlet Info WebApp is a simple servlet which dumps a bunch of info about the request, session, init-params, and server machine to the page for troubleshooting purposes. It also includes an AJAX call back to the server which can be started and stopped with the "Start" and "Stop" buttons and how many seconds between AJAX calls is determined by the number in the input text box. When the AJAX response is received, the data on the page is replaced by whatever the server sent back. This WebApp is especially helpful troubleshooting clustered environments.
Clone the Mavenized project from GitHub (https://github.com/mjremijan/ferris-servletinfo).
Clone the Mavenized project from GitHub (https://github.com/mjremijan/ferris-servletinfo).
Here is what the information on the page looks like (IP address information has been blacked out)
Subscribe to:
Posts (Atom)