Powered by Pressflow, an open source content management system
Home

This week I've been fighting Hibernate again. That is, last week I should have implemented a quick job to export 30 million entities from a DB and to a new interchange format.

Instead the job blew up due to memoryproblems. Below you'll find teh solution.

.

I've been using Apache Camel more and more lately and one thing that has irritated me is creating a big project with maven, multiple classes etc for just a simple task. I thought Scala would be my savior, instead Groovy is.

This post shows how to get groovy scripts to block when stating up.

.

I just upgraded to Munin 1.4.3 on Centos 5.4 (from 1.3.x I think) the other day and after some time noticed that my Graphs were not updating.

.

A few days ago someone asked on #symfony if it is possible to make symfony load fixtures from different places depending on the environment.

To do this, you have to define your own task. Here's one I just created. As a bonus, this task also loads sql files from a separate sql directory.

.

One thing I love about Java is that there are a number of databases that you can load into memory and run functional tests against. This is also an option in PHP thanks to Sqlite.

Just a few quick notes on things to do when converting from using the DBCP connectionpool implementation to using C3P0

You start by changing the  dataSource in your Spring config from:
<bean id="dataSource"

        class="org.springframework.jdbc.datasource.DriverManagerDataSource">

        <property name="url" value="jdbc:mysql://localhost" />

        <property name="username" value="yourname" />

        <property name="password" value="yourpass" />

    </bean>
To:
 <bean id="dataSource"

          class="com.mchange.v2.c3p0.ComboPooledDataSource"

You do not always have the luxury to decide how things are done. This weekend the image service at work decided it was its turn to wreck itself. The whole story starts of with me rewriting a part of the image service - the component that inserts an image into the service. The service has two parts: One that saves images to the datastore and one that retrieves images from the datastore and delivers them to some client, usually as a thumbnail. This should be fairly simple stuff that should never go wrong and usually just work. The problem was in the chosen datastore: MySQL. MySQL is good for many things, but far too often have I seen it used as a hammer where a screwdriver should have been used. The schema for image database looked like this:

Problem: setUp() is called for every method but I only want to start logging once. Solution:Add a check on logger.handlers to see if any handlers have been registered with the logger:def startLogging():    logger = logging.getLogger()    if len(logger.handlers):        return logger    stdout = logging.StreamHandler()    stdout.setLevel(logging.DEBUG)    logger.addHandler(stdout)    return loggerclass MyTest(unittest.TestCase):     def setUp(self):         startLogging()    def test_something(self):        some_function_that_uses_logging()

I spent the best part of yesterday afternoon fighting the message above. I post this so that the next person fighting it may save some time. One of the problems was that none of the solutions suggested helped. After some beer, sleep and a fresh start I found this message that talks about replacing

	<tx:annotation-driven transaction-manager="transactionManager" />

With

<code>
<bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" 
factory-method="aspectOf">
		<property name="transactionManager" ref="transactionManager">
	</property>
</bean></code>

And suddenly it all worked. Another example of GDD - Google Driven Development. If anyone knows why this works - please explain.

 

Update:  There seems to be an issue when it comes to combining @Confgurable and @Transactional in a project that relates to the comment above. Also, I later experienced that doing sessionFactory.getCurrentsession() is not a good idea when using spring transactions. Instead, use

 

Update 2: None of the examples of Transactional tests using spring show it, but you'll need the TransactionalTestExecutionListener to get @AfterTransaction and @BeforeTransaction to work. Det it up like this:

#umount /var<br />
umount: device is busy<br />

Who hasn't experienced this one?

Anyhow, I found this shellscript that does the important checks:

#!/bin/sh
# Attempts to umount a mountpoint or device. If it fails, give info on why it might be busy.

/bin/umount $* || (
    if [ -z "$*" ]
    then
        exit
    fi
    echo `pwd`/"$1" | sed 's/^.*\/\//\//g' | ( read abspath
   
    mtab_entry=`grep "$abspath " < /etc/mtab`
    echo $mtab_entry | if grep "/" > /dev/null
    then
        device=`echo $mtab_entry | sed "s/ .*$//g"`
        mountpoint=`echo $mtab_entry | sed "s/[^ ]* //" | sed "s/ .*$//g"`
        #echo $device $mountpoint

        ( echo The mountpoint $mountpoint is in use by:
          lsof | grep " $mountpoint" | head     #list files open
              cat /etc/mtab | grep " $mountpoint/"  #list sub mount points
        ) 1>&2
    fi
))

 

I've been using Drupal a bit lately for some simple sites and just happened to come over this debate on the relative security between Drupal and Plone. I think we need to go beond looking at the number of Security advisories and start discussing how we protect vulnerable versions of software. The problem with the larger PHP CMS'es (Drupal, Joomla etc) isn't that they do not care about security - but that that their users do not.One thing I've noticed is that there are a lot of simple sites out there that get hacked because they do not upgrade their CMS'es to the latest version. Often the hacker keeps the site up so that it is impossible to notice that that the account is being used for all kinds of spamming - for example by adding a bunch of "invisible" links at the bottom of the site. I've tried to contact some ISP's that hosts sites like this (Servetheworld amongst others), but their reply is that they cannot disable a customers account or clean up the customers site just because it is hacked. IMHO we need a way to protect users against themselves here. A simple protocol that checks the version of the running CMS against a registry somewhere and then either shuts down the CMS and/or notifies the user.At least 50% of the people running small sites do not know enough about the security to keep their site up to date. We need to provide protection for them.

