일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
This tutorial shows you how to use NetBeans IDE to expose a MySQL database as a RESTful web service endpoint. You will deploy the "sakila" sample database on GlassFish v2 using the RESTful Web Services plugin. In this tutorial, you learn to create:
Contents
To follow this tutorial, you need the following software and resources.
Software or Resource | Version Required |
---|---|
NetBeans IDE | Web & Java EE download bundle 6.1 or 6.0 Java download bundle 6.5 |
Java Development Kit (JDK) | version 6 or version 5 |
The latest stable MySQL (download). | |
The "sakila" sample MySQL database (download). | |
Java EE-compliant web or application server | Tomcat web server 6.0 and/or GlassFish application server v2 |
Both Tomcat and GlassFish can be installed, optionally, with the Web and Java EE distribution of NetBeans IDE. Alternatively, you can visit the GlassFish downloads page or the Apache Tomcat downloads page.
This tutorial also requires the RESTful Web Services plugin. In the IDE, go to the Plugin Manager, under the Tools menu, and check whether the RESTful Web Services Plugin is installed, under the Installed tab. If it is not, install it from the Available Plugins tab, as shown below:
MySQL is the world's most popular open source database software, with over 100 million copies of its software downloaded or distributed throughout its history. With superior speed, reliability, and ease of use, MySQL has become the preferred choice of corporate IT Managers because it eliminates the major problems associated with downtime, maintenance, administration and support.
The IDE supports rapid development of RESTful web services from databases, by the creation and exposure of entity classes. RESTful web services are services based on HTTP header operations. Building web services using the RESTful approach is emerging as a popular alternative to using SOAP-based technologies for deploying services on the internet, due to its lightweight nature and the ability to transmit data directly over HTTP.
To celebrate the announcement that Sun Microsystems is acquiring MySQL, Arun Gupta originally created this demonstration, showing how a MySQL database could be exposed as a RESTful web service using the IDE.
Before you use this tutorial, you should see the following:
The IDE contains the MySQL Connector/J JDBC Driver, allowing you to connect to a MySQL database. The goal of this exercise is to create that connection.
The goal of this exercise is to create a new Web Application project. This project will contain entity classes and RESTful web services.
The goal of this exercise is to generate entity classes from the sakila database.
Click Finish. The IDE creates the entity classes.
In Generating Entity Classes from a Database, you created a perstence unit. The configuration of this persistence unit is stored in the file persistence.xml. In your Projects view, you can find persistence.xml in your project, in the Configuration Files node.
You need to change this persistence file to pass the username and password. Open the XML tab. Edit the file to include toplink.jdbc.user and toplink.jdbc.password properties. It matches the following snippet (the parts you add or change are boldface):
<persistence-unit name="sakilaPU" transaction-type="JTA">
<jta-data-source>jndi/sakila</jta-data-source>
<properties>
<property name="toplink.jdbc.user" value="root"/>
<property name="toplink.jdbc.password" value="your_root_user_password"/>
</properties>
</persistence-unit>
The goal of this exercise is to generate RESTful web services from the entity classes that we generated in the previous section.
The RESTful Web Services node in the Projects window displays all the RESTful web services in your project. The value between the square brackets, such as [/films/], is the value for the URI template. You can also navigate to the source file by doubling clicking on this node. This view also displays all the HTTP methods and Sub-resource locator methods. Again, you can navigate to the methods by double clicking on the nodes.
Now that our entity classes and RESTful web services have been generated, let's test our application. The IDE provides a useful utility for testing RESTful web services. We will make use of it in the next section.
The goal of this exercise is to try out our application.
The server starts and the application is deployed.
Finally, the browser should display your application, with a link for
each of the web services:
On the left-hand side is the set of root resources. Here they are named languages and films.
You can view more entries by appending /?max=n to the URL. For example, "http://localhost:8080/sakila/resources/films/?max=40" shows the first 40 entries. Additional fields from the table can be displayed by adding getter methods to the "converter.FilmRefConverter" class, such as:
@XmlElementThe getTitle method returns the film title in addition to the fields already returned. The different columns in the table can be viewed by going to the "Services" tab and expanding the sakila database connection created earlier:
public String getTitle() {
return entity.getTitle();
}
Here are a few more ideas for you to explore:
A JRuby-on-Rails application using MySQL is explained here. TOTD #9 explains how JDBC connection pooling in GlassFish can be used for a JRuby-on-Rails application using MySQL.
The key message here is MySQL can be very easily used with GlassFish and NetBeans IDE makes it possible.
For more information about using NetBeans IDE 6.0 to develop Java EE applications, see the following resources:
To send comments and suggestions, get support, and keep informed on the latest developments on the NetBeans IDE Java EE development features, join the nbj2ee@netbeans.org mailing list.
Creating a Graphical Client for Twitter (0) | 2009.03.09 |
---|---|
Representational State Transfer (0) | 2009.03.09 |
[펌: developerWorks ] SOA 솔루션에 레거시 시스템 전략 적용하기 (한글) (0) | 2007.08.28 |
[펌] SOA 성숙도 모델 (0) | 2007.04.07 |
[펌]SOA 거버넌스 입문 (0) | 2007.03.29 |
archidream's Blog is powered by Daum