Monday, December 20, 2010

SSL negotiation fails after Apache and OpenSSL update

Today I updated many packages on my server to the latest version and also build and installed the latest Apache server. After the update however, I was not able to connect to my server anymore using SSL. The browser reported it could not establish a secure connection with the server and on the server the logs showed this error:
[Mon Dec 20 16:18:20 2010] [error] [client xx.xx.xx.xx] Re-negotiation request failed
[Mon Dec 20 16:18:20 2010] [error] SSL Library Error: 336068931 error:14080143:SSL routines:SSL3_ACCEPT:unsafe legacy renegotiation disabled

Googling around I finally found this post in the openssl-users mail archive which described the problem. Apparently the latest openssl package fixes a renegotiation bug which allowed a man-in-the-middle to intercept negotiation traffic. This was fixed by extending the ssl protocol. Some browsers like IE 7 and 8 and Safari (!) however still do not support this new extension so cannot connect over ssl anymore to the server.
In the Apache server a new option was added (SSLInsecureRenegotiation) which allows you to disable this bugfix so older browser can still connect. This means however that you are still vunerable to man-in-the-middle attacks !

Friday, November 19, 2010

JBPM4-Spring-integration update

I got some remarks about the released JBPM4-Spring-integration sources since I didn't include the test sources. So I just released a new version which now also contains an assembly of the whole project so all resources including the test classes and test resources are included in this.

Update 28-12-2011:
Both documentation and sources can now be found in this git repository. It also contains the pre-git releases and snapshots of previous versions. Latest version is 4.3.2.

Back from Devoxx 2010

Just back from the Devoxx 2010 conference in Antwerp. Again an excellent event with too many interesting sessions, so I'll have to get a Parleys account to view all the ones I was not able to see.
This year my focus was mostly on script languages and NoSQL/Cloud. I have seen lots of cool sessions about Hadoop, Hive, HBase, Cassandra, Infinispan. Eager to start using it in some dummy project.

At Devoxx Mark Reinhold announced the release plans for Java7 and Java8 (mid 2011 and end 2012) and also announced the creation of 4 new JSR's for project Lambda, project Coin, Java7 and Java8. The original plan of Sun was to release Java7 this year. Ok, there was the takeover by Oracle, but it seems the developers have done nothing since the Java7 release is not going to include the most wanted features. For example, no closures in Java7. I think the 'new' script languages like Groovy and Scala are going to be used must more often in the next years. Because the Java language evolves so slowly compared to the script languages, probably because of the slow JSR processes, from now on Java will just be trying to catch up with the script languages, but hardly bring anything really new. Because of the slow evolution you get projects like project Lombok to try to make Java more like the script languages.

The Java modules feature which will come in Java8 looks promising. Because Java8 will not come until the end of 2012, this will most likely also effect the release of JEE7 which wants to make use of the modularity. In the Java discussion today at Devoxx, Mark Reinhold was very clear about modularity: In his opinion OSGi is not the right modularity solution for all Java developers for all time. So therefore they're working on project Jigsaw. Will this mean OSGi will only exist until the release of Java8? Maybe not, because lots of vendors are already adopting OSGi for the app servers.

All in all a very good conference. If you were not able to attend, then definitely get a Parleys.com account so you can watch the sessions online. In twice the resolution as next year. And, while your at Parleys, watch the session of Uncle Bob of Devoxx 2009, which is free by now. Very good session. All his comments are still actual I think. That's the only think Devoxx 2010 was missing: Uncle Bob. Next year you can probably was more sessions real-time online. This year was the trail with just the keynotes.

Tuesday, July 6, 2010

BeanUtils vs. PropertyUtils

Every now and then I come across a situation where I want to set a property by name in stead of calling the setter directly. The Apache Commons BeanUtils provides both a BeanUtils and a PropertyUtils class which implements this functionality, but I can never remember the difference between these two. When googled for this I found a comment from someone who said that PropertyUtils is the newer class so it's probably best to use that one.
There is however a big difference between these two classes which I came across while using these classes: BeanUtils does an automatic type conversion and PropertyUtils does not.

