Over a million developers have joined DZone.

Integrate a Web Service into NetBeans RCP... without Coding a Single Line

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

Let's integrate the Shakespeare Search web service into a NetBeans RCP application. The point is to show the general process for doing so and also how trivial it all is.

  1. Get the Right NetBeans IDE Distro. Make sure you have the "Java Web" or "All" distribution of NetBeans IDE because the tools described in the next steps are not found in the basic "Java SE" distribution.

  2. Register the Web Service in the IDE. You'll see that this step will prove to be very useful because once a web service is registered, you can use "drag and drop" to generate all the messy web service connectivy code. So, in the Services window (Ctrl-5), right-click the Web Services node and you'll see this:


    You'll see this when you choose "Add Web Service..." above and you then enter the URL to the WSDL defining the web service:


    Click OK and your web service is registered, with nodes for all the methods defined in the WSDL:


  3. Use the Web Service in an Application. Now let's connect to the web service from our own application. In this case, for purposes of this example, I have taken the NetBeans RCP Paint Application from the New Project dialog. I've added a TopComponent and then used the Palette to drag and drop a JLabel, a JTextField, a JTextArea, and a JButton, with this result:


    Switch back to the IDE and select the Search button you created in the Matisse GUI Builder:


    Double-click the button and you're automatically switched into the Source Editor, within the action performed method of the button:


    Now, here's the really cool part! Select a method, as shown above, in the Services window and then drag it into the action performed method in the Source Editor. Then this dialog pops up, with a list of input parameters, that you can fill in as you like:


    Click OK and the snippet below is created. I only changed the code slightly, i.e., I added "jTextField.getText()" and I added "jTextArea.setText()", then I removed all the fully-qualified bits of code, with the result below being how I've left it:


    Look in the Files window and your module will suddenly have (thanks to the drop above) a new JAR containing the web service connectivity code, as well as new entries in the "project.xml" of the module, for putting the JAR on the classpath of the module:


  4. Run the application. Now when you run the application, you'll be able to enter a phrase in the text field, click the button, and you'll see your payload returned from the web service (which you can parse to clean it up a bit):


And that's all. Your NetBeans RCP application is now able to retrieve content from a web service, without you having typed a single line of code.


The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}