Wednesday, December 23, 2009

C# String GetHashCode()

It is very difficult to Java developers to write C# code. Not because of the language - they are pretty much the same. But it turns out you make basic assumptions which are just not true.

We develop C# code that access services deployed in WebSphere ESB and send messages in WebSphereMQ. The sender creates a message identifier, that consists of the sender id, object type and more. The listener creates the same identifier, and listens to the queue with this identifier.
Suddenly - the identifier the listener and the sender create is different.

Turns out that the problem lies in the fact that the sender is a 32bit machine, and the listener runs on a 64bit machine.

Why is that a problem? Because in .net, code is not cross platform - not even between Windows environments - since the GetHashCode() function of String is not cross platform - and works differently on 32bit and 64bit machines.

Unbelievable!!!

Anyway, we wrote our own Hash function, that simply copies the java.lang.String hash() function (every JDK comes with src.zip, where you can find the java.lang.String code).

3 hours of my life wasted...

Thursday, December 3, 2009

WebSphere Process Server - skipping steps in the process

A customer of mine has decided to build an application that can monitor his processes, instead of the regular WPS supplied tool.
His main concern was skipping steps. Turns out that when a process has executed a specific activity, and this activity is in a special position (like user task) - an outside application can cause a skip in the process.
I have developed a short demo for this, and I'm enclosing the main method here. Just make sure to disable the process security before running it - or you'll get a non authorized exception...

// Connect to the server
Properties props = new Properties();
props.put(Context.PROVIDER_URL, "iiop://localhost:2811");
javax.naming.InitialContext ctx = new javax.naming.InitialContext(props);

// Lookup the BusinessFlowManager. If you get casting exception - read the InfoCenter - you need to add some JARs to your code - it's WPS/ProcessChoreographer/client/bpe137650.jar
Object lookupResult = ctx.lookup("com/ibm/bpe/api/BusinessFlowManagerHome");

BusinessFlowManagerHome processHome = (BusinessFlowManagerHome) PortableRemoteObject
.narrow(lookupResult, BusinessFlowManagerHome.class);

BusinessFlowManager bfm = processHome.create();

// Replace with any process id
ProcessInstanceData pid = bfm.getProcessInstance("_PI:90030124.f71386d4.dbed54f5.5d84025c");

// Replace with any activity name
ActivityInstanceData aid = bfm.getActivityInstance(pid.getID(),"Wait");

// Skip to the specific activity
bfm.skipAndJump(aid.getID(), "TargetActivity");

Wednesday, November 11, 2009

AspectJ 1.6 with runtime weaving and WPS 6.2

Well, I haven't blogged in ages, and it's not because I lacked things to share...
Anyway, almost all of my WPS customers are looking for some level of polymorphism (or process templating) and AOP. For the first - I currently have no solution. For the second - here comes...

  1. Download AspectJ 1.6.2.
  2. Since it's been a long time since I worked with AspectJ, I wrote a small program in Eclipse. I just made sure that it used the WPS JDK - to make sure the -javaagent flag works. It does. However, you can't use it when your eclipse works with a Sun JDK. So - add a -vm to your eclipse.ini file. (See here for details: http://wiki.eclipse.org/Eclipse.ini
  3. Now, I opened a new WID module, wrote a short process.
  4. I also created a small Java Project, which will create a JAR in the WAS/lib directory. It will include my aspects and the aop.xml file (under the META-INF directory)
  5. I started my WPS server, and put the -javaagent flag in the startup options. WAIT!!! Since WPS security is enabled by default, and the aspectJ weaver is located outside the WPS libraries - java security policy won't let it load - and you can't start your server!!! Copy the jars into the WPS lib directory. Just make sure you don't override existing files (aspectj.jar should be in WPS/lib - just rename it to something that doesn't end with JAR)
  6. That should be it - the aspects now work. However, how do we tie them to the process itself?
  7. It seems that the way WPS works is that for every BPEL activity there is a class in the com.ibm.bpe.engine package, and the doActivate method is called. So our pointcut will need to look like this - @Before("call(void com.ibm.bpe.engine.BpelActivityKind*.*(..))") - this should also explain why we put the aspect in the JAR in the WAS/lib directory - it should be in the correct class-loader level.
  8. Well the only thing missing is the actual pointcut - but it's too late for that - will publish it tomorrow morning... Don't hold it against me. I will also post the required code to get which Activity we are on. Quite cool...

Sunday, September 27, 2009