For example: with BeanUtils you can set a double valued property by providing a String. BeanUtils will check the type of the property and convert the String into a double. With PropertyUtils you always have to provide a value object of the same type as the property, so in this example a double.

Concluding: If you want automatic type conversion, use BeanUtils. Otherwise both BeanUtils and PropertyUtils seem to do the same thing. Debugging through the BeanUtils code, you'll even notice that the BeanUtils class eventually uses the PropertyUtils to set the property. So, if you don't need type conversion, by using PropertyUtils you'll probably save a couple of cpu cycles.

Tuesday, June 1, 2010

Reviewing #Navmii on #iPhone

A couple of weeks ago I bought Navmii for the Netherlands for on the iPhone. I had heard and read about it and the reviews were pretty good. From Brodit I bought a proclip and holder for in the car which are really good and non destructive for your interior. My first trip was a very short drive within Utrecht to a friend. It was just a 10 minute drive. None of all the directions given bij Navmii were correct!! Ok, I live in Leidsche Rijn where they are building continuously, but the roads I used are in use for more than 3 years so you would expect them to be on the map. This is not just a problem of the AND maps used by Navmii. Also with TomTom, GoogleMaps and YahooMaps it's impossible to navigate here. All map makers should update their maps more often. Where AND got their information is a mystery for me. Their map seems to be a mix of old roads and roads in the far future, but at least in Leidsche Rijn it contains hardly any roads of the present.

The second time I used Navmii to drive to a new house of friend near Emmen. When I tried to lookup the address in Navmii, I could not find their street. It was on the map however and when I clicked on the street it did show the correct name. I had this same problem with several other addresses too. Could not find it by name, but it was on the map. So apparently the street search list does contain just a fraction of all the streets on the map. Very annoying.

The navigation part of Navmii is pretty ok. If you follow the direction you get where you want to go. You have to pay attention to the actual situation and signs, because sometimes Navmii will direct you in directions where you are not allowed or cannot go. If you don't follow the direction it quickly calculates an alternative. When you start driving Navmii seems to hesitate or is a bit shy because it starts giving directions after the first few turns.  Too bad there is just 1 dutch voice and no options to add or download other voices. While driving on the highway Navmii tells you to keep left for each parking area or gas station. Because this is said at least 3 times which stops the music playing it is very annoying. I don't know whether this has to do with the Points Of Interest setting, but even when disabling the POI parking area's it keep saying it. Every now and then the music is faded away, but no direction is given.

The 3D view is good and shows enough info on the little display of the iPhone. The day and night view options are nice. I'm missing a sunglasses mode however. With sunglasses on I can hardly see the map on the display, but maybe this is just a thing of the iPhone display.

I use a Belkin iPhone charger with FM transmitter to charge the iPhone in the car and to be able to listen to music. We had great pleasure using it when we drove from Darwin to Perth in a campervan. With Navmii it is possible to play music in the background. The player looks a lot like the iPod app, it will stop and continue the music when a direction is given. It is impossible however to play just 1 album, Navmii will always shuffle over all your songs which is hardly ever something I want. I tried to work around this by using the iPod app to start playing an album before I started Navmii. This seems to work, but now the music is not stopped and continued but just faded away when a direction is given and often the music is faded but it gives no direction. There is a music button on the main display, but I'm missing at least a 'next' and 'pause' button. It's not possible to go to the next song. If you want something else, Navmii opens the iPod lookalike view and you have to navigate to find a next song. Not something you really want to do while driving.

Conclusion:
Navmii is a nice navigation app for on the iPhone. Maybe I should not expect that much from a €3,99 app, but hé, we want it all for nothing, right? The music shuffling and all those parking area direction are just annoying, not being able to search for the correct street is just bad and the map ... well that's just AND's fault. Maybe this app is so cheap because AND sells Navmii some old out-of-date maps. But when disregarding these annoyances Navmii will get you where you want.
It would be nice if Navmii would open up it's navigation app by allowing free (or payed) plugins to be added. This would allow plugins to add on the net available information to the app like up-2-date traffic jam info and up-2-date speed control information and there is probably more info on the net available which would be nice to have while driving. Opening up the app allows the community to take the app to a higher level and I'm convinced that in no time this app would be the greatest navigation app around.

