Posts

Showing posts from October, 2008

Bad Unmarshalling of a CXF object which results in a null object

The story in short: I have a webservice which gathers some information from my DB, creates an object containing the info, then sends it to my client. Sounds like a simple CXF webservice scene? Well, for the last two days i'm fighting it; why? Cause my client gets only a nullified object, it's quite frustrating... So i caused some logs to appear and discovered that - The SOAP message actually contains the whole Object. My client just can't build it (Unmarshal it) into the object it's supposed to be. So, whose fault is it and how do I fix it? Aegis' binding is my guess (not that it helps much), so that's the road i'm taking. What did I find (OK, what did my boss find?) ? Here are some interesting things that I learned in the process of getting the Peering WS client to connect up with the Peering WS: The basic mechanism for serializing and deserializing the data of a web service is the databinding implementation.  I’ve been using Aegis, which is described ...

JUnit 4 Template Class

Each time I want to create a JUnit test class, I take a look at an older one, copy it, then remove all of the specifics of the previous tests. That isn't a good practice  :-) So I've decided to do it once more, in order to create a template - a working JUnit class which doesn't do anything, just add your specific code you want to test and run along: package org.chaiavi.TestJunit; import java.io.IOException; import org.junit.*; import static org.junit.Assert.*; public class TestJunit{ /** Use this method for all of the lines of code you want to run before the whole JUnit Class. */ @BeforeClass     public static void unitSetup() throws Exception { } /** Use this method for all of the lines of code you want to run after the whole JUnit Class. */ @AfterClass     public static void unitCleanup() throws Exception {     }  /** Use this method for all of the lines of code you want to run before each JUnit test. */ @Before     public void methodSetup() throws Exception ...

Master of Magic - Game Remake

Do you remember this game? I used to play it for days over days - really loved it. So, for the sake of nostalgy I decided to search for the game in order to play it, to no avail, the game works only on a dos machine. So i've tried playing it using a good DOS emulator: DosBox, but it didn't go well. I searched harder and found a new version of Master of Magic which works on XP. So, if you are suckers to nostalgy, And if you have some spare time, Give it a try. The game can be downloaded from here: First part  , Second Part  . The dos game is abandonware thus freeware, The XP version is also freeware from Implode's site. Enjoy, Chaiavi.

How do you know that your Unit tests cover all of your code? use a good Code Coverage tool

Unit Tests and Code Coverage Unit Tests In computer programming, unit testing is a procedure used to validate that individual units of source code are working properly. A unit is the smallest testable part of an application. In procedural programming a unit may be an individual program, function, procedure, etc., while in object-oriented programming, the smallest unit is a method; which may belong to a base/super class, abstract class or derived/child class. Ideally, each test case is independent from the others; mock objects and test harnesses can be used to assist testing a module in isolation. Unit testing is typically done by developers and not by end-users. (Taken from WikiPedia) Code Coverage The Unit tests are a good measure of testing, but how much of the code is being covered? Did the unit test check all of the paths of the code flow? These are the issues the Code coverage helps us solve. The Code Coverage Tools run the Unit Tests we created and tell us explicitly how much cod...

Did you try parsing a number residing in a String and an exception occured when that number was 8 or 9?

Parsing String numbers When parsing numbers residing in Strings one should pay attention to the parsing method. There are several parsing methods in the Integer Class, and not all of them parse the numbers in a Decimal (Base 10) order. For example if you'll try running the following line of code - an exception will be thrown: Integer i = Integer.decode("09"); The exception will be thrown due to the simple fact that there is no numeric character 09 when you use an Octalic counting base (Which is the decode method's default). Try using a different method for a Decimal based number. So, in order to correct our specific example we should use: Integer i = Integer.parseInt("09");

Do you wish you could debug with your local Eclipse a Java program running on an other machine ... remotely?

Remote Debugging The General debug flow. In order to debug with your Eclipse a Java program that runs on an other machine, you will need to configure two components, one in the remote machine (Where the Java program runs) and the second is a local configuration addition to your Eclipse IDE. The Remote machine will run the Java program using a special command line argument which will tell the JVM that an external debugger will connect to it and how it will connect to it (Connection type, Port etc). The Local Machine which runs Eclipse should use a special debugging mode, configured to connect to the remote Java program. The Explicit configurations. Configuring the Remote Java program. When running the program just add these command line arguments after the "java" command before the "-jar" argument (For more detailed information about these arguments - read the article which it's link is attached below): -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,suspend=n...

Do you want your Log4J to send you emails with notifications?

Log4j.SMTPAppender Include the following files in the Component’s Classpath:   mail.jar   and   activation.jar . This appender’s trigger for sending an alert email is ERROR or FATAL. Lesser logs cannot be a trigger to send an email although they can be cached to be sent later on (bundled with a trigger level) when an ERROR / FATAL log occurs. In order to enable lesser than ERROR level logs, two arguments should be defined:   BufferSize   and   threshold . For an   XML   file use the following lines: <appender name="mail" class="org.apache.log4j.net.SMTPAppender"> <param name="SMTPHost" value="172.16.100.3" /> <param name="From" value="ChaiAvi@Chaiware.googlepages.com" /> <param name="To" value="Chaiavi@Chaiware.googlepages.com" /> <param name="Subject" value="[LOG] ..." /> <param name="BufferSize" value="2" /> <param name=...

Does your Application stall for several seconds (or more)?

Garbage Collection If you have a Java app that handles large volumes of data but your app hangs randomly for several seconds (or even minutes), a good call will be a wrong configuration of Java's Garbage Collection. What can be done? First of all lets get some of the garbage collector's  logs . In order to see the GC's logging (Stdout) details, use these command line parameters: -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps Eg: java -jar -verbose:gc -XX:+PrintGCTimeStamps java_app.jar Now to the actual garbage collecting. Apparently Java 1.5 has three different  fixed garbage collection modes . The fixed garbage collection modes are: -XX:+UseConcMarkSweepGC -XX:+UseParallelGC -XX:ParallelGCThreads= -XX:+UseTrainGC Eg: java -jar -verbose:gc -XX:+PrintGCTimeStamps -XX:+UseParallelGC java_app.jar If you find the fixed garbage collection modes not satisfying enough, you can configure the garbage collector manually with several additional command line parameters, use th...

WARNING: Can't find the the request for http://127.0.0.1:8080/... 's Observer

When did this stackTrace been thrown? While running a CXF webservice over a tomcat server. Scenario: My client (client software) tries to connect the CXF webservice, but the following line keeps being stacked at my server's console windows: WARNING: Can't find the the request for http://127.0.0.1:8080/... 's Observer What's the problem? After thorough investigation I tried invoking a services list using my web browser - And a list I got! Where I found out that I wrote the wrong endpoint Mystery solved :-)