20 April 2010

Deploying custom web services in an OpenCMS container using Axis 1.2

This short manual describes how to generate an Axis 1.2 web service based on a WSDL file and then integrate it into OpenCMS (probably as part of a larger module). Unfortunately the process is not fully automated as the modification to the web.xml file that is required needs to be done manually. All other files could be generated preliminary and deployed with a custom module (the server-config.wsdd file, the web service code, Axis libraries etc.)

Although all the required information was quite hard to gather the actual steps are really very easy.

Generating our web service

I would not go into detail – the Axis 1.2 manual describes the process here

Modifying the OpenCMS web.xml file

This would be our first step. We can’t really avoid this, and I am not sure if it could be done automatically (for instance if we wanted our own module to set up AXIS). I didn’t have much time to research this so I just went with the manual update. All we need is to add these lines and restart the server (assuming that our module deployed the required axis libraries in the WEB-INF/lib directory):



AxisServlet
Apache-Axis Servlet
org.apache.axis.transport.http.AxisServlet



AxisServlet
/services/*




wsdl
text/xml



xsd
text/xml



Creating the server-config.wsdd file

The default file is something like:

xmlns:java="http://xml.apache.org/axis/wsdd/providers/java";>















We only need to put the contents of our deploy.wsdd file (generated in step 1) in the place of the “HelloWorldService” service element.
We than place the server-config.wsdd file in the WEB-INF/ directory (alongside the web.xml of the OpenCMS application).

Voila!

To access the service we need to visit http://localhost:8080/opencms/services/ HelloWorldService?wsdl, assuming our web service name is set to HelloWorldService

Testing basic Java skils [Q2]

Taken without any changes from Paul Szulc's Blog

I won’t be doing long introductions, let’s just jump right into the code. Check those two classes below:

public class Foo
{
public int a;

public Foo()
{
a = 0;
}

public void add()
{
a = a + 10;
}

}

public class Bar extends Foo
{
public int a;

public Bar()
{
a = 2;
}

@Override
public void add()
{
a = a + 5;
}
}

Looks normal, right? Class Bar overrides method add from Foo class, additionally it initialize a variable in constructor. So the question remains, what will following code print on the output when run:

public static void main(String[] args)
{
Foo f = new Bar();
f.add();
System.out.println("a = " + f.a);
}

To make this task easier, I give you 5 possible answers. Only one is correct:

A) a = -2
B) a = 0
C) a = 5
D) a = 7
E) a = 12

And the correct answer is…

B) a = 0

You might say “What!? Anything not 0! I mean I made addition operation at least once. Or have I…”. Well you are right, you made addition operation, but you were adding value to different variable then you thought you were. The devil is in the details. When you create again ‘a’ field in class Bar

public class Bar extends Foo
{
public int a;

...

you hide ‘a’ field from Foo class. In Bar class we have actually two ‘a’ fields, but we can only access one: the one that was declared last. In other words we loose access to ‘a’ field declared in Foo class. Now everything should become clear. In Bar constructor we initialize the other ‘a’ field with value 2, then we add 5 to it and so it finally equals 7. But when we are printing the output

System.out.println("a = " + f.a);

we are actually printing the hidden ‘a’ field from the Foo class. Tricky, ain’t it?

The problem lies in the ‘public’ access level of the ‘a’ field. It is almost never good idea declaring your fields as public (beside rare occasions like inner classes\). Also try not to name fields in your child classes with names from the parent class.

15 April 2010

And some engineering humor

Optimist: The glass is half full.
Pessimist: The glass is half empty.
Engineer: Why is the glass twice as large as it needs to be?

08 April 2010

Some management humor

A man flying in a hot air balloon suddenly realizes he’s lost. He reduces height and spots a man down below. He lowers the balloon further and shouts to get directions, "Excuse me, can you tell me where I am?"

The man below says: "Yes. You're in a hot air balloon, hovering 30 feet above this field."

"You must work in Information Technology," says the balloonist.

"I do" replies the man. "How did you know?"

"Well," says the balloonist, "everything you have told me is technically correct, but It's of no use to anyone."

The man below replies, "You must work in management."

"I do," replies the balloonist, "But how'd you know?"

"Well", says the man, "you don’t know where you are, or where you’re going, you expect me to be able to help. You’re in the same position you were before we met, but now it’s my fault."

---

Some more here http://stackoverflow.com/questions/234075/what-is-your-best-programmer-joke