Wednesday, February 17, 2010

Unittesting an asynchronous process with a latch

This week I wanted to write some tests to test the correct handling of a JMS message. The first service method was easy because the service send a reply, so I could check the reply to see if the message was handled and if the handling was correct. But the second service method was more difficult, because the service did not send a reply. Mmm ... how can you unittest an asynchronous process?

I googled a bit and found a reference to a CountDownLatch. Apparently a Java 5 Concurrency class. Looking at the source of this class, I thought it was something I could use, but of course I wanted to have the result of the async method available in the test so I can verify the result. In the API of the AbstractQueuedSynchronizer, which is used by the CountDownLatch, is a BooleanLatch example which looked like a good starting point for what I needed. From this example I created a FunctionResultLatch.

FunctionResultLatch

Sunday, January 10, 2010

Connecting to GigaSpace VM's with UI

I am preparing for a GigaSpaces training later this month. Since I work sometimes on my MacPro and other times on a MacBook, I wanted to create a VM in which I can play with GigaSpaces. But since I'm using a very basic Debian VM, which has no X11, I have to run the UI on OSX.

On first try I could not get this working. The UI would not display the GSM's and GSC's started on the VM. Here's how I got it working with a little help from J.R. from Tricode:

The reason why the UI cannot see the GSM's and GSC's has to do with a multicasting problem. The XAP 7 documentation contains an item about configuring multicast. For me it was pretty simple.

  • On the VM: I changed the hostname in /etc/hostname to 'giga1' and added the ip and hostname to /etc/hosts: '192.168.1.110  giga1'.

  • On the UI host: I added the VM hostname and ipaddress to /etc/hosts: '192.168.1.110  giga1'


I ran the multicast test which was successfull are these changes. To run the multicast test run these commands. One on the VM and one on UI hosts:
gs>admin multicastTest -sender
gs>admin multicastTest -receiver -verbose

Here are some links for those who have more complex setups:
http://www.gigaspaces.com/wiki/display/XAP7/How+to+Configure+Multicast
http://www.gigaspaces.com/wiki/display/XAP7/How+to+Determine+Whether+Multicast+is+Availablehttp://www.gigaspaces.com/wiki/display/XAP7/How+to+Configure+an+Environment+With+Multiple+Network-Cards+%28Multi-NIC%29
http://www.gigaspaces.com/wiki/display/XAP7/How+to+Configure+Unicast+Discover

JBPM 4.3 with Spring

Just before 2010 the JBPM team released the 4.3 version. Some new features are the new jms activity and BPMN 2.0 support. But besides the new features the integration of JBPM with Spring is very much changed. Not for the best, if you ask me, but they did make it easier to get started with Spring. Reason for me to rethink what I wrote about in Integration JBPM with Spring.

In 4.3 if you generate a new configuration for Spring, you also get an application context ready to use.
ant -Dtx=spring create.cfg

This looks good. There is a problem however with getting the JBPM services, like RepositoryService, ExecutionService, available in Spring. (See issue JBPM-2710) The problem is caused by the Spring integration rework they did in JBPM 4.3. The old SpringConfiguration is replaced with a SpringHelper to create a SpringProcessEngine. When requesting a service this SpringProcessEngine only looks for available components in the Spring context which creates the cyclic dependency. Spring wants to construct a service, delegates the creation to the SpringProcessEngine which returns the bean under construction from Spring. Spring detects this and throws an exception.

Issue JBPM-2710 workaround


The solution to this problem is to have SpringProcessEngine first to look in the JBPM contexts and then in the Spring context. Because the SpringProcessEngine class is hardcoded in the ConfigurationImpl it is not possible to subclass it and do the right stuff. The first workaround I tried was to create a new Environment, using the SpringProcessEngine as an EnvironmentFactory, and get the services from this Environment. This does return valid services because the environment does search in the correct order. The problem however is that the Environment gets closed and therefore also closes the Hibernate Session causing 'session is closed' errors when you want to do multiple actions in a single unit.

