Technology

Mint 9 and VirtualBox

If you intend to run Mint 9 inside VirtualBox on Windows, and if you are also willing to use the Guest Additions, I recommend that you use the latest VirtualBox version. On VirtualBox 3.1.2, I tried this and after I had installed the Guest Additions and rebooted the virtual machine, X wouldn’t come up because it couldn’t find any working configuration. I upgraded to the latest VirtualBox, reinstalled the newest Guest Additions inside the virtualized Mint, and everything runs just fine. Nice work again, Mint team! :)

I’m slightly disappointed by the VirtualBox “upgrade” process though. The installer would simply hang at the point where it configures the network interfaces – I had to first uninstall the old VirtualBox, reboot, then install the new version. This is not really (and never has been) an “update” or “upgrade”, it’s a complete reinstall. Being the lucky guy that I am, I could at least use the existing VMs without any problems after the “upgrade”. This needs to be improved, no matter what the company behind the product is called. >:)

Tags: ,

Thursday, July 1st, 2010 Technology No Comments

Basic Reflection Magic, and BeanUtils too

In my current project, a good deal of my daily work goes into an often repeated sequence of tasks:

  • Read data from an XML file (so-called “structured content”, OpenCms)
  • Put the data into an object tree in order to do stuff with it
  • Put the object(s) on a JSP page context in order to display parts or all of the contained data.

The old way was a bit less comfortable, being heavily based on Maps and Lists that were filled with single elements of the structured content and that then had to be parsed a second time in the JSP. I like the use of transfer objects a lot better because it keeps the code clean and easy to maintain and because it’s easier to apply modifications to the data between reading it and displaying it.

Thus, I’m searching for a nice way to get the cleanest, most concise code for the XML -> object tree step. For simple tasks, I make havy use of BeanUtils at the moment. Let’s say the XML contains elements called “title”, “link” and “image”. I then create a class with exactly the same attributes and sensible types (in this case, they are all Strings, but I do use boolean and numeric values in some places).

Because the attribute names in the class are the same as they are in the XSD, respective XML file, I can then easily populate an instance of my class while reading from the XML at the same time, roughly like this:

PropertyDescriptor[] propertyDescriptors = 
    PropertyUtils.getPropertyDescriptors(Teaser.class);
 
Teaser teaser = new Teaser();
 
for (PropertyDescriptor pD : propertyDescriptors) {
    try {
        String xmlPath = /* create basic XPath here */ + pD.getName();
        BeanUtils.setProperty(
            teaser,
            pD.getName(),
            document.getStringValue(cmsObject, xmlPath, currentLocale)
	);
    } catch(...) {} /* Exception handling and logging omitted for brevity */
}

This code is partially specific to the OpenCms API, but I think you get the point.

In most situations, you would probably get the PropertyDescriptor array only once and put it into a constant, because it’s not very likely that the transfer class will change during runtime.

This way of saving about n-1 lines of code where n equals the number of attributes you want to read from the XML makes me very happy.

But, as with every solution, I’m still looking to improve this even more. The downside at the moment is that I cannot remove loops yet for lists of entries in nested XML files. Thus, I did some research + experimenting on reflection mechanisms today. My intention: to pass the top-level transfer class into a method that recursively checks the structure (e.g. dives down into lists of other custom transfer classes, e.g. List or whatever) of my desired object tree and that then goes ahead and slurps the entire XML into an object tree. This should – in the end – fit into only a couple lines of code, allowing for a clean API and perfect encapsulation of reusable “please-read-this-XML” code.

First experiments were quite successful and I recommend this article: Java Reflection: Generics, especially section 4, “Generic Field Types”.

I’ll omit my code snippets here, because it’s much more fun to build stuff like this yourself ;-)

I’m quite fascinated by the inner workings of reflection at the moment, and I suppose that I will research this topic until I have a working bit of code – only to then find some proven framework that does the same thing – but maybe my small, self-made solution is just so small and simple that it does NOT require me to put an extra 10 JARs into the project… or maybe the idea turns out to be complete crap – we will see. Essentially, it’s all about having fun with technology :-)

