Fastest Web Service Development in the West

Well, I read through this extensive article about creating Web Services and am ready to give you an alternative approach. After I show you how I approach doing Web Service development, I will compare the two approaches.

Get Ready

You need to install GlassFish and NetBeans 5. I am using GlassFish build 32 and a nightly build of NetBeans 5 (which will be an RC any day now). Once you install these, register the GlassFish instance with NetBeans.

Implement A Service

I will create a web-app based service, just like the other author did.

So, I create a web-app.

I create a class that will implement my service.

I add the service annotations.

    package services;
    
    import javax.jws.WebMethod;
    import javax.jws.WebService;
    
    @WebService
    public class Greeting {
        @WebMethod public String sayHello(String name) {
            return "May I be of service, "+name+"?";
        }
    }
    
I change the web.xml file, so that the web app will be deployed as a Java EE 5 component, instead of a J2EE 1.4 component. To do this you just need to change the web-app element from
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
	 version="2.4">
to
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	 version="2.5">
I deploy the project.

Testing the Service

The GlassFish implementation of Java EE 5 includes the ability to test web services from within the Admin Console. Testing is just one of the features of the web service management capabilities in the Admin Console.

You can open the Admin console from within NetBeans, using the context menu of the target instance.

There are two sets of pages associated with web services. The first set provides general information about the services deployed on your instance. The other tab in the set allows you to create a catalog of registries.

The second set of pages/tabs allows you to manipulate individual services. The General tab provides all sorts of detailed information and has the Test button.

A new browser window opens when you press the Test button.

After you enter the arguments for the service, pressing the operation button provides the result and detailed informatiion about the SOAP messages exchanged between the service and the client.

Comparison of the two implementation methods

Both processes use JAX-WS 2.0 to implement a web service. Both methods deploy that service onto GlassFish. Both methods use NetBeans 5.0 as the development environment.

The method outlined in the other article stays within the boundries of what NetBeans 5.0 supports. My method goes outside that supported environment slightly, since changing the web-app element disables the web.xml multiview editor. If you need to do a lot of web.xml editing, change the web-app element LAST, so you can take advantage of the GUI editing capabilities.

The other method requires that you change the build.xml file for your web application. This is supported. The method that I outline in this entry pushes most of the "work" to the GlassFish deployment processing. This is also supported. It may be a bit less error-prone, since you won't need to remember to edit the build.xml for each SEI that is in the implementation WAR file.

Conclusion

At this point, you have a couple different strategies to implement JAX-WS 2.0 web services in NetBeans for deployment to GlassFish. Both are pretty easy to do.

You also have a couple different strategies for testing your web services.

You have seen some of the Web Service Management features exposed by the Admin Console.

Updates

Ludo pointed out a mistake in this note... If you register a project for deployment to a GlassFish domain, javaee.jar is ALREADY a library! To see it, explore the Libraries node of your web project. I have updated this note to account for that. I love it when things get easier!
Comments:

Basically the difference in the two approaches is whether the service gets deployed as a jsr109 compliant service or not. JSR109 (WebService for JavaEE) defines how a JAXRPC/JAXWS based web service can be deployed on a JavaEE platform in a portable way. The approach described by Vince in his blog results in the service being deployed as a jsr109 compliant web service wherein the WSDL gets published at a well defined location, there is no need for descriptors like sun-jaxws.xml etc.

Posted by Vijay Ramachandran on January 10, 2006 at 04:27 AM PST #

Your comment triggered a thought:

If the user follows Bobby's approach, their web service would not be "visible" in the web service management areas of the Admin Console. That seems like it would be huge.

Please correct me if I am wrong on this....

Posted by vince kraemer on January 10, 2006 at 07:58 AM PST #

You are correct - Following Bobby's appraoch would mean glassfish recognizes the deployed app as any other web application and hence web service management and monitoring features wont be available

Posted by Vijay Ramachandran on January 10, 2006 at 08:49 AM PST #

Post a Comment:
Comments are closed for this entry.
About


Vince Kraemer writes the entries in this blog.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
News
Blogroll

No bookmarks in folder

automarks