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 NetBeans 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.

@Path("lookup")
public class LookupResource {
    @HttpContext
    private UriInfo context;
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.

   /**
     * Retrieves representation of an instance of com.wbrogden.phonetic.LookupResource
     * @return an instance of java.lang.String
     */
    @GET
    @ProduceMime("text/html")
    public String getHtml() {
        // the context contains all query information
        String word = context.getQueryParameters().getFirst("match") ;
        return "Match String " + word ;
    }

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:

http://localhost:8080/MetaPhone1/resources/lookup?match=word

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.

http://localhost:8080/MetaPhone1/resources/lookup/someword 

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.




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


RELATED CONTENT
The Web Services Advisor
XMPP-Extensible Messaging and Presence Protocol: SOAP and REST get closer company
Find your server in the Cloud
Erlang and concurrency in service-orientated architectures
Backup to the compute cloud
SPARQL shines as RDF's query language
Testing Web services: Unit testing and monitoring
Web services for Windows CE
Testing Web services and RIAs
The problem with IT project management
Web services with Open and Microsoft Office

Representational State Transfer (REST)
User combines open source ESB with data services to speed customer reports
Microsoft modeling strategy: Work in progress
Microsoft previews new Dublin composite app platform for SOA
WSO2 supports PHP during 'growth spurt' driven by SOA
REST architecture integrates data services to SaaS
SOA policy in a box
SOA ends era of big apps, opens door for Ruby on Rails
Where Ruby on Rails fits into SOA
SOA for pets uses REST and SOAP
REST with Axis, Struts, ColdFusion and WCF

Java Web Services
Verizon uses BPEL app to cut down on code, check for fraud, and go green
Visual orchestration tool addresses event processing and SOA
Adobe Integrated Runtime (AIR) melds with ColdFusion - builds calendaring system for child services agency
Oracle re-brands BEA WebLogic as its strategic server for SOA
Ajax and Flex try to co-exist inside RIA development
BEA gives Oracle new Java platform, Eclipse tools
Where Ruby on Rails fits into SOA
Sun Java CAPS chugs down SOA open source track
JavaOne: JBoss on SOA middleware, Java EE and data services
Open source software requires governance, Burton warns

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

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.

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




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