WebSphere ESB and EJBs

My next post will probably be a book review - I was asked to review a new book on WAS 7.0 administration. Cool. Hopefully I'll be able to read it in the next couple of days (did I ever mention I was a quick reader?)
In the meantime, I want to publish my findings on the use of EJBs in WebSphere ESB.
A customer of mine is using WebSphere ESB. For services, it developed EJBs (stateless, of course, but still - version 2.0).
The mediation module has imports for the EJBs.
This turns out to be a very bad architectural decision (I arrived to the project after this decision was taken :-) ) , and right now they are rewriting everything, to drop EJBs and use SCA Java components.
Why?
  1. SCA Java components are actual EJBs, so why have an EJB call an EJB? Not a smart move, performance wise.
  2. Mediation Module (6.1) EJB support is lousy. It fails generating good mapping between the Java bean parameters and Data objects. So my customer resorted into sending Strings to the EJBs, and then parsing them, at the EJB level, to POJOs, using XMLBeans. This is insane - and shouldn't be done.
So what is the current (working!) recommendation?
Use SCA Java components, in the same module, or other modules, depending on your component visibility and deployment needs.
Inside the Java component, use a mapper to map the DataObject object into real Java POJO. and then pass it to your business logic, which is implemented in regular Java Classes.

The mapper is really easy to write:
1. Use JAXB or XMLBeans to generate mapping between the DataObject XSD and a Java class.
2. Write a method that has the following signature:
public static Object mapper(DataObject do, Class clz)
3. Use reflection on the clz - create a new instance of it, and for every field decide:
3.1 If its a primitive - transform it.
3.2 If its a Java Class - call yourself in recurssion
3.3 If its an array - run over all elements

It works fine, great performance, and the development barrier was lowered by more than a few inches.

Hope it serves someone well.


Thursday, September 17, 2009

Problems installing WID 6.2 on Windows 7

I faced many problems while installing WID 6.2 on my Windows 7 machine. I won't get into the full set of problems I encountered, but the process that did work for me was as follows:
1. Don't run the launchpad application, but the installer inside IM_win32
2. Run the installer in compatibility mode, for WindowsXP SP2
3. Since I already tried installing - I had to install everything to a clean directory
3.1 This is a reported bug and was fixed in a fixpack already
4. Remove the file c:\windows\.nifregistry

I found the last tip after digging inside the installation log files, I found the following command executed -C:/Program Files/IBM/WID62/image/WPS62/iip/contrib/6.1.0-WS-WASWS/1/WinX32\WEBSV\install.exe -options C:/Users/liran.ALUNA/responsefile.WEBSV.txt -silent
And the log file specified a NullPointerException on the com.ibm.ws.install.ni.framework.product.VersionUtils.compareVersionsUpToDigit(VersionUtils.java:170)

The weird thing is that I did everything by the book, so it's not clear to me why no one else got this error. But hey - it works now...

Sunday, September 13, 2009

Working with Linkedin

I've found that I'm using LinkedIn more and more. As a matter of fact - I think I spend around 2-4 hours a week on LinkedIn - getting new connections, sending messages, and finding leads. Heck - I even found a recommendation for my kid's kindergarden from LinkedIn. Not exactly what I would expect from a professionals network.

But mostly - I try to hire people through LinkedIn. All our tests found this to be the most effective way to get CVs. From around 700 connections I usually get 40 responses (not all from my connections, and I also post in groups I belong to) - around 80% of them relevant. Much better than the junk I get from web based hiring sites, or from head hunters.

Still - I have a problem. Can't understand why LinkedIn limits me in sending messages to only 50 people at once. Considering all of these guys are my friends - LinkedIn shouldn't care about that. Heck - if they only offer this option for premium sites - I'll go premium (they don't, however).

What to do? Can't say it here (haven't checked the legal stuff yet). But I might have found a solution. It involves coding however. Tons of coding. Luckily I have strong Java roots...

Sunday, August 9, 2009

Stale Connection in WebSphere Application Server 6.1

Well, a customer of mine has a very weird bug. Sometimes he gets a StaleConnection exception when executing a statement against his Oracle Connection. The client runs WebSphere App Server 6.1, Oracle Database 10g, and uses EJBs and an XA datasource.
Finally, we discovered that there is a scenario that always raises the Stale Connection Exception, and we started investigating the root of the problem.

