pulsar's blog

Combined Access Log Format for a proxed Tomcat

If you need to let your Tomcat write access logs while being proxied by Apache's mod_proxy using the combined format, you will soon notice the lack of the client IP address. Pretty useless if you would like to get some access statistics for that particular instance.

Fortunately the Apache's mod_proxy will add some extra headers with the missing information to each request. Just set up your Log-Configuration in Tomcat as follows:

  1. <Context>
  2. <Valve
  3. className="org.apache.catalina.valves.AccessLogValve"
  4. prefix="access_log"
  5. pattern="%{X-Forwarded-For}i %l %u %t &quot;%r&quot; %s %b &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;"
  6. rotatable="false"/>
  7. </Context>

Please note that I'm rotating the Tomcat logs using logrotate. Therefore the "rotatable" attribute is set to "false" above. Just in any case, here is the logrotate config for my setup:

  1. /home/tomcat/logs/*_log
  2. {
  3. weekly
  4. rotate 48
  5. create 640 tomcat www-data
  6. sharedscripts
  7. postrotate /etc/init.d/tomcat restart
  8. endscript
  9. compress
  10. }

Nvidia's VMR Woes

For some reason, NVidia does not seem to get their drivers right regarding the video output using VMR-7/9 on digital panels hooked up via DVI. The drivers should detect the display type and use the enhanced color range (0-255) instead of the TV-Scale (16-235) to output video streams on your screen. Obviously they don't!

Once, NVidia has documented a registry hack in their driver release notes (AFAIR in 80.xx-90.xx driver revisions) which would force the driver to use the enhanced color range for videos. Never worked for me - I had to look for other workarounds. All I wanted was a true black (0,0,0) and a true white (255,255,255) on my screen. How difficult can it be?

You have various options to get rid of this nasty behavior. One would be to let your video player use RGB colorspace instead of YUV when rendering the video onto a VMR Surface. FFDShow Codec can do that. This workaround will obviously only work for video players using FFDShow. DVD Playback or in-game video might not be affected by using this method. The most reliable method I found was to use the video color correction in the recent NVidia drivers.

I grabbed a color test pattern movie over at Burosch (look for the link labeled "Download: 1920 x 1080 mit Stereo - Ton"), had set up my player to loop the video, and did a lot of screenshots which I pasted into Paint.NET to colorpick the black and white values while fiddling with the video color settings of the NVidia color panel. Sounds like pain in the ass? It feels like that too!

Anyway, in the end if have came up with following settings which look just perfect on my setup:

NVidia video color settingsNVidia video color settings

Now tell me one thing, why isn't it possible to export the color settings from the new oh-so-fancy-and-sluggish-nvidia-control-panel? WTF!? If you look at the screenshot above, you might think, that you only need to adapt percentage values. Think again. Between each decimal step, there are about 5-6 intermediate steps which you can only access via the keyboard / cursor keys. The driver does not always apply values set this way onto the live video, so you have to uncheck/check the "Use the NVIDIA Control Panel color settings" checkbox each time to let the driver accept fine-tweaked settings. JEEZ! Can I have the old snappy control panel back?

P.S. don't be as naive as I was to fire up Regmon / Process Monitor to take a look where the control panel stores the settings. Dragging a slider bailed out 64316 Registry-Access-Events (Open, Query, Close) PER SECOND! WTF! Now I have an idea why the control panel feels that slow!

How to set Nullable Types via Reflection on Properties in C# / .NET

Here is a Code-Snippet from a generic CSV -> Object Importer/Mapper I wrote. At some point I ran into an issue with Nullable types / values which I had to set (and convert) based on strings from the CSV file.

  1. public virtual void HandlePropertyAssignment(PropertyInfo pi,
  2. string propertyValue,
  3. T instance)
  4. {
  5. try
  6. {
  7. if (
  8. pi.PropertyType.GetGenericArguments() != null &&
  9. pi.PropertyType.GetGenericArguments().Length > 0 &&
  10. pi.PropertyType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))
  11. )
  12. {
  13. Type genericType = pi.PropertyType.GetGenericArguments()[0];
  14. pi.SetValue(instance, Convert.ChangeType(propertyValue, genericType), null);
  15. }
  16. else
  17. {
  18. pi.SetValue(instance, Convert.ChangeType(propertyValue, pi.PropertyType), null);
  19. }
  20. }
  21. catch (System.Exception ex)
  22. {
  23. throw new DAOException(String.Fromat("Could not convert {0} to property {1} of type {2}",
  24. propertyValue,pi.Name,pi.PropertyType),ex);
  25. }
  26. }
Note: T is a Generic Type.

Enable AHCI SATA Mode for Vista

Today I decided to finally give AHCI a try on my Vista setup. Unfortunately I've installed Vista with no AHCI support enabled in the BIOS, so no drivers were installed by Vista for this very mode automagically.

How difficult can it be? Reboot, Enable AHCI in the BIOS, Boot back up again: Boom - Bluescreen. Here is something I can't get, why does Windows bug me with plenty of useless dialogs to confirm or cancel but does reboot automatically about 2 seconds after throwing a Bluescreen which IS actually important? If you are lucky, you can catch a glimpse at the error message for about 1-2 seconds but if your shiny new TFT is busy synching to the new video mode you won't even notice it!

This can be fixed by adjusting the Crash Control Registry settings:


Set AutoReboot to 0.

OK, next time I will be able to read which component did cause the Bluescreen. Nevertheless I started looking around for others having problems switching to AHCI. Aside very adventurous solutions like moving the boot device to a separate SATA controller, enabling the AHCI mode on the other and booting up so Vista can install proper drivers or hacking the hell out of the Registry and some Intel-Raid application I have found a way more convenient way to enable AHCI.

It turns out that Vista will disable AHCI support for good if you did not had it enabled during the setup. To switch it back on you will need to do one tiny Registry Hack:


Set Start to 0

Yes, 0 to enable it. Don't ask.

Reboot, toggle the AHCI Support in your Bios and everything should be fine.

Debugging with Mole for Visual Studio 2005/2008

By the way... If you are into .NET development and use Visual Studio 2005/2008 you should give mole a try. It's a very nice debug visualizer for various datatypes. For instance you can easily navigate through the structure of a DataTable:

MoleVisualizer: Mole Visualizer for Visual Studio - Happy Debugging!MoleVisualizer: Mole Visualizer for Visual Studio - Happy Debugging!

head over to http://karlshifflett.wordpress.com/mole-for-visual-studio/ and check it out!

How to access Excel files via ADO.NET

The C# snippet below will dump ALL sheets of a given Excel file (c:\test.xls) onto the console. It took me a while to figure out how to access sheets within a Excel file which names I don't know - so here it is:

  1. String connectionString =
  2. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\test.xls;Extended Properties=\"Excel 8.0;HDR=YES;\"";
  3. DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
  4. try
  5. {
  6. using (OleDbConnection connection = new OleDbConnection(connectionString))
  7. {
  8. connection.Open();
  9. DataRowCollection rows = connection.GetSchema("Tables").Rows;
  10. foreach (DataRow row in rows)
  11. {
  12. string sheetName = row["TABLE_NAME"] as string;
  13. Console.WriteLine("************************************************************************");
  14. Console.WriteLine("Dumping Sheet: "+sheetName);
  15. Console.WriteLine("************************************************************************");
  16. using (DbCommand command = connection.CreateCommand())
  17. {
  18. string[] restrictions = { null, null, sheetName, null };
  19. DataRowCollection columns = connection.GetSchema("Columns", restrictions).Rows;
  20. string[] columnNames = new string[columns.Count];
  21. for (int i=0; i<columns.Count; i++)
  22. {
  23. columnNames[i] = columns[i]["COLUMN_NAME"] as string;
  24. }
  25. Console.Write("Columns in Sheet: ");
  26. foreach (string s in columnNames)
  27. {
  28. Console.Write(s);
  29. Console.Write(" ");
  30. }
  31. Console.WriteLine("");
  33. command.CommandText = "SELECT * from [" + sheetName + "]";
  34. using (DbDataReader dr = command.ExecuteReader())
  35. {
  36. while (dr.Read())
  37. {
  38. foreach (string columnName in columnNames)
  39. {
  40. Object fieldValue = dr[columnName];
  41. Console.WriteLine("'" + columnName + "' : " + "'" + fieldValue + "'");
  42. }
  43. Console.WriteLine("------------------------------------------------------------------------");
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }
  50. catch (Exception e)
  51. {
  52. Console.Write(e.StackTrace);
  53. }

To be honest - I did not expect it to be that easy. I guess I spent too much time developing Java applications.

Speedup Windows Shares Access for Vista

At least for me it did a marvelous job:

  1. netsh interface tcp set global autotuninglevel=disabled

Accessing Windows Shares from my Vista machine works damn fast now. The shares are either located on a Win2003 Server (LAN) or on another vista machine connected via VPN. The browsing performance via VPN was never that fast!

Red Ring Of Death - Welcome to the Club


Red Ring Of Death: borkedRed Ring Of Death: borked

XEN: Bridged Network Routing Issues

My current XEN installation has some unconventional setup. On my new root server I have to use routed network setup / script since I need to provide the default gateway for my assigned subnet to my XEN guests by myown.

In a common scenario, where each guest gets his own Public IP, this might not be a problem. In my case there was a need for a secondary private network where I would add proxied hosts (i.e. one for java applications proxied by apache).

Unfortunately the network scripts shipped with XEN 3.1.0 does not provide any out of the box support for such setup. So here is what I have hacked:

  • dom-0 gets a eth0:1 NIC alias set to
  • dom-u gets eth0 with a public IP and eth1: a private one like (it's very important to include both of the ip addresses in the guest-configuration file!)

to enable routing you need to patch the vif-route script in order to get your private network routed properly.


  1. if [ "${ip}" ] ; then
  2. for addr in ${ip} ; do
  3. ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip}
  4. done
  5. fi


  1. if [ "${ip}" ] ; then
  2. for addr in ${ip} ; do
  4. base=${ip:0:3}
  5. route_ip=${main_ip}
  7. if [ "$base" = "192" ]
  8. then
  9. echo "private ip detected, ${ip}" >> /xen-debug
  10. route_ip=""
  11. else
  12. echo "public ip detected, ${ip}" >> /xen-debug
  13. fi
  15. ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${route_ip}
  16. echo "${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${route_ip}" >> /xen-debug
  17. done
  18. fi

Not pretty, but it will do. The hardcoded eth0:1 IP address could be obtained from the ifconfig / IP output.

Imprint Datenschutzerklärung