It is possible to workaround this issue by using a Command to retrieve the services. I created a GetEnvironmentObject Command to achieve this. By passing the wanted class type to this command you can retrieve any object from the JBPM context so also the services.
RepositoryService rs = processEngine.execute(new GetEnvironmentObject(RepositoryService.class));

Making it even easier


In the application context generated by the JBPM Ant build, the JBPM components are configured like this:

<bean id="springHelper" />


<bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />


Because of issue JBPM-2710 it is not possible to get the other JBPM services available in Spring. By using the auto configuration options of Spring 3, we can not only replace this with just 1 <context:component-scan ../> line but also workaround the JBPM-2710 issue and make all services available in Spring. Take a look at the JbpmAutoSpringConfiguration source. With this configuration class other Spring components can autowire to all JBPM services.

ProcessLookup Bean


When we're going to use JBPM at the customer I'm currently working, we probably want to be able to deploy new versions of processes at runtime. This means that components starting process instances must somehow be able to always start the latest version. With this in mind I created the JbpmProcessLookup bean. In the future I will probably add some methods some you can easily start the current or other versions of a process.

Sources and docs


I updated the sources and docs from the Integrating JBPM4 with Spring example for this blog.
Update 28-12-2011: I pushed all sources, binaries and docs about the jbpm-spring integration to this new git repository. This also contains the version 4.3.1 maven artifacts for this post. Note there was an update on this post and that this is not the latest version.

Any comments and feedback is welcome to jbpmspring AT diversit DOT eu.

Sunday, January 3, 2010

Integrating JBPM4 with Spring

At the Devoxx last november I attended the JBPM In Action univerity class. I was very impressed with JBPM and looking at all the tools available it also looked like a product which could really be used in production environments. Because I might have a project in which I could use JBPM, I decided to have a closer look at it. Straight after the Devoxx I downloaded JBPM and started working with the examples. The documentation is really good and it was easy to get started.

Since the customer I work for uses Spring in all it's projects, I searched for how to use JBPM in Spring. Although I found some references like this Server Side article, it appeared Tom had only explains this in his Spring Enterprise Recipes book, but not on any public site. So I had a go with it.

Integration:


I started with 3 goals in mind:

  1. To be able to use JBPM for other Spring component so JBPM resources are available and a process can be started by other components.

  2. For JBPM to be able to use Spring component in it's process.

  3. To be able to run Maven tests using JBPM in an in-memory HSQL db.

Looking at the JBPM Javadoc API I guessed the best place to integrate JBPM with Spring was via the Environment. I already drew some classes but when I wanted to implement and use them I noticed there are already some Spring classes available.
By using org.jbpm.pvm.internal.cfg.SpringConfiguration class to configure your JBPM ProcessEngine a Spring context is added to the environment. Disadvantage of this class is that is loads it's own Spring context via a 'jbpm.test.cfg.applicationContext' property if you use this class from your own code to initialize JBPM. However, this class does implement Spring's ApplicationContextAware interface, so by defining a 'configuration' bean in Spring with this class, the ApplicationContext automatically gets injected.

<bean id="configuration" class="org.jbpm.pvm.internal.cfg.SpringConfiguration" />


So this makes the Spring context available with a JBPM environment (and solves my 2nd goal). To make JBPM components available in Spring and to be able to start a Process for other Spring components, I created a JbpmProcessBean. This bean takes a resource name for an jdpl.xml file and automatically deploys the process when the Spring context is started.
<bean id="testProcess" class="eu.diversit.jbpm.spring.JbpmProcessBean">
<property name="resourceName" value="org/jbpm/examples/java/process.jpdl.xml" />
</bean>

To be able to deploy a process, the bean must have a ProcessEngine instance. A ProcessEngineFactoryBean provides a single ProcessEngine for the whole application. Because the factorybean uses the configuration bean the Spring environment is automatically also available within JBPM. The ProcessEngine is autowired to the JbpmProcessBean.
<bean id="processEngineFactoryBean" class="eu.diversit.jbpm.spring.ProcessEngineFactoryBean" />
<bean id="processEngine" factory-bean="processEngineFactoryBean" factory-method="createProcessEngine" />

