DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. NetBeans in the Classroom: Teaching RESTful Web Services

NetBeans in the Classroom: Teaching RESTful Web Services

Ken Fogel user avatar by
Ken Fogel
·
Jun. 08, 14 · Interview
Like (0)
Save
Tweet
Share
24.75K Views

Join the DZone community and get the full member experience.

Join For Free
ken fogel is the program coordinator and chairperson of the computer science technology program at dawson college in montreal, canada. he is also a program consultant to and part-time instructor in the computer institute of concordia university 's school of extended learning. he blogs at omniprogrammer.com and tweets @omniprof . his regular columns about netbeans in education are listed here .

in preparing for a second class i am about to give on restful web services, i decided to show my students the netbeans wizard " restful web services from database" . there is a tutorial on this called getting started with restful web services at this location:

https://netbeans.org/kb/docs/websvc/rest.html

i started up netbeans ide 8.0 and proceeded to follow the instructions.

first, here is my working environment:

  • windows 8.1

  • java 8

  • glassfish 4

  • mysql 5.6

  • netbeans 8

the first thing the tutorial instructs you to do is to create a java web – web application.

after creating the project you need to create the entity and web services class using the restful web services from database wizard.


the next screen requires you to select the data source. the tutorial assumes that you have a mysql database called ‘sample’ not to be confused with the derby database called ‘sample’. i did not have this database but my plan was to use a database that i had used in previous courses called ‘aquarium’. this is a single table database listing details about fish for aquariums.

i already had a netbeans connection to this database so i followed the tutorial but used my aquarium database instead of samples.



so far so good. with the data source created, i was able to select the single table called ‘fish’. on the next dialog i entered a package name. a quick tip, always place entity classes in packages that have as the last name ‘entities’. another tip, on the last dialog you are presented with the package name for the services. in my case it wanted ‘com.kenfogel.entities.service’ that i shortened to ‘com.kenfogel.service’. i clicked on finish.


the wizard proceeds to generate all the entity classes and the restful classes. very cool. without writing a single line of code this is what i had.


the next step in the tutorial is about testing the web service. you need to create another java web – web application project. once created you select your original project and right mouse click to reveal test restful web service . the configure rest test client dialog appears and you are told to select web test client in project . browse to your new project and the dialog should look something like:


at this point it started to go wrong. clicking ok results in a number of files being added to the webservicestest project. glassfish is started and the browser opens here:

http://localhost:8080/gfrestservice/test-resbeans.html

...and presents a 404 error. the problem is that this page is really at this location:

http://localhost:8080/webservicestest/test-resbeans.html

correcting the url in the browser gives you:


returning to netbeans i looked at the glassfish server 4 output window. there was a stack trace. quite a long stack trace. after reviewing the trace i zeroed in on the following message:

severe: exception while preparing the app : invalid resource : jdbc/aquarium__pm

well now i’m stymied. i followed the tutorial almost exactly except for using my database. when the web services application deployed it rejected the database resource. more confusing is that it rejected a resource with a different name. mine was called jdbc/aquarium but the error called it aquarium__pm.

when i started out as a freelance programmer i used to add as much as a thousand dollars to my job estimates to cover the cost of books i was going to need to learn what i just told a client i could do. today all you have to do fire up your favourite search engine and you are awash in thousands of links. in this case i discovered that other programmers had encountered a similar problem. the solution, i learned after a few false starts, was to register a resource and a pool directly in glassfish. i found a tutorial titled ‘how to setup a jdbc connection in glassfish’ at this location:

http://computingat40s.wordpress.com/how-to-setup-a-jdbc-connection-in-glassfish/ .

i followed the instructions and found that the jndi name i used in glassfish now appeared in the list of available data sources when i ran the restful web services from database wizard in netbeans. but when i chose the name an error message appeared in netbeans.


some people had left comments on this tutorial about this error. the author’s response was that he did not use netbeans and since it worked for him it was a problem with netbeans. so back to the search engine,

here i discovered that indeed some people reported this problem as a bug in netbeans. you can see the bug report at this location:

https://netbeans.org/bugzilla/show_bug.cgi?id=238667

well, it appears to me that there is no bug. the last person to comment (ahead of the comment i just added) had the solution. you just have to add a property to the glassfish jdbc connection pool called ‘driverclass’ and give it the value of ‘com.mysql.jdbc.driver‘. not a bug but a failure in the documentation.

here are the properties if your jdbc connection pool is using java.sql.driver for the resource type.


if you plan to use the one of the other choices you will have to make similar changes. for example, if you use java.sql.datasource there are 214 properties. going through this list you will see where to put the url, user and password. the datasource is not required because it is already a property.

in working through this problem i recreated the work every time i thought i found a solution. i must have created the web projects at least two dozen times. the end result is a repeatable solution in the environment i use. in the end this is what the test should look like if you choose the url for count.


if you are interested in the related powerpoint presentation, see the slidedeck below. the presentation, 16 slides, goes step by step on how to configure glassfish for a mysql jdbc connection pool and jdbc resource.

cejv659 week09 glassfish-s14 from ken fogel
Web Service NetBeans Database REST Web Protocols Classroom (Apple)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Top 5 Node.js REST API Frameworks
  • Why Every Fintech Company Needs DevOps
  • Spring Cloud: How To Deal With Microservice Configuration (Part 1)
  • Using the PostgreSQL Pager With MariaDB Xpand

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: