Monday, March 30, 2009

JBoss Serialization simple example

I know this is a rather trivial thing, but serializing non-serializable objects is not very well documented online (as far as I could see), so thought I would post an example using the well known solution JBoss Serialization.

What I am doing is trying to add jBPM context variables that are serialized for transport (SOAP), so here a non-serializable web service result object will be serialized.

// Using Jboss to serialize a non-serialziable web service result object.
//
Map<String, Object> contextData = new HashMap<String, Object>();
JBossObjectOutputStream objOut = null;
byte[] serializedResult = null;

try {
    ByteArrayOutputStream out = new ByteArrayOutputStream() ;

    objOut = new JBossObjectOutputStream(out);
    objOut.writeObject(result);
    objOut.close();
    out.close();

    // jboss serialized object into byte array.
    serializedResult = out.toByteArray();
} catch (IOException ioEx) { 
    LOG.error("Unable to serialize the service results object: " 
        + ioEx.getMessage());
} 

// insert into context.
context.put(RESULT_DATA, serializedResult);

// using previously created process instance we can now add this to 
// our jbpm context via a given token.
token.processInstance.getContextInstance().addVariables(context, token);

To un-serialize you just reverse the order above using a ByteArrayInputStream and JBossObjectInputStream.

================ UPDATE =====================

I have cleaned up the above action and provide a reusable utility method to serialize and un-serialize an object to/from a byte array.

/**
 * Converts an object to a serialized byte array.
 * 
 * @param obj Object to be converted.
 * @return byte[] Serialized array representing the object.
 */
public static byte[] getByteArrayFromObject(Object obj) {
    byte[] result = null;
       
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new JBossObjectOutputStream(baos);
        oos.writeObject(obj);
        oos.flush();
        oos.close();
        baos.close();
        result = baos.toByteArray();
    } catch (IOException ioEx) {
        Logger.getLogger("UtilityMethods").error("Error converting object to byteArray", ioEx);
    }
        
    return result;
}

/**
 * Utility method to un-serialize objects from byte arrays.
 * 
 * @param bytes The input byte array.
 * @return The output object.
 */
public static Object getObjectFromByteArray(byte[] bytes) {
    Object result = null;
 
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
 ObjectInputStream ois = new JBossObjectInputStream(bais);
 result = ois.readObject();
 ois.close();
    } catch (IOException ioEx) {
        Logger.getLogger("UtilityMethods").error("Unable to deserialize object from byte array.", 
            ioEx);
    } catch (ClassNotFoundException cnfEx) {
        Logger.getLogger("UtilityMethods").error("No corresponding class for byte array.", 
            cnfEx);
    }
  
    return result;
}

Saturday, March 21, 2009

Open Source Expert Panel - IBM heeft lastige klus aan integratie SUN

A while ago I provided some opinion material to an article stating that SUN is a leaking oil tanker. Now that IBM might be willing to save that sinking ship I have been asked to provide my thoughts again, published here as a front page news item.

Friday, March 20, 2009

Another long Veluwe ride

It was a 2,5 hr ride through the hills around Apeldoorn, Hoenderloo, and Otterlo. Sunny,
cool at 12 C, with a bit of wind. Burned over 2800 calories over 64 km.

This was a good day. ;-)

Wednesday, March 18, 2009

Ride in the Veluwe today

Rode for 1 hour and 40 minutes in the hills near our vacation location. Climbed up a 6 km hill (awesome!) and some smaller steeper ones around Apeldoorn. Total ride was 40 km and I burned over 1700 calories. Great weather, sun and a bit cold.

Friday, March 13, 2009

Have you ever had an old school design session?

I thought some of you out there might appreciate this picture. While looking at a rather complex problem that required a process design, I was presented with this very old school work breakdown structure as the Information Analyst saw it (on the right in the picture, with all them yellow sticky notes just waiting to fall off).

It took most of the day in a sort of workshop session to pull the not yet written use cases out of the Information Analysts and many "oh yeah, I forgot to mention..." It resulted in the process design you see here which is then used to roughly estimate the number of man hours needed to implement it. With all the available technology, we are using sticky notes for placeholders, notes in a workbook, and nothing even remotely created in this century... luckily I had my mobile phone camera to be able to capture the work done in this session.

Is it just me? Have you ever had days like this on your jBPM projects?

Saturday, March 7, 2009

Bit of a time trial today

Made a run with my new bike to Uden today. Bit of wind at the back but from door to door it was 32km and I did it in 1 hr 5 min, the fastest I have done that yet. I love this bike!

Trading in my Austin Mini 1987

Today I have traded in my lovely Mini for a better car. It was a necessary step in the evolution towards my new job, but rational thought has nothing to do with it. I have over a 5 year relationship with this beautiful car. I have been working on it in the hot sun, in the rain outside in the street, and I loved every minute of it.

My kids really have loved having "the blue car" in the family and they both giggle with glee when we ride around in it. I will never forget my little girl helping me tuning the points on a sunny summer evening, passing the tools to me and asking Daddy "what is that... what does this do..." With a Mini in your life, you have it really good.

Some of my favorite memories are pictured here and I hope some day in the future to be able to claim that I own a real Mini again. May the future owner of this Mini enjoy it as much as I did. I am afraid this will be my last Mini posting for some time.

Friday, March 6, 2009

Job change - off to join RedHat

I have been rather quiet on posting as I was struggling with a very big decision over the last 5 weeks. I have decided to accept an offer made to me by RedHat and become their JBoss Solutions Architect BeNeLuX.

It was an offer that I could not refuse, with both technical depth and the elements of Free Open Source Software (FOSS). This challenge lies close to my heart and I am very excited to get started having just signed the contract papers today. I hope to make use of my experiences with both JBoss and jBPM in the field to fulfill my new tasks. I will be starting on May 1st, 2009.

I will be leaving behind a job at SNS IT that I really enjoyed and an employer I would rate as the best I have had up to now. They gave me the freedom to be both technical and creative, a combination not often achievable within IT organizations. For this I will always be grateful and would like to thank all of you (you know who you are) that made each day fun and full of laughs!

Sunday, March 1, 2009

First trips on the new bike

After picking up my new bike I was really looking forward to the first ride. Unfortunately the weather (both snow and ice enough to skate on here in the Netherlands) and a few colds in a row kept me off the thing.

Finally this weekend I got two days of 12 degrees Celsius and some sunshine! Off on Saturday for 40 km but ran a rear tire flat at the 20 km mark. Had to take it easy the last 20 km back home. On Sunday I only got 6 km down the road and again another rear tire flat. That pretty much ended my weekend attempts at riding. Both punctures were just small pieces of stone / shell that cut through both tire and tube. I sure hope this was just plain bad luck...