Wednesday, March 23, 2011

Java programming nowadays

A colleague hit a problem yesterday while testing in isolation a SCA (Service Component Architecture) component. He was trying to call WSDL method from a Java SCA component using a SCA reference. In this case you actually obtain an implementation of a generic interface com.ibm.websphere.sca.Service, and on this interface you have to use a generic invoke that looks like this:
java.lang.Object invoke(java.lang.String operationName, java.lang.Object input);

In the case the WSDL method you try to invoke has one parameter then you just pass an object (SDO - Service Data Object in fact) of that type to the invoke method, we had such a case and it worked. But what do you in case the WSDL method has 2 or more parameters? Initially we guessed that the input would be an array of objects, but it didn't work (wrong number of arguments exception) and if you think carefully it would be ambiguous to have an array of objects because one cannot distinguish if the invoke should have as many parameters as the number of objects from the array, or just one parameter (array of objects). At this point we were stuck.

So what do you do when you get stuck? You search on Google: for the exception, or a part of the stack trace, add a few keywords that you think are relevant like the application server you are using (WebSphere Process Server 7.0), framework and technology names (SCA, SDO, WSDL, Java, invocation) and the like. Sometimes you get the answer immediately if someone else hit earlier the same problem and posted the solution on a blog or a forum, but this time it was not that easy. I had to search for about 45 minutes, try all kind of keywords, read forums, blogs and help pages until I finally found the solution in a sample in some documentation manual from IBM. You basically have to use the SCA API and create a special wrapper SDO that contains all the input parameters as properties and then pass this object to the invoke method. You can read the full solution here if you are interested :)
Post a Comment