So with these 3 small components, JbpmProcessBean, ProcessEngineFactoryBean and SpringConfiguration, we now have integrated JBPM with Spring so Spring components can use JBPM resources (via JbpmProcessBean) and JBPM can use Spring components (via SpringConfiguration).
The complete Spring configuration looks like this:
<context:annotation-config />
<bean id="configuration" />
<bean id="processEngineFactoryBean"    class="eu.diversit.jbpm.spring.ProcessEngineFactoryBean" />
<bean id="processEngine" factory-bean="processEngineFactoryBean" factory-method="createProcessEngine" />

Easy configuration:


Although this configuration is not that difficult, I wanted to make it even easier by using the new annotations available in Spring 3. An AnnotatedSpringConfiguration class was made which does just extend the SpringConfiguration class, no new functionality!, but adds some annotations so Spring is able to detect this component and automatically initialize it upon context startup. By default this component is registered with qualifier 'jbpmConfiguration'.
Annotations were also added to ProcessEngineFactoryBean so Spring knows it's a Spring component and that the createProcessEngine method constructs ProcessEngine beans.
Although JbpmProcessBean is a Spring component, this class must always be configured in the Spring context because you probably want a bean instance for every process you have. In the context you have to define the jpdl.xml resource for each process bean. (Alternatively you could subclass this class for each process and automatically deploy that subclass to Spring)  The initialize() and destroy() methods are annotated with resp. @PostConstruct and @PreDestroy so the process automatically gets deployed in the ProcessEngine and also gets undeployed when the context gets destroyed.
The JBPM-Spring integration components can now be used just by adding this component-scan (and library dependency of course) to your context:
<context:component-scan base-package="eu.diversit.jbpm.spring" />

Testing it:


To test this integration I reused the 'org.jbpm.examples.java' example which comes with JBPM4. A simple testcase reuses code from the original JavaInstanceTest but in stead of creating a Process instance in code this is done via a Spring context. The process variables are also defined in the Spring context to test the use of Spring components by the JBPM Process.

Look here for the code of the JbpmSpringBeanTest (the testclass tests both starting the process via a key of via an id). This is the Spring test context:
<?xml version="1.0" encoding="UTF-8"?>
<beans ... (removed for readability) ...>

<bean id="testProcess" class="eu.diversit.jbpm.spring.JbpmProcessBean">
<property name="resourceName" value="org/jbpm/examples/java/process.jpdl.xml" />
</bean>

<bean id="hand" class="org.jbpm.examples.java.Hand" scope="prototype" />
<bean id="joesmoe" class="org.jbpm.examples.java.JoeSmoe" />

<!-- Embedded HSQLDB for testing -->

<jdbc:embedded-database id="jbpmDataSource" type="HSQL">
<jdbc:script location="classpath:db/jbpm.hsqldb.create.sql" />
</jdbc:embedded-database>

</beans>

The main Spring context, which you would use in your own project, looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans ... (removed for readability) ...>

<!-- Auto-detect configuration -->
<context:component-scan base-package="eu.diversit.jbpm.spring" />
</beans>

Both tests run successfully so both using a Jbpm process as a bean as Jbpm using Spring components works.

NB! Notice the 'scope="prototype"' attribute on the hand bean. Default Spring creates beans a singletons so JBPM will use the same bean instance for all processes or process-instances (!) in which the bean is used! This is ok as long as you don't keep any state within the bean itself. The Hand class however has an 'isShaken' property which is set when the hand is shook. If this bean is used as a singleton, this property is already set to 'true' before the 2nd (and all subsequent) process shakes the hand. The added 'timesShaken' (int) property shows this. If you run the test without the 'scope="prototype"' attribute on Hand, in the 2nd test the timeShaken will be 2.
By adding the 'scope="prototype"' attribute Spring will create a new bean instance every time one is requested.

Using HSQLDB with Maven tests:


JBPM needs a database to work. When running tests with Maven you don't always want to rely on an already available database. For development testing it would be handy if it would be possible to start and stop a database together with the test.

