Home > SOA Tips > The Web Services Advisor > Using the NetBeans IDE for RESTful Web Services
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

THE WEB SERVICES ADVISOR

Using the NetBeans IDE for RESTful Web Services


William Brogden
03.04.2008
Rating: -3.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


The integrated development environment landscape is dominated by two open source offerings, NetBeans and Eclipse. Today we will look at how one of them, NetBeans, is offering support for RESTful Web services.

NetBeans stems from a commercial IDE company purchased by Sun Microsystems and released as open-source in 2000. NetBeans is written in Java, giving it a very wide user base. Like Eclipse, NetBeans has a multitude of add-on modules with support for many languages and design techniques. NetBeans provides support for many of Sun's favorite technologies including the Glassfish open-source Java EE 5 application server. Although the server is the core of the Glassfish development community, there are many projects which have an independent existence. Some projects are definitely on the cutting edge of Web service technology. One of these is an implementation of JAX-RS, the Java API for RESTful Web Services or JSR 311, called Jersey. I was delighted to discover that the Jersey implementation has progressed to the point that it is a plug-in addition for the latest NetBeans, version 6.0, released in December 2007.

Installing NetBeans

I downloaded and installed NetBeans 6.0 - this is a rather large package in spite of the fact that it comes with only a minimum set of plug-ins. The plug-in manager function provides an elegant system for keeping up with updates and for picking the plug-ins you need. The installation includes the Glassfish server and the installation will detect other servers in your system. NOTE - although NetBeans works with Java JDK 5, upgrading to JDK 6 before installing NetBean...


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
The Web Services Advisor
What to expect with the new JavaScript standardization (ECMAScript 5)
Restlet framework wrestles RESTful Web applications
3 tips for choosing whether to use EGL
Use SoaML to facilitate Model Driven Architecture
Enterprise mashup patterns act as API enablers
XQuery learns to write using XUF
Descriptive Languages for RESTful Services
Notable Python language update on view
Try XML-based Extensible Business Reporting Language (XBRL) for accounting reports
Whatever happened to ''X''?

Representational State Transfer (REST)
Restlet framework wrestles RESTful Web applications
Mulesoft architect talks REST, ESBs
How do I balance throughput requirements and interoperability?
IBM Sabbah's say on REST for collaborative ALM
Report on REST- REpresentational State Transfer
Are tools available to work with OSGi today?
Expert Query: What is the difference between RESTful transactions and Web Services transactions?
Progress/Actional SOA diagnostic tool builds on Mindreef purchase
SOA goes beyond 'rip, replace, repeat'
Inside the SOA big tent; Azure at PDC; more

Java Web Services
Tools add Web services to existing Java EE applications
Video: Author says Enterprise JavaBeans is here to stay
Languages like F# may replace Java, says Ted Neward
Mobile development growing in prominence according to survey
OSGi framework helps you manage Java components
SpringSource moves VMware up the stack
SpringSource gains cloud console: Q&A with Cloud Foundry head
Adopting OSGi requires patience and money, but development flexibility results
Speed up application deployment with automated blackbox frameworks
Java Servlet API 3.0 improves application plugability

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
REST  (SearchSOA.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


s would be a great idea.

Adding RESTful Web service support

Updates to NetBeans and adding new functions is handled by the plug-in manager which connects to the central repository. I added the plug-in named "RESTful Web Services" and also updated several other modules. This plug-in is considered a beta version, corresponding to the Jersey version 0.5.1, so it is still in early stages of development.

I created a new RESTful Web Service project in NetBeans by following the Jersey example cited in the Web resources below. This mainly involved filling in the name that will appear in URIs, Java package name and class name. The purpose of this service is to examine an input word and return a list of words that sound similar based on the Metaphone phonetic coding algorithm. I specified that the URI path to this resource will be "lookup."

The JAX-RS specification always uses the word "resource" to emphasize the REST style of thinking about a service, as opposed to the SOAP and JAX-RPC style of thinking about services as activating a named procedure. The Java code the IDE created from the RESTful pattern uses this convention in creating skeleton code for the "LookupResource" class as seen below. Each request causes creation of a new instance of LookupResource. The "@Path" annotation tells the Jersey runtime servlet to map "lookup" in a URI to this service class. The "@HttpContext" annotation causes the runtime servlet to automatically "inject" a UriInfo object reference which carries all of the request URI information when an instance of LookupResource is created.

In the following Java code I have left the comment generated by NetBeans in creating the code skeleton. The "@GET" and "@ProduceMime" annotations tell the framework that this method can handle HTTP GET requests and return a HTML formatted String. Naturally it is up to the programmer to write the internal details of such methods. This example shows my first step, verifying that the query parameter value can be extracted from the UriInfo object.

The "@ProduceMime" annotation is used to locate the resource provider that is the closest match to the type specified in the request. Using the NetBeans "run" command for this project started my Tomcat server. Startup messages from Tomcat showed that when the framework servlet started, it searched for implementing classes. Sending my browser to the following URI:

Generated the expected text "Match String word" response, verifying that the framework was able to locate my service class, create an instance, and call the getHtml() method when the URI uses the query formatting style. However, further experimentation revealed that I could not get the system to recognize a URI that used the REST hierarchical style instead of query style formatting. The following URI should pass the "someword" text to the lookup resource, but Tomcat reported an error.

There are plenty of examples of support for the hierarchical style in the stand-alone version of the Jersey download so it looks like I still have some work to do to figure out how to get the NetBeans plug-in to do the same.

Netbeans provides plenty of support for programming and debugging. For example, when editing the getHtml() method code, the editor showed me all of the methods that the "context" object supports. A great feature for Web related programming is the ability to record the complete HTTP request and response text.


Rate this Tip
To rate tips, you must be a member of SearchSOA.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



SOA Trends and Strategy - SOA Education, SOA Development, SOA Implementations
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2001 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts