2012年2月1日水曜日

How To Create Web Service From An Ejb

how to create web service from an ejb

Create Web Services with netbeans7.0 and Glassfish 3.1

In this example I use:

- netbeans 7.0: 
- glassfish3.1: 
- postgresSQL 8.3: 
- pgAdminIII: 

Let's consider a very simple real example of a library where we define a basic model to describe the reality. There are three entities:

- author
- book
- reader

with these relations:

- an author write many books
- a book has only one author
- a book is read by many readers
- a reader read many books

so we can describe these relation as:

- author-book: one-to-many
- book-reader: many-to-many

With these rules we can  write our database:

create table author

(

id bigint not null,

cod_author varchar(10) not null,

des_author varchar(100) not null

);

create table book

(

id bigint not null,

cod_book varchar(10) not null,

des_title varchar(100) not null,

id_author bigint not null

);

create table reader

(

id bigint not null,

cod_reader varchar(10) not null,

des_reader varchar(100) not null

);

create table reader_book_ref

(

id_reader bigint not null,

id_book bigint not null

);

alter table author add primary key(id);

alter table book add primary key(id);


Lightweight Java Web Application Development: Leveraging EJB 3.0, JSF, POJO, and Seam
Learn more
Michael Juntao Yuan

alter table reader add primary key(id);

alter table reader_book_ref add primary key(id_reader, id_book);

create unique index idx_author_cod_author on author(cod_author);

create unique index idx_book_cod_book on book(cod_book);

create unique index idx_reader_cod_reader on reader(cod_reader);

alter table book add foreign key(id_author) references author(id);

alter table reader_book_ref add foreign key(id_reader) references reader(id);

alter table reader_book_ref add foreign key(id_book) references book(id);


Now follow these steps:

First Step: open pgAdminIII and connect PostgresSQL server. Then right click on Database voice of the menu and create new database called libdb. Right click on db libdb and click on "CREATE code". Put script listed above on the window and execute to build our database libdb.

Second Step: create an empty folder BiblioProject, the open netbeans IDE and click file --> New project --> JavaEE --> Enterprise Application and fill the field of the wizard as it follows:


An Introduction to IBM Rational Application Developer: A Guided Tour (Ibm Illustrated Guide Series)
Learn more
Jane Fung

click next and confirm the build of ejb module and Web App Module as follows:
and click finish.

Click on the tab services, open Database-->Divers, if you don't have Postgres Driver right click on Drivers and add new Driver as follows:

Now add connection to libdb: right click on databases and add new Connection typing information as follows: 

Test connection to verify that is all correct.

Now turn back on the tab Projects, click on EABlio-ejb module--> new --> entity classes from database --> select data source --> add new data source:

add all tables in the available tables window on selected tables windows:

and click next. in the following window type the package where insert the classes generated com.entities:

Click finish and you can see that Netbeans generate for you all entity classes of your database. In this  case in com.entities we have insert the classes Author.java, Book.java, Reader.java that include jpa annotation.

Now right click on EABiblio-ejb module and click on "New Session Bean from Entity" and add all entity classes from Available Entity classes list to Selected Entity classes list:

click next, then replace package name with com.session and check local:


When you click on finish button Netbeans generate for you alla facade netbeans that will be the interface to your database.

At the end you can create a web service that allows you insert, update or extract data from database libdb. Right click on EABliblio-ejb module and click on "New Web Service" --> type WSAuthor as name of the web service, ws.author as package and check option "Create Web Service from Existing session bean" and browse for select the Session Bean AuthorFacade:


Follow the same step to create WSBook and WSReader. Now you have created Web Service!

To test the execution of the web service right click on EABiblio Application and click on deploy: glssfish server will be started and the application will be deployed on it. At this point you can go to tab Services, open voice servers on the tree and see that glasfish is started and it contains EABiblio applications  and WSBook, WSAuthor and WSReader services.

Turn back to tab projects and open voice Web Service on the tree of the EABiblio-ejb module, right click on WSAuthor and will be opened the browser with address http://localhost:8080/WSAuthor/WSAuthor?Tester, if yuo replace WSDL instead of Tester at the end of the address, you can see the wsdl generated. If you put Tester again:



These are our most popular posts: how to create web service from an ejb

java and more more more: Webservice on EJB local, remote ...

by Author 1 under CXF, EJBs, security, WebService. Hi, JBoss AS7 provides support for Apache CXF 2.4.4, so in this demonstration we will see how to develop a Simple EJB3 Based CXF webService with Basic Authentication enabled. In this ... read more

JCHICCHE: Create Web Services with netbeans7.0 and Glassfish 3.1

First of all JDeveloper 10G is targeted to rapid web application building, utilizing all the achievements of J2EE World: web service, EJB, MVC frameworks, XML, etc. ... bi-directional code generation between UML models, EJB models, required J2EE patterns generation with one click of the button, visual web application builders and other capabilities open the doors for developer, who had never before being dreaming to create industrial-strength J2EE application! 2. read more

Procedure Pl Sql

package main.java.com.ws.service; import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.jws.WebService; import javax.xml.ws.Holder; import org.jboss.ws.annotation.SchemaValidation; @Stateless @Local( ITestWs.class) @Remote(ITestWsRemote.class) ..... Create a new ObjectFactory that can be used to create new instances of * schema derived classes for package: * main.java.com.ws.service.generatedClasses * */ ... read more

EJB based CXF WebService with Basic Authentication in JBoss AS7 ...

dalicore-ejb: contains everything related to managing the dalicore entities: User, Content, Group and Permission; dalicore-oauth: allows web applications to become an oauth service provider; dalicore-externalnetwork: allows web ... Creating an application. Allright, time to get started. We start with creating the web application that will act as our oauth service provider. Fire up NetBeans and create a new Maven Web Application project. Create a new Maven Web ... read more

Related Posts



0 コメント:

コメントを投稿