In this second part of a blog series (part 1), I plan to explore the steps to develop/deploy/invoke a Web service on GlassFish using IntelliJIDEA IDE.

 

Searching in the help bundled with the IDE on "web service from Java" returned no results relevant to Web service. I found several (1,2,3) people asking "How do I develop Web service in IntelliJ 6.x?" but all the questions are unanswered. The online documentation does not seem to talk anything about Web service.Searching on intellij.org gave no results. Finally I found somelead after searching in the forums but there is no help on "Enable Web Service Support" as mentioned in the post. Another response in the forum requires you to add@javax.jws.WebService manually, pretty primitive. So I decided to ask the question (1,2) in the forum. 

After discussion in the forum I found that IntelliJ does not support creation of Web services natively but instead support it through a Web service plugin. The plugin, at the time of this writing is "0.6 build 2" with few skeptical comments but anyway worth a try. This plugin supports JWSDP 2.0 so first I'll investigate how Web services can be deployed on GlassFish and then come back to this plugin.

Here are the steps I followed to successfully build and deploy a Web service:

  1. Create a Web module (requires 12 clicks for default settings), say with name "hello". On Deployment Descriptors tab, select the default "Web Module Deployment Descriptor" and delete it as shown here. This is not required for deploying a Web service in GlassFish v2. Take all other defaults.
  2. In the "Project" pane, click on "src", add a new package "hello" as shown here.
  3. Select the package "hello", add a new class "Hello" as shown here.
  4. Click on the Project, right-click and select "Module Settings". Select the module and remove "j2ee.jar" as shown here. Add a new module library, javaee.jar, from GlassFish lib directory as shown here.
  5. Add @javax.jws.WebService annotation to the class and add a method as shown:

    @WebService
    public class Hello {
      public String sayHello(String name) {
        return "Hello " + name;
      }
    }
  6. Select "Build", "Make Project" (default shortcut Ctrl+F9).
  7. Configure and Run GlassFish v2 in IntelliJ. I added GlassFish v2 M4 using the following steps. 
    1. Select "Run", "Edit Configurations ..." menu.
    2. Click on "+" in top-left corner to add a new configuration and then select "GlassFish Server" and "Local" as shown here.
    3. Specify the location of GlassFish by clicking on "Configure" button.
    4. Select the domain (default value "domain1") in "GlassFish Server Settings".
    5. Add a new server by clicking on "+" in top-left corner and give the location where GlassFish is installed as shown here. Ignore the "There are no modules to deploy" warning as this will be fixed during Run. Now GlassFish is configured.
    6. To run the GlassFish instance 
      1. Select "Run", "Run" (default shortcut Shift+F10) menu item. 
      2. Run configuration window displays the warning message "There are no modules to deploy". Go to "Deployment" tab and selecting the newly created module to deploy as shown here .
      3. Check "Deploy Web Module" check box and click "Configure" button and select "Create web module war file". A warning is displayed "Warning: 'Glassfish Web Module Deployment Descriptor' is not defined" as shown here. This message can be ignored as no GlassFish specific deployment descriptors are required.
      4. Click "Run" button.
  8. Once the GlassFish server has started, the endpoint is hosted at http://localhost:8080/hello/HelloService?wsdl.

The key point to note here is that no Deployment Descriptors (either standard or application serve specific) are required in the WAR file. The deployed WAR file in GlassFish consists only of the compiled class. 

The only way IDEA support creation of Web service clients is through Web Services plugin so I'll explore it in another blog. So the recommended way is to use NetBeans 5.5.1 to invoke the Web service

Enjoy Web services deployed on GlassFish in IntelliJIDEA! And remember, GlassFish v2 uses Web Services Interoperability Technology (WSIT) that gives you interoperable Web services with Microsoft .NET 3.0 framework.

Technorati: NetBeans IntelliJ Eclipse GlassFish Web service WSIT