Dienstag, 28. Dezember 2010

Synaptics,UltraNav,Thinkpad Scrolling in Netbeans,IntelliJ or other Java Swing Appz

I do love my Thinkpad! And of course I do love the red bubble called track point and its way of scrolling. But sometimes scrolling doesn't work. Most often it stops working in java apps using the swing framework. This includes Netbeans IDE and IntelliJ IDEA. This morning I thought its time to fight the evil of this problem and after an endless list of bug reports and forum questions with many crazy ideas(including JNI Hooks - buäks) I found one interesting hint to a file called TP4table.dat located at C:\Program Files\Synaptics\SynTP. I tried what this guy said but nothing changed - still no scrolling in IntelliJ. A refined google query using swing and TP4table.dat leaked the evils secret. All you have to do is to add some lines to this file to make the driver send the right scrolling events to the app. In case of IntelliJ use the following:

*,*,idea.exe,*,*,*,WheelStd,1,9


It may be necessary to restart windows. If its not working try to add this line at the top of the ruleset definitions right under the comment

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Pass 0 rules (These rules run first)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


and confront your brave Windows Machine with the challenge of a reboot. If its still not working rename the idea.exe file to java.exe. (There is a predefined rule for java in the TP4table.dat file) and start IntelliJ using this exe. If scrolling is working now you made a mistake copy and pasting or forgot to reboot your machine.


Happy new year with scrolling in Swing appz!

Montag, 13. September 2010

HOWTO do global JNDI registered Connection Pooling (DataSource) in Tomcat