I’ll write a follow-up as soon as I have new results. Stay tuned!

Tags:

Wednesday, May 6th, 2009 Development, Technology No Comments

Windows 7 vs. VirtualBox

After I had downloaded the ISO, I created a new VM in VirtualBox with a dynamically growing max 20GB hard disk, 1GB RAM and 128MB video memory. I mounted the ISO as the virtual CD drive and fired up the VM. Installation went through quickly, the only lag it showed was probably caused by a lack of RAM – but of course, I still wanted to work on the host system, so 1 gig had to be enough. The system boots up quite fast, which is not really a relevant metric right now because there are absolutely no applications installed yet. Windows 7 comes with Internet Explorer 8 as the default. Solitaire has been redesigned. That’s all I’ve tested so far :-) The VirtualBox Guest Additions cannot be installed currently, because they are not yet updated in order to run on Windows 7.  If I find some free time, I’ll try some apps on the sandbox system. So far, I’m quite happy that it runs out of the box inside the box!

Tags:

Sunday, January 11th, 2009 Technology No Comments

Windows 7 Public Beta

Having had troubles with overloaded download servers (hint: bittorrent exists!), Microsoft has now managed to bring the Windows 7 Public Beta downloads back online. I’m grabbing the 32-bit version right now. Will try to run it in VirtualBox. Hang around for my first report!

Tags:

Sunday, January 11th, 2009 Technology No Comments

JBoss MBeans + jconsole + JMX

jconsole is a handy tool for taking a quick look at JMX data provided by running Java processes. Although jconsole (JDK5) features a very ugly GUI, it’s still nice to play with. It should well be good enough if you just want to take a quick look at memory consumption or trigger some management methods on MBeans. Well, MBeans, the buzzword deluxe as far as JBoss is concerned – I wanted to see MBeans registered in a running JBoss 4.0.x in jconsole. This is not quite simple because you need to specify several additional options in the run.sh/run.bat. Thanks to this and this, I got it working like this:

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote"
JAVA_OPTS="$JAVA_OPTS -Djboss.platform.mbeanserver"
JAVA_OPTS="$JAVA_OPTS -Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl"

In Windows environments (run.bat), the syntax is – of course – slightly different. In Eclipse, simply add those options to the server configuration.

Just in case you’d like to do some MBean/JMX voodoo with the Spring framework, try the MBeanExporter. I’ll write a couple of sentences about that as soon as my own experiments are done.

Have fun :-)

Tuesday, November 25th, 2008 Java, Technology No Comments

Trainings Galore

I took part in two interesting and entertaining trainings during the last two weeks, both highly relevant for my daily work.

The first training I went to was a SCRUM master certification training with Jeff Sutherland and Serge Beaumont (Xebia). It took place in Utrecht on November 13th/14th. Utrecht is quite a nice city, I will go there again next year and look at it in more detail. Next time I travel to the Netherlands, I’ll go by train or helicopter – 90 minutes on the way back for 30 kilometers is too much :-) The SCRUM training itself was quite packed with entertaining stories and hands-on exercises and I learned a lot about team dynamics. As we have been doing SCRUM at work for some weeks now, I’m keen to see how this method of working will develop. After my return home, I immediately started doing SCRUM at home as well – very useful to get things done :-)

This week (November 18-21) we had an in-house Core Spring training with Mike Wiesner, who is a very good trainer as well. The training was very well structured with labs for each topic. SpringSource does not only give a complete set of slides to every participant, but also a printed guide for the labs and a complete Eclipse-based development environment with prepared lab projects and complete solutions. Four days of condensed input gave me quite a bit of brain load, but I think it was well worth the time. I also learned a lot about what I have been using in my projects for almost two years now. I will take the “Certified Spring Professional” exam as soon as possible. The training participation certificate will then be exchanged with the “real” certificate :-)

Thanks to all trainers for their good work!

Tags: ,

Friday, November 21st, 2008 Development, Java, Random Thoughts, Technology No Comments

