Wednesday, December 4, 2013

NoClassDefFoundError: Could not initialize class org.apache.axis.client.AxisClient

Have you ever met this Exception while you were running your java program? Were you surprised why the program complied although some class was missing? OK, here is my experience concerning this nice exception, the cause and the treatment.

1- First I double checked that the axis.jar is included in the project (actually if not included it wont compile).
2- I checked  that the mentioned class was there with its correct path.
3- I started googling the problem, got across some solutions, One of which suggested that I was using the wrong version of axis jar, and that the issue arose because the webservice client that was using this Axis class is developed using axis2 while I was using axis1 jar, so I downloaded axis2 jar, tried it, but didn't work for sure. the packages inside are not the same at all - this wasn't my solution
4- Another one suggested it was a problem with plugin activation in eclipse... I didn't get deep into exploring this solution, It seemdd to me out of scope.
5- Another one suggested a good answer, that's instead of missing class definition, It might be rather a duplicate class definition. i.e. you are using another jar that has the same path in it, or a duplicate path for a class that your axis client needs

You noted the red statement? Yes. Although the previous point wasn't the solution, It gave me a clue. the jar might be dependent on some other resource.

6- So, As usual I went to my friend "findjar", and asked him about the jar I was using which was axis1.4, checked Its dependendies (in the "Depends On" section) I found that it was depending the following jars : 

I downloaded the missing jars, tried again and it worked a piece of cake. 

Hope it helps

NullPointerException while calling A web service with a non null soap messge

<An issue whose reason was known>

The issue that I faced was as follows:

1- I was calling a web service providing it a non null soap message.
2- I am not the one who creates the soap message, I am using a certain kind of engine (or wizard) that parses the WSDL, asks for the method that I want to call on the WS, asks for the parameters and then it creates the SOAP message on its own and sends the SOAP request.
3- The response returned was the cute "NullPointerException"
4- I asked the team responsible for handling the called Web Service to check their logs and tell me wither my request was processed or not and tell me what resulted this response.
5- They told me that the request sent was null although I was sure that the request was sent with values

The Solution strategy I followed:

1- First I used Soap UI to check that I was able to call the WS and that it was working fine, And after trying I found that it was working fine, then I realised that the problem is in the wizard that generates the soap message, either it generates nothing or generates a wrong message.
2-I used Wireshark to track the Soap message sent, In the Filter text box, I specified the port on which the WS is called, (tcp.port == 31112)

3-I started trying again and the http request appeared in the wireshark, I opened it (right click- Follow TCP stream) and took the request body copy paste to SOAP UI.

4- I tried calling the WS with that SOAP message -note in the picture, Request1 is the one generated by Soap UI, Request2 is the one I got from wireshark(the message sent actuallty)
You can note the difference in the SOAP message format, this is the cause of the error, the web service couldn't recognize this malformed SOAP message, so as  if it's null.

I used a work around to call this webservice - instead of using this wizard, I used normal java client generated from jboss JAXWS

The aim of this topic was mainly to discuss the problem symptoms, cause and the tools used for its detection more than the solution you will use since the solution depends mainly on the system you are actually using - for me I was using a wizard tool that's like an eclipse plugin, for some one else you might be able to change the format of the SOAP message or even the structure of the web service itself.

Hope it helps :)

java.net.UnknownHostException: D

You can often find this exception or something similar (UnKnownHostException : C , UnKnownHostException : E, etc ) when trying to access a file on your machine (or on  server) and the file name is wrong.
mostly the file name begins with "file://D" or "file://C" ... All you need to do is to
replace "//" with "///" 
i.e. begin the file name with "file:///D"
enjoy