Using a connection pool of the servlet container seems to be a good idea IMHO. Here's a litlle HOWTO do so using tomcat and postgresql.

  1. Provide the jdbc driver by copying the postgresql-8.4-701.jdbc4.jar (or any other version working for you) to the CATALINA_HOME/lib directory.
  2. Register the jndi resource by adding the following lines to your CATALINA_HOME/conf/server.xml under <GlobalNamingResources>
    <Resource
     name="jdbc/postgres-ds" type="javax.sql.DataSource"
     driverClassName="org.postgresql.Driver" url="jdbc:postgresql://MYSERVER:5432/testdb"
     username="MYUSER" password="MYPASS"
     defaultAutoCommit="false" 
     maxActive="5" maxIdle="2" maxWait="30000" initialSize="0" 
     validationQuery="SELECT 1;" testOnBorrow="true" testWhileIdle="false"  
    />
  3. Create or user the file /META-INF/context.xml(Using maven it is src/main/webapp/META-INF/context.xml in your webapps project with the following content:
    <?xml version="1.0" encoding="UTF-8"?>
    <Context>
     <ResourceLink name="jdbc/dbds" global="jdbc/postgres-ds" type="javax.sql.DataSource"/>  
    </Context>
  4. edit your web.xml and add the following lines to the root node:
    <resource-ref>
     <description>postgreSQL Datasource example</description>
     <res-ref-name>jdbc/dbds</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
    </resource-ref>
  5. Use the connection in a way like this:
    InitialContext cxt = new InitialContext();
    DataSource ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/dbds");
    Connection con = ds.getConnection();
    con.setAutoCommit(false);
    Statement statement = con.createStatement();
    ResultSet rs = statement.executeQuery("SELECT id, \"name\" FROM test;");
    while (rs.next()) {
     long long1 = rs.getLong("id");
     String name = rs.getString("name");
     System.out.println(long1 + " - " + name);
    }
    
    rs.close();
    statement.close();
    con.commit();
    con.close();

Additional Info:
Tomcat 6 is using the Apache dbcp project to do connection pooling. So the available connection pool configuration parameters are described here

The pool is created at the time of the first connection request.

Make sure to always close the connection. Connections that are not closed are not released. This means those connections can't be reused.

If you are using eclipse wtp and Tomcat 7 you may get a nasty java.lang.NullPointerException at org.apache.catalina.core.StandardContext.getObjectNameKeyProperties. It is related to the <ResourceLink name="jdbc/dbds" global="jdbc/postgres-ds" type="javax.sql.DataSource"/> setting in the context.xml file. The problem is described here in more detail. Just enable the server option "Publish module contexts to separate XML files" and the problem is solved.

If you are using eclipse wtp and Tomcat you may need to remove and add the tomcat server again so the wtp plugin recognizes the changed server.xml file.

I'll provide an example project if someone requests :-)

Mittwoch, 8. September 2010

J4v4 rul3z

Montag, 16. August 2010

Joomla template development using Ant

My personal 3 Problems developing Joomla templates

First it is necessary to maintain a file called templateDetails.xml. In this file you have to define all the files used by the template. Adding a picture means adding this picture to the list of files. If you forget to do so, the file is not installed which results in template bugs.
Second building the template package means creating a zip file. This is like creating a jar file - who would want to do it using a file manager and a zip tool?
Last but not least it is not possible to reinstall a template. Once installed, you have to uninstall it prior to installing the new version of the template. Who would like to do this every time a css file changed? So most people are using a ftp client like FileZilla which supports "online file edit" or directory synchronization. In my case this means opening files with FileZilla, not with eclipse. DO NOT forget to sync them back!

Ant to the rescue

I spent some time and created a custom ant task and a build script using the ftp sync feature built into ant. The custom ant task is responsible for maintaining the file list of the templateDetails.xml. It scans the template directory recursively and replaces the files section with the results. You can download it here. You can find the source code included in the jar file. I don't want to include those ugly lines doing their dirty job in this article.
The ant build script is quite simple:

<?xml version="1.0" encoding="UTF-8"?>
<project name="MyKewlTemplate" default="myKewlTemplate">
 <target name="refreshFileList">
  <taskdef name="TemplateDetailsGenerator" classname="de.rhauswald.ant.joomla.TemplateDetailsGenerator" classpath="ant/TemplateDetailsGenerator.jar" />
  <TemplateDetailsGenerator templatedirectory="myKewlTemplate" />
 </target>

 <target name="clean">
  <delete file="build/myKewlTemplate.zip" />
 </target>

 <target name="myKewlTemplate" depends="clean">
  <antcall target="refreshFileList" />
  <zip destfile="build/myKewlTemplate.zip" basedir="myKewlTemplate" />
 </target>

 <!-- include apache commons-net into  ant lib directory-->
 <target name="sync">
  <antcall target="refreshFileList" />
  <ftp password="XXX" server="XXX" userid="XXX" passive="true" newer="true" remotedir="templates/myKewlTemplate" verbose="true" binary="true">
   <fileset dir="myKewlTemplate">
   </fileset>
  </ftp>
 </target>
</project>
Now my three problems are solved: The file list is auto generated before every build(ftp sync or zip). I can build the installation zip file with just one click. The ftp sync works like a charm. Change something, click the build button and ant uploads the changes only. In case I add a background picture and the proper lines to the css file a click at the build button does the following:
  1. Add the new picture to the file list
  2. Upload the templateDetails.xml file
  3. Upload the picture
  4. Upload the css file
I can concentrate on writing div boxes and css now...

Samstag, 14. August 2010

Speeding up maven dependency report

Executing the maven site goal with the default configuration can take a long time. In my case . Most of the time is consumed by the "Dependencies" report. This is the build summary with the default configuration:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 44 seconds
[INFO] Finished at: Fri Aug 13 09:31:14 CEST 2010
[INFO] Final Memory: 69M/429M
[INFO] ------------------------------------------------------------------------
The docs of the dependency report module offered two options enabled by default. Disabling both of them is done in the reporting section of the project pom this way:
<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-project-info-reports-plugin</artifactId>
 <version>2.1</version>
 <configuration>
  <dependencyDetailsEnabled>false</dependencyDetailsEnabled>
  <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
 </configuration>
</plugin>
This speeds up the site generation extremely:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22 seconds
[INFO] Finished at: Fri Aug 13 09:33:44 CEST 2010
[INFO] Final Memory: 65M/395M
[INFO] ------------------------------------------------------------------------

Freitag, 13. August 2010

Windows Command / CMD Alternative

I found an awesome tool today named "console". It can be used as an alternative command line window for windows. Everyone who has broken his fingers a hundred times using the cmd tool shipped with windows should give this piece of software a try!

The website states: Console is a Windows console window enhancement. Console features include: multiple tabs, text editor-like text selection, different background types, alpha and color-key transparency, configurable font, different window styles

Dienstag, 13. April 2010

Howto set the Bacula Storage Daemon 's (bacula-sd) umask in Debian

The default Debian init script for the Bacula Storage Daemon is not providing a configuration option for the umask. Of cause it is possible to append a --umask to the start-stop-daemon lines init script but this is not update safe and last but not least it will change the checksums and intrusion detection scanners (debsums, tiger,...) will complain about this file. This leads to an ignore rule in the IDS which means more configuration, less security and more complexity.

The solution is to use a pam module named pam_umask. It is contained in the package libpam-modules which should be installed by default. After switching on the module the only thing that needs to be done is to add a umask setting to the Bacula users GECOS field.

For the copy paste fraction:
apt-get install libpam-modules
echo "session   optional   pam_umask.so" >> /etc/pam.d/common-session
usermod -c umask=027 bacula
/etc/init.d/bacula-sd restart
pam_umask can also be used this way to modify the umask of any specific daemon user without a shell.

Samstag, 27. März 2010

TrueCrypt and Ubuntu 9

Today I installed True Crypt on an Ubuntu box. Tried apt-cache to search truecrypt without success. Cause I'm a damn good rftm'er I continued using google. Every page suggested to compile the sources. Not that I'm afraid of compiling source code but hey that's Ubuntu not Gentoo. So I stopped doing the rtfm stuff and had a look at the homepage of True Crypt. Downloaded a tar archive, extracted it and run the extracted executable. A few seconds later I got True Crypt running on the box. Why are all the linux guys always trying to compile things...

Freitag, 26. März 2010

Debian Bacula vulnerability / security leak

Another shorty: Bacula is a neat backup tool and Debian provides maintained packages for it. But the install script opens a big security hole. It generates all the necessary configuration files for the file and storage daemons, the director and the console client. It also generates the user names depending on the host name. And it seems to do this job in a secure way cause the passwords for the Bacula users are long enough to be very secure. This is indeed very important cause the file daemon runs as root. This is necessary so the file daemon is able to backup the whole system. The only downside is that those passwords are neither generated nor is the installer asking for them. This makes many users believe that those passwords are generated and not have to be changed. Combining those facts leads to the following situation: Every default Bacula installation in Debian is using the same password to secure the file daemon which is capable of reading all the files of the system as root. So every non privileged user is able to use this daemon to get access to files he has no access to. |-|4\/3 4 L07 0Ph p|-|U|\|...

Montag, 15. Februar 2010

How to determine the size of all postgres databases

A manic Monday, reading log files, a big WTF: No space left on device external backups... WTF? .... 5 Minutes later: found a reason: The backups of the test database server... 30 databases on this machine.... which ones are the biggest?

This query to the rescue:
select databases.datname, pg_database_size(databases.datname)/1024/1024 as size from (SELECT datname as datname FROM pg_database) as databases ORDER BY size DESC;

One test database with 1,4GB ... another one with 0.9G... WTF? - Drop database... war is over

  © Blogger template 'Morning Drink' by Ourblogtemplates.com 2008

Back to TOP