First of all, WebSphere throws the Stale Connection exception as a wrapper to specific SQL Exceptions received from the JDBC connection.
But why is the connection suddenly closed? A step-by-step following with the debugger found that we get the connection open from the datasource, and then, suddenly, the connection is closed.
We tried to convert the datasource to a non-XA datasource, and received allot of exceptions. This showed us that the process in question needed the XA capabilities of WAS.
We then wrote wrappers over Oracle's XA connection manager (oracle.jdbc.xa.client.OracleXADataSource) and Oracle's Connection (oracle.jdbc.pool.OraclePooledConnection), and seen the debug messages.
We still have no solution, but there can be 2 options:
1. There is a bug with the WAS XA handler.
2. When using statement.getConnection().close(), we close the physical connection, and not the logical connection coming from the datasource. The customer now changes his code, to see if he can get away without the statement.getConnection() bit, and close the logical connection received from the datasource.

I'll post more details later.

Sunday, August 2, 2009

WebSphere ESB Invalid Content Length

Well, turns out I was mistaken in my previous post. Invalid Content Length can occur when using MTOM in .net C# clients with WebSphere ESB, but that was not the case in our customer.
Invalid Content Length appeared when the client closes the socket before sending the entire request. This can happen when the process is halted during send time. WESB will sysout Invalid Content Length, but you can usually ignore it.

However, we still faced a problem with very large service calls (over 1MB in size - only XML, no attachments). Turns out that our synchronization code was messed up, and for some reason - our cache was not correctly initialized, and so we received allot of NPE (NullPointerExceptions).
So - we synched our cache, and voilla - all works.

That teaches me to blog before I see everything working in my own eyes.

One last important issue. Sending large service calls can take time. Allot of time. And so, each C# client has a Timeout property, that sets that Timeout for the service call, in milliseconds. Use it well, since you are very likely to get a Timeout exception before you get the web service response.

Thursday, July 23, 2009

WebSphere Integration Developer issues

Well, it was a while since I've posted - mainly since my partner (Doron) is in Japan, and I have to do the work of two.
But there is a 10 minutes break now, and I really wanted to blog these issues:
1. If you need WAS 6.1 to work with WS-Security and C# clients - drop it. The built in web services support in WAS - JAX-RPC or JAX-WS, just doesn't work.
2. If you send WAS web services, with large content from C# and get SRVE0080E: Invalid content length - you need to set the sendChunk=false property on the .net request client. This will fix it.

Thursday, July 2, 2009

WebServices Versions

Well, just read this. It's an article by IBMers on versioning of web services and schemas. I got this URL from @kfrion after a phone call we had together concerning the versioning of APIs.

The article highlights the same problem I'm presenting in my SOA classes and to my customers. Generating WSDL is great. Whether you're using VS.Net or AXIS/CXF/Metro - WSDL is automatically generated and it works just fine.
However, if you want to use company standard XSDs (from your repository of business objects), to enforce policies, or anything like that - you're stuck. The reason - WSDL editing tools are just not good enough.
And if you need to upgrade your WSDL version - changing the target URL, the schema and so on - then you're on the road to hell, since it requires so much low level understanding of the schema and WSDL specs that your chance of getting it right is slim.

So, what we really need are tools that will allow us to set everything in the WSDL from our code annotations (schema locations, policies, etc.), and can understand changes we made to our programming language code, and generate a backward compatible WSDL according to all versioning best practices.
I've developed something like that (very very limited) in C#. If someone is interested - reply or mail me.

Wednesday, July 1, 2009

Technorati

Well, time to join Technorati. So here is the code - hbsqcxpkyg... Hope all goes well.

Monday, June 29, 2009

WPF and Silverlight

Wow. 2 weeks since my last post. Had about 100 twits since then. Just goes to show you.
Anyway, I was asked to give a presentation to a customer concerning Microsoft new technologies. I told them that I'm a Java guy - but they just asked me to do it anyway. What could I do?

So, I opened my VS.Net2010, and my PowerPoint 2007, and started making some slides. Talked about cloud (from Yahoo presentations), VSTS, SQL Server 2008 and more.

But the technology I'm most impressed with is Silverlight and WPF. Now, I've seen my share of WPF and Silverlight applications, and development demos. But working on these technologies using VS2010 is a great experience. I've developed 2 demos (on technologies I hardly know) in like 5 minutes. And comparing it to my VB6 experience way back, I had to say WOW. WPF is clean, organized, very well documented and understandable. Compared to SWING/AWT/SWT - it is much simple to use, the applications run faster, and the development tool is much much better.
For short - the old best practice - of building client UIs in MS technologies, and backend systems with Java technologies, and connecting the dots with Web Services/REST/JSON - seems to still be in place.