Data shredding

I recently cleaned out my hardware collection and found a couple of old hard disks that have been out-of-use for quite some time. I decided to backup any interesting data and then clean the disks. The normal formatting approach seemed too insecure to me, so I tried this first:

$ dd if=/dev/urandom of=/dev/hda & pid=$!
$ watch -n 30 kill -USR1 $pid

Sending USR1 to dd prints IO statistics and then resumes copying. I saw that the throughput was at about about 30MB/min which would have taken 5.5 hours for a 20GB disk.

I then remembered “shred”, which overwrites the target file with random data, optionally performing multiple passes. I ended up doing

$ shred -n 10 -v /dev/hda

which is way faster and more secure. So far, the first pass has written random data to the disk, the second pass is writing 0×6db6db chunks. 10 passes should be enough to render the old data unrecoverable to a reasonable degree :-)

Saturday, November 1st, 2008 Security, Technology 2 Comments

VirtualBox > VMWare Server

I had some trouble upgrading from VMWare server 1.0.5 to 1.0.7 – I had to run the installer at least 3 times, rebooting even more often, in order to get the upgrade done. After that, I installed Mint 5 inside VMWare, and ran into the well-known troubles installing VMWare tools with a 2.6 kernel. I ended up being very frustrated. At that moment, a work mate recommended VirtualBox to me. I kicked VMWare off my machine (nice side effect: the speed of my internet connection roughly doubled after I uninstalled VMWare) and installed VirtualBox.

VirtualBox installs in almost no-time, and appears to be very fast and slim. It’s very easy to attach an ISO image as a virtual CD drive, so I chose this way to install a current stable Debian. I set virtual networking to NAT mode, which works “out of the box”: VirtualBox installs a network driver to the host system that maps packets to the “real” network connection of the host and vice versa.

Because the console video resolution was not too great inside VirtualBox, I added a port forwarding rule for host:2222 to guest:22 in order to ssh into the virtual machine using PuTTY. Doing this is really easy – you just need to execute the following commands (on Windows):

VBoxManage setextradata "Linux Guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP
VBoxManage setextradata "Linux Guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22
VBoxManage setextradata "Linux Guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222

This example is taken directly from the VirtualBox help file. As soon as you have set those options, you need to switch off the virtual machine and then start it again.

At the moment, I’m very happy using VirtualBox – there is even a so-called “seamless mode”, which enables you to have X windows on your Windows desktop, behaving like “native” Windows windows. I haven’t tried this yet, but I will do so asap.

First impression: VirtualBox is very easy to maintain, it runs fast and stable, and it doesn’t modify as much of the host system as VMWare does. Hence, I prefer VirtualBox at the moment.

Tags: , , ,

Sunday, September 14th, 2008 Technology No Comments

Openswan fun

I’m currently trying to build a VPN tunnel to a work-related ISP in order to have transparent VPN access instead of using the Cisco VPN client. So far, I have managed to build the ipsec module for a 2.6 kernel, going “back to the roots” because the standard Debian ways of building modules wouldn’t work with the provided source code packages. In the end, I downloaded the Openswan source code and compiled it directly, ignoring the usual Debian way. This worked out fine and I have a loadable ipsec kernel module now. Right now, I’m working on the ipsec configuration, trying to get the tunnel initiation work over NAT. I’ll keep posting on this topic in order to describe progress and pitfalls.

Tags: , ,

Sunday, September 14th, 2008 Networking, Security, Technology No Comments

Finding duplicate db entries

Supposing you have a MySQL table like this:

id
login
client
password
email
...

without a UNIQUE constraint for (login,client) – you want to find out which combinations of login and client are there more than once – use this kind of query:

SELECT login,client,count(*) as cnt
FROM yourtable
GROUP BY 1,2
HAVING cnt > 1
ORDER BY 3;

Thanks to Mike for the hint.

Tags: ,

Wednesday, July 9th, 2008 Technology No Comments

Welcome!

Have fun reading this blog. You will find some "about" data if you follow the link in the header.

Archives