Few things can provide as much frustration as refactoring a legacy system bit by bit. Today I have been wrestling with a field defined in MySQL as "timestamp default '0000-00-00 00:00:00'. In my (reveng'ed) POJO the field is defined like this:

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "httpstatus_time", nullable = false, length = 19,
            columnDefinition="timestamp default '0000-00-00 00:00:00'")
    public Date getHttpstatusTime() {
        return this.httpstatusTime;
    }

Now, it turns out that JDBC cannot deal with date values that are before UNIX epoch, something 0000-00-00 clearly is. So, what does JDBC do in these situations? It will throw an exception. To get around this, you can add 'zeroDateTimeBehavior=convertToNull' to your jdbc url. After setting zeroDateTimeBehaviour, the value will be set to a Java null. This provides you with another issue: When you get an object from the db, and you modify it, you may have to also modify some other values and set them to something other than null.

Note: I tried setting the dates to "new Date(1)" but that didn't work - it is too close to 0 so JDBC still throws a fit. I ended up with "new Date(10000)".

If you do not check your null's, you'll get this: (I've omitted parts of the stacktrace for brevity)

.

I spent the best part of yesterday afternoon fighting the message above. I post this so that the next person fighting it may save some time.
 
One of the problems was that none of the solutions suggested helped. After some beer, sleep and a fresh start I found this message that talks about replacing
 
<tx:annotation-driven transaction-manager="transactionManager" />
With

<bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect">
factory-method="aspectOf">
<property ref="transactionManager" name="transactionManager">
</property>
</bean>

And suddenly it all worked. Another example of GDD - Google Driven Development.
 
If anyone knows why this works - please explain.
 
 

This post is inspired by a question on the Twisted mailinglist by Michele:

I'm currently working on a PoC with twisted, Python, to prove the<span class="moz-txt-citetags"> </span>technology as an alternative to more<span class="moz-txt-citetags"> </span>established enterprise choices (java app servers, etc..). <span class="moz-txt-citetags"></span>the question is: if I have N number of processes running in a M number <span class="moz-txt-citetags"></span>of machines, given that there are no network restriction, <span class="moz-txt-citetags"></span>and that at least http and hhtps are always available, how these <span class="moz-txt-citetags"></span>services would be efficiently monitored?<br />

What I do is to have the service listen to a http connection that returns some monitoring data. The service returns a simple xml message containing some datapoints.

Then I use a custom Nagios plugin to request this url and Nagios-PNP to make graphs of the datapoints the monitor produces. It it doesn't return anything I know the service is down.

The plugin setup is done by providing an url (say http://myservice:893/monitor) to monitor. The plugin will then both monitor the application and graph it.

Today when deploying a new version of a webapplication to Tomcat I got the following error:

Could not initialize class javax.crypto.SunJCE_b

Since I had just upgraded Java, I started looking there. After a lot of digging around, including changing from Suns java to Openjdk (this was on Centos 5.2) I got this error:

    java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.DefaultSSLContextImpl)

After some digging around I found two things that were wrong:

a) I am quite sure that the /usr/lib/jvm/jre-openjdk/lib/security/cacerts file should be larger than 32 bytes.

b) The main problem was that I had set the CLASSPATH all wrong.

Morals? No morals, just check those two if you ever get this error.

Quite often I've cursed Maven for missing the simplest usecase: Being able to place a .jar file in a lib/ directory in the project directory and make Maven use the jar file as if it was part of the dependencies.

The odd thing is that this is both easy and simple to do - if you happen to know every Maven detail. Fortunately there is Google Driven Development (GDD), where I ended up finding this post.

The post says that if you define a dependency as "system" and add a path, then you are good to go. Here's what I use to get the latest version of the Rome rss library installed:

<br /> <dependency><br />      <groupId>rome</groupId><br />      <artifactId>rome</artifactId><br />      <version>1.0RC1</version><br />      <scope>system</scope><br />      <systemPath>${basedir}/lib/rome-1.0RC1.jar</systemPath><br /><br />    </dependency><br />

Update: I ended up finding this bug that says that if you use a system scoped jar then it will not be included in a war file. It seems that the only way around this is create a central repository for your projects and add the jar files there. I wish this was easier.

I've been planning to test Scalable OpenGroupware.org for some time now, but all my email boxes are 64 bit and Inverse only provides 32bit rpms.

Recompiling the RPMS hit some unfortunate problems, and the maillinglist didn't provide much help. The project got shelved for not being workable - until a client asked for a calendar solution.

.

Reading through the getting started documentation for EC2 I find this little gem:

C:\> <span class="command"><strong>ec2-describe-images -o self -o amazon | findstr /i windows</strong></span>
grep for windows. Yay!
.

One of the things I often miss with Netbeans is better navigation between different files.

 

For example, I miss the CTRL-e shortcut from Eclipse that lets me easily move between different files I am editing. Another example si being able to click on a line in the output from running a Junit test and be transported to that file and line number.

 

.

When you have written a few tests using Easymock you might get into the fun situation that you need to mock a method that returns void and you want the method to throw an exception. What do you do?

Usually you would write something like:

expect(mockSender.send(message)).andThrow(new Exception());

But this does not work with void methods because expect() cannot work with a void return value.

Solution

Use expectLastCall():

.

5 months ago, I switched jobs. One of the things I needed to implement at my new workplace was a systems monitoring and management solution. I decided to use Zenoss.

The reasons were many, but the main ones were:

.