Spring 3 now provides Embedded database support to make this possible. Just adding jdbc:embedded-database to your (test)context will give you a datasource to that database.
<jdbc:embedded-database id="jbpmDataSource" type="HSQL">
<jdbc:script location="classpath:db/jbpm.hsqldb.create.sql" />
</jdbc:embedded-database>

The jdbc:script is run when starting the database so this is used to load the JBPM schema in the db. The default database type is HSQL, but I just added it so it's clear what kind of db is created.
Just adding this is not enough unfortunately. I had hoped it would just start a db and JBPM would be able to connect to it using the already configured url, but because the database is lazy so when it's not used by another component it is not started.

So to get this working we have to configure JBPM to use this Spring defined database. A Hibernate LocalSessionFactoryBean is added to the context and a dummy datasource is defined in the main Spring context:
<bean id="jbpmSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="jbpmDataSource" />
<property name="mappingResources">
<list>
<value>jbpm.repository.hbm.xml</value>
<value>jbpm.execution.hbm.xml</value>
<value>jbpm.history.hbm.xml</value>
<value>jbpm.task.hbm.xml</value>
<value>jbpm.identity.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
</props>
</property>
</bean>

<jee:jndi-lookup id="jbpmDataSource" jndi-name="java:comp/env/jdbc/myds" />

To let JBPM use this datasource we must remove the hibernate configuration from the JBPM config. The jbpm.cfg.xml points to a jbpm.default.cfg.xml (located in jbpm-pvm.jar) which contains the hibernate configuration and uses the jbpm.hibernate.cfg.xml. jbpm.default.cfg.xml is copied to jbpm.spring.cfg.xml and the hibernate configuration is removed from this configuration. In jbpm.cfg.xml jbpm.default.cfg.xml is replaced by jbpm.spring.cfg.xml.

Now I thought it would be necessary to (auto) inject the datasource into the SpringConfiguration (it has a setHibernateSessionFactory(..) method), but that was not necessary at all. Because we have JBPM already configured to use Spring components, JBPM will also look in Spring to get a HibernateSession instance and will get one from the LocalSessionFactoryBean. The test context replaces the (dummy) jndi datasource with the jdbc:embedded-datasource so JBPM now uses the embedded HSQLDB.

NB! JBPM has a jbpm.tx.spring.cfg.xml configuration which should configure JBPM to use Spring transactions but this didn't work in my tests. The jbpm.tx.hibernate.cfg.xml seems to work fine in this example.

Using JBPM-Spring integration

Update 28-12-2011:
I moved all maven sources and artifacts to this new git repository. The version 0.1.1 source and jar maven artifacts are available in the releases folder. Note however that other posts about this subject have been written and the latest version of the sources is 4.3.2.

All binaries and code shown in this article is freely available (Apache 2 license) via my maven repository : http://maven.diversit.eu/repository/.
The project is named 'eu.diversit.jbpm.jbpm-spring-integration' and the released version is 0.1.1.
Documentation is available via : http://maven.diversit.eu/docs/jbpm-spring-integration/

To use this in a project add a Maven dependency:
<dependency>
<groupId>eu.diversit.jbpm</groupId>
<artifactId>jbpm-spring-integration</artifactId>
<version>0.1.1</version>
</dependency>

And add the repository so the project can be found:
<repository>
<id>diversit</id>
<name>DiversIT Maven Repo</name>
<url>http://maven.diversit.eu/repository</url>
</repository>

The project will probably give you all needed dependencies for JBPM and Spring. I have to look into this if this is handy or that I should make the dependencies optional.
Either copy the context of the jsiApplicationContext.xml to your Spring context or import the jsiApplicationContext into your context. Don't forget to define you own jbpmDataSource for a production environment database! For testing you can use the jsiEmbeddedHSQLDB.xml context which defines an embedded HSQLDB as shown above.

Feedback:


In reasonably short time I was able to do this JBPM - Spring integration and realize all the goals I had. Since I could not find many examples of JBPM and Spring integration I'm curious to know if this information is usefull to anyone. So if you have any remarks (or compliments) about this article or the JBPM Spring Integration project or sources please send me some feedback to "jbpmspring AT diversit.eu" or leave a comment.