Monday, June 15, 2009

Facebook App Development

So, preparing to my alphageeks lecture, I started building a demo facebook application. As always, I try to set the standard high - probably too high for my free time. So, mining facebook data is not interesting enough for me. Instead - I want to build a facebook applicaiton, that will be hosted on my page.
Not an easy task - let me tell you that.
  1. I started by downloading Apache-Tomcat 6, hoping it will run my application.
  2. Downloaded the Google Java Facebook API, and the web application that comes along with it. (See here)
  3. Deployed the web-app in Tomcat.
  4. Got tons of DB related problems - but I don't care.
  5. Fixed params in the facebook.properties file (api_key, secret and callback)
  6. Got a static IP.
  7. Changed the facebook app call-back URL
  8. Added my custom code to the web-app.
  9. Voila - all works.

Monday, June 8, 2009

TPTP and Java6

Well, I'm demoing TPTP, and decided to use Java6. Why? Because my laptop is new, and I'm going with the most up-to-date version. Not neccessarily the right call. Why? Because all tutorials on the net show how TPTP work with Java5, and not with Java6. What's the difference? JVMPI, which TPTP works on, is discontinued on Java6. So, how do we profile using TPTP?

Man. This is lame!!!

Sunday, June 7, 2009

Meeting effectiveness is disproportional to its length

Well, I've read - http://www.businessinsider.com/how-not-to-blow-your-meeting-with-me-2009-6 - and loved it.
I'm following a rule that says the longer the meeting - the less effective it is. Our board meetings take 2 hours - and are a total waste of my time. Customer meetings - I'm keeping to a 30 minutes top. The most effective ones I have are 10 minutes long. 5 minutes chit-chat, 3 minutes business (this is what I do - cool, this is what I need, or vice verse), and 2 minutes goodbyes.

I've searched and couldn't find a reference to such a law on the net (meeting effectiveness is disproportional to its effectiveness). If you do - please post it here.

BTW - the law doesn't apply in government agencies and financial institutions. Or rather - it applies there more than anywhere.

Thursday, June 4, 2009

SOA and GWT/HTML Scraping

As promised, I continue my previous posts on the Message Enrichment scenario. I met with the customer, and it seems, that the only way to truly enrich their ESB message is to build an image processing engine right inside the ESB. Although it sounds quite cool - and I'd love to do it myself, since it's been years since I wrote some image processing code (last time was on Turbo Pascal for Windows 1.5 - ;-) ) - it seems like a waste to put inside the ESB.
The solution? Use an HTML scraping as an ESB connector, to rip the data from the web browser, and use it as a service. The reason - the application wrote some code inside the engine, and some code (like zoom-in/zoom-out) inside the web browser (using GWT). And so a command will be recieved, it will be translated to an HTTP GET request, and the resulting HTML will be scrapped, to get the actual required image.

I like this idea, and not (only) becuase it's mine. I think it makes good reuse of existing code, which is what service exposure is all about, at least for me. The shocking part was that no one I talked to even considers HTML scraping as a legitemetasdf SOA concept. Ain't that odd? I can't count the times I had to pull my HTML scraping toolkit (XQuery and JTidy are fine by me, thanks) and rip information from existing HTML pages.

However, there is a chanllenge here. Is it even possible to scrap GWT based pages?

Wednesday, May 27, 2009

Attention span

I am watching the soccer game right now, Barsa is leading 1-0. However, my laptop is on my laps (I already have 2 kids). I find that I just can't focus on anything on TV without doing some work in between.
I blame it on the TV series I watch on my laptop while working. I think I saw all of Stargate 10 or so seasons without wathcing a single episode - just hearing them.
Really lame.

Tuesday, May 26, 2009

Message enrichment

I was asked yesterday by a new customer about the following problem.
You have 2 systems that do basically the same thing. You build a new UI that needs to activate both systems. One system exposes WSDL A, the other - WSDL B. There is an ESB in the middle.

So, my gut feeling was - build a bridge in the ESB and make one service to the outside application.

But - turns out the bridge is quite a task. WSDL A and WSDL B were designed in a totally different manner - one is coarse grained and on is fine grained. So the bridge would need to store temporary information in a database. If that's not enough - some messages contain JPG files, and processing and merging them is neccessary.

