Second Thoughts about Software, Technology and Business...

Wednesday, March 19, 2008

Web Services using NetBeans 5.5 [2]

In the previous article we have created and deployed successfully a working Web service. Now we are going to build the 3 Clients that will consume this web service.

9.From the context menu of your web project select to create a new "Web Service Client". This is how the things goes in NetBeans, whatever the type of your project was to let it consume a web service you must create a web service client in this project and this is logical indeed as you must provide some information (mainly the WSDL Document path) to the client.

10. In the "New Web Service Client" dialog box, browse to your projects list to select the "sayHelloWS" web service and NetBeans will automatically figure out the WSDL path of the service. Also create a new java package for the test client - here i called it com.ws.client

11. After finishing you can see the WSDL Document retrieved for our "sayHelloWS" web service.

12. Now we would like to invoke directly the "sayHello" method in the service. Open the "index.jsp" of your web project and between the body tags right click then choose "Web Service Client Resource" then "Call Web Service Operation". As we can see NetBeans makes the whole process of developing and consuming web services so simple and straight forward.

13. Choose the only method available "sayHello". As you can see in the figure below the code was automatically generated to call the method.

The code generated is self explanatory. At the first few lines we create a new reference for the web service then obtain the port associated with it then we simply pass the correct type parameter and obtain the result then print it.
I have highlighted the name passed to the method "Java Duke" for test purpose.

14. Run the whole web project and you should see the following result.

As you can see the response of the service is printed on the screen with the correct input. Congratulations!

15. Using the Same logic we can also create a J2SE JFrame Based web service client and a J2ME MIDP 2.0 Mobile client as well. The screen shots for those 2 projects invoking the same "sayHelloWS" web service are listed below.



Well, as we saw here we could create 3 Clients invoking a backend web service in just 15 steps. Although the example presented here maybe simple but it is rather a good start for developing Web Services based applications.

Hope you liked this short tutorial :)

Web Services using NetBeans 5.5 [1]

In this article i am going to explain step by step how to use Netbeans IDE v5.5 to create a simple Web Service replying with a Hello String + the name parameter passed to it along with 3 Web Service Clients invoking it: A Web Client (JSP Page), a Desktop Client (JFrame) and a Mobile Client (MIDLET). The following projects use JAX-WS and the latest Web Services technologies.

1. Launch NetBeans IDE and Create a new Project from type "Web Application".
We are going to call our project "sayHelloWS" and choose Tomcat v5.5.17 as our deployment server. Be careful to uncheck the Set Source Level to 1.4 option for compatibility reasons while working with Web Services.

2. From the context menu of our new just created web project select to create a new "Web Service".

3.In the "New Web Service" Dialog Box, type the service name "sayHelloWS" and specify a Java package that will contain the service source files. Let us call it for instance com.ws.hello

4. After Pressing the "Finish" button in the later screen, NetBeans will create for you all the source files and configurations needed. Notice the annotation "@WebService()" just above the web service class.
We need now to add a simple function to our web service to let it do an action. Right click on the service name in the "Web Services" folder from the Projects Explorer then choose "Add Operation".

5. We are going to call the method "sayHello" with return type "String" and with one only parameter called "name" from type "String" as well.

6. In the figure below you'll notice that the new method has been added - also with the annotations @WebMethod and @WebParam - to our web service class. Just modify the return line to return a meaningful string such as the word "Hello" concatenated with the name passed to the method. In fact this is all what our web service will be able to do.

7. Run & Deploy the web project. Then right click on the web service "sayHelloWS" then choose "Test Web Service".

8. The default browser should launch then on the web services page of your web project and you are supposed to see something like that.


In the above screen you'll notice that our "sayHelloWS" web service is listed with "ACTIVE" status along with the service information such as the address,WSDL document,port and implementation class.
If you reached this point then you have successfully created and deployed your first web service and you are ready to build the 3 clients that invoke this great web service!

Tune in till next episode..

Dojo Framework

I am going here to present briefly what is Dojo Framework and what you can actually do with it when it comes to professional Web Development. According to Dojo's Web Site:

"Dojo is an Open Source DHTML toolkit written in JavaScript. It builds on several contributed code bases (nWidgets, Burstlib, f(m)), which is why we refer to it sometimes as a "unified" toolkit. Dojo aims to solve some long-standing historical problems with DHTML which prevented mass adoption of dynamic web application development.

Dojo allows you to easily build dynamic capabilities into web pages and any other environment that supports JavaScript sanely. You can use the components that Dojo provides to make your web sites more usable, responsive, and functional. With Dojo you can build degradable user interfaces more easily, prototype interactive widgets quickly, and animate transitions. You can use the lower-level APIs and compatibility layers from Dojo to write portable JavaScript and simplify complex scripts. Dojo's event system, I/O APIs, and generic language enhancement form the basis of a powerful programming environment. You can use the Dojo build tools to write command-line unit-tests for your JavaScript code. The Dojo build process helps you optimize your JavaScript for deployment by grouping sets of files together and reuse those groups through "profiles".



In more simple words, Dojo allows you to create professional DHTML & JavaScript UI Components in easy way. To feel more about what Dojo can do, I recommend you to take a look at the Demos Page.
There are really very exciting features such as the FishEye Widget which is something like rendering the main toolbar in Apple's Mac OS Desktop but inside the browser!

So what you have to do in order to start playing with Dojo. First, download Dojo's Toolkit from the main web site. Second, Extract the downloaded archive into a test folder called for example "dojo" inside a "js" folder which in turn is in the root demo folder called for example "DojoTest". Third, Create a normal HTML file with the code in the image below and name it "index.html".

I assume that the code in the screenshot is self explanatory. It just import the desired dojo's libraries on Loading and then demonstrates how to create a button widget and associate an event with it.If you have a basic knowledge of JavaScript, then you should not find any difficulty with this simple example.

dojoSampleCode


The good news is that as you see till now, there is no server side code in the HTML page which means that we do not need a web server to run our example, just browse the page. Of course this is not the case always in real applications as you should integrate Dojo with PHP or JSP or any server side scripting language.

Where to go from here? The best place to go to now is to read Dojo's Developer Book. It contains very clear and easy explanation on every detail about this wonderful framework with samples on nearly everything.

Thursday, March 6, 2008

First Cup of Second Cup.

Welcome to my humble own space on the web. This is where I am going to post ideas about Software, technology and any new fascinating trend. I am committed to a clear and neat writing style to let you truly benefit from reading posts here.

Farewell,