So, what do we do? we thought of another option. Building the new UI, and letting the UI activate the 2 services - or even better, do some mashups from the existing 2 applications (each accessing the different application).

Since this was just an introduction meeting, nothing was yet decided. My gut feeling is the bridge, since this is the organization first real "Service", and I want to make sure the organization get the real taste for SOA.

But, there will be some more meetings on this matter - I will write updates on this post.

More on Windows7

I can promise that this would be the last post on Windows7, but that would be a lie...
Anyway, Eclipse3.4 (Ganymede) now works on my machine. What changed? I don't know. I did nothing, that's for sure. But Windows7 is starting an irritating habit of restarting during the night. Now since I am (still!!! damn IBM) downloading the 5.5GB of WID, this freezes my download, and I need to wake up to continue the download manually. Luckily, my 4month old - Naama, is waking at 5:30, so I don't lost much download time.

In addition, I updated my network drivers, and it seems my browsing experience is much improved, thank you. I saw allot of questions in the forums on this - slow browsing/downloading - so I guess that this is quite common. I hope I am behind this topic. Only 1 hour to finish download WID. I am not sure, but I might install it on Ubuntu. I downloaded the VM yesterday.

After that - downloading an Oracle DB VM. Oh - and I'm working too. But that - on my next post.

Monday, May 25, 2009

Chrome and Windows7

So, it seems that Murphy decided to visit me after my last post on the wonders of Chrome. It seems that on Windows7 I'm facing some weird bug - download speed is slowing to a crawl. So my 5.5 GB download of WID 6.2 (IBM - get me a net installer, like VSTS10) was supposed to take like 500 days or so. on IE8 - 9 hours. Odd...
But still, I'm keeping loyal to Chrome. At least until something better arrives.

Sunday, May 24, 2009

Chrome

Well, I've installed my Windows7 machine, liked it, and so on. However, with Windows7, comes IE8. Now, I still used IE on my old machine (XP) since some sites demands IE (my bank site, government - pay taxes site and my favorite - Matrix internal portal). But I've moved to FireFox3 a long time ago, and never looked back.
However, on Windows7 - no more FireFox. Only Chrome. I've used it before, but now it is my default (and practically only) browser. IE8 is there - for the IE required sites, but I never even tested it. Just installed Chrome - and off we go.
The most useful feature about Chrome is it's layout. No Windows title - so more browsing space. Address-bar is merged with search-bar, few management icons - hell I even leave the links bar activated - my first time ever.
And you have a really cool ability to take a tab and drag it to a new window, and vice-verse.
And it is quick. Really.

However, Shockwave plugin works terrible on Chrome. Some sites (www.themarker.com for instance) use Shockwave for commercials, and my page gets stuck. Luckily (and unlike FireFox) Chrome isn't hang over Shockwave - only closes the misbehaving tab. So for now - Chrome is my browser of choice. 

One more word for Google - quickly you guys, release a plugin environment. Everyone is waiting...

Thursday, May 21, 2009

Windows7

It's been 36 hours since I installed Windows7. Somethings I gathered:
  1. Installation is a snap
  2. Everyone thinks I'm crazy - especially those with Vista experience. Since I never used Vista - I have no idea what they're talking about. For now - I love my Windows7.
  3.  There's a key combination providedd by Windows to support projectors. Finally. I have these Lenovo combinations. The hibernate button on my Lenovo laptop was the Projector button on my HP laptop, so for the first couple of months I've closed my machine whenever I wanted to present something. Not cool!!!
  4. Most of the things are installed. At least the important stuff. 
  5. I gave up and instead of using my own private directories for files - I've placed everything under my documents. No more "c:\My Music" but instead using a Music library.
  6. I hate Windows Media Player. Don't know why. It downloads stuff for each MP3 I play. Why do I need it? But the media library is very nice. I'll need to learn how to use it though.
  7. Took me a time to get accustomed to the small icons stuff on the TaskBar. Finally I gave up and displayed the labels as well.
  8. Can't get used to the new Windows Explorer. So, I've downloaded Total Commander - which rocks, even on Windows7
  9. The fact that I can use Alt-Tab to "Show Desktop" isvery good.
  10. I need more hours in a day. And much more sleep.

Starting 1,2,3...

So, finally, started using Blogger. My older posts are at http://cafe.themarker.com/view.php?u=96770, which I dropped since I dislike TheMarker Cafe.