1 / 25

DALILA BURHAN 142568 NAZIRAH SHARIFUDDIN 142554

ENTERPRISE JAVABEANS (EJB). DALILA BURHAN 142568 NAZIRAH SHARIFUDDIN 142554. Introduction.

kynan
Download Presentation

DALILA BURHAN 142568 NAZIRAH SHARIFUDDIN 142554

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ENTERPRISE JAVABEANS (EJB) DALILA BURHAN 142568NAZIRAH SHARIFUDDIN 142554

  2. Introduction • The Enterprise JavaBeans architecture is a component architecture for the development and deployment of component-based distributed business applications. Applications written using the Enterprise JavaBeans architecture are scalable, transactional, and multi-user secure. These applications may be written once, and then deployed on any server platform that supports the Enterprise JavaBeans specification.

  3. Context: Three-tier Architectures First Tier Middle Tier Third Tier Presentation Business Logic Backend Database Database

  4. Implementing Distributed Objects using Stubs and Skeletons Client Server 2. Communicate method invoked SKELETON 1. Client invokes a method Object Server STUB NETWORK 3. Invoke on server 5. Return result 4. Communicate return value Distributed object architectures are based on a network communication layer. Essentially, there are three parts to this architecture: the object server, the skeleton, and the stub. The object server is the business object that resides on the middle tier. The stub and the skeleton are responsible for making the object server, which lives on the middle tier, look like if it is running locally on the client machine. This is accomplished through some kind of remote method invocation protocol. The stub acts as the object server’s surrogate on the client. This means from the outside that the stub must look like the Object server which means the stub implements the same interface. However it doesn’t contain any business logic, it only implements the networking operations that are required to forward the request to the object server and receive the results.

  5. Different Types Within Business Logic Stateless Stateful A bean implements business logic: Business process SessionBean Business data EntityBean Remote Interface Home Interface Primary Key Entity bean might represent a customer, a piece of equipment, an item in inventory, or even a place. In othter words, entity beans model real-world objects; these objects are usually persistent records in some kind of database. Session beans are an extension of the client application and are responsible for managing processes or tasks (making a reservation, …). A session bean doesn’t represent something in a database. Obviously, session beans have lots of side effects on the database. The remote interface for an enterprise bean defines the bean’s business methods: the methods a bean presents to the outside world to do its work. The methods in this interface can be used by the client and the methods are implemented by the bean class. The home interface defines the bean’s life cycle methods: methods for creating new beans, removing beans and finding beans

  6. Message Driven Beans • Message listener interface that act in the business interface • No requirement to implement on other interface • can process JMS messages or other kinds of messages. • Message-driven beans have the following characteristics: • They execute upon receipt of a single client message. • They are invoked asynchronously. • They do not represent directly shared data in the database, but they can access and update this data. • They can be transaction-aware. • They are stateless.

  7. Enterprise JavaBeans Architecture EJB Server Client Client code EJB Container EJB home Home interface EJB object Remote interface Bean class Red: define your self Yellow: automatically generated

  8. Bean Deployment • Beans are deployed using JAR (Java ARchive) files. JAR file Class files Deployment descriptor

  9. Resource Management Session beans reduce network traffic and thin down clients • Client using only Entity beans • Logic is in client • Clients does lots of small updates on entity beans • Client using Session beans • Logic is in the session beans • Client only gives small number of commands to Session beans EJB SERVER

  10. Conclusion EJB is About Hiding • EJB hides a lot of things for the developer. Such that the developer can focus on the business logic of the application. • EJB hides: • Distribution of objects • Resource Management • Transactions • Security • Concurrency

  11. Sun Java System Application Server 9.1 • targeted as the build and runtime environment . • to build, deploy, and run the program

  12. Starting and Stopping the Application Server To start the Application Server asadmin start-domain --verbose domain1 • When completed : Domain domain1 started. To stop the Application Server asadmin stop-domain domain1 • When the server has stopped : Domain domain1 stopped.

  13. Starting the Admin Console • To administer the Application Server and manage users, resources, and Java EE applications • The Application Server must be running before invoke the Admin Console. • To start, open a browser at http://localhost:4848/asadmin/

  14. Starting and Stopping the Java DB Database Server • The App Server includes Java Database Server • To start : asadmin start-database • To stop asadmin stop-database

  15. Building Using NetBeans IDE • Register your Application Server installation as a NetBeans Server Instance : • Select Tools→Server Manager to open the Server Manager dialog. • Click Add Server. • Under Platform Location, enter the location of your Application Server installation. • Select Register Local Default Domain and click Next. • Under Admin Username and Admin Password, enter the admin name and password created when you installed the Application Server. • Click Finish.

  16. Getting Started with Enterprise Beans • The purpose of converter is to calculate currency conversions between Japanese yen and Eurodollars. • Create the enterprise bean: ConverterBean. • Create the application client: ConverterClient. • Create the web client in converter-war. • Deploy converter onto the server. • Run the application client. • Using a browser, run the web client.

  17. Coding the Business Interface package com.sun.tutorial.javaee.ejb;  import java.math.BigDecimal; import javax.ejb.Remote;  @Remote public interface Converter { public BigDecimaldollarToYen(BigDecimal dollars); public BigDecimalyenToEuro(BigDecimal yen); }

  18. Coding the Enterprise Bean Class package com.sun.tutorial.javaee.ejb; import java.math.BigDecimal; import javax.ejb.*; @Stateless public class ConverterBean implements Converter { private BigDecimalyenRate = new BigDecimal("115.3100"); private BigDecimaleuroRate = new BigDecimal("0.0071"); public BigDecimaldollarToYen(BigDecimal dollars) { BigDecimal result = dollars.multiply(yenRate); return result.setScale(2, BigDecimal.ROUND_UP);} public BigDecimalyenToEuro(BigDecimal yen) { BigDecimal result = yen.multiply(euroRate); return result.setScale(2, BigDecimal.ROUND_UP);} }

  19. Compiling and Packaging in NetBeans IDE • In NetBeans IDE, select File→OpenProject. • In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/ejb/. • Select the converter folder. • Select the Open as Main Project and Open Required Projects check boxes. • Click Open Project. • In the Projects tab, right-click the converter project and select Build. You will see the output in the Output tab.

  20. Creating Application Client public void doConversion() { try { BigDecimal param = new BigDecimal("100.00"); BigDecimal yenAmount = converter.dollarToYen(param);  System.out.println("$" + param + " is " + yenAmount + " Yen."); BigDecimal euroAmount = converter.yenToEuro(yenAmount); System.out.println(yenAmount + " Yen is " + euroAmount + " Euro.");  System.exit(0); } catch (Exception ex) { System.err.println("Caught an unexpected exception!"); ex.printStackTrace(); } } } package com.sun.tutorial.javaee.ejb;  import java.math.BigDecimal; import javax.ejb.EJB; public class ConverterClient { @EJB private static Converter converter; public ConverterClient(String[] args) { }  public static void main(String[] args) { ConverterClient client = new ConverterClient(args); client.doConversion(); }  Compiling -The application client files are compiled at the same time as the enterprise bean files.

  21. Creating Web Client public void jspDestroy() { converter = null; }%> <html> <head> <title>Converter</title> </head>  <body bgcolor="white"> <h1>Converter</h1> <hr> <p>Enter an amount to convert:</p> <form method="get"> <input type="text" name="amount" size="25"> <br> <p> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </form> <%@ page import="converter.ejb.Converter, java.math.*, javax.naming.*"%>  <%! private Converter converter = null; public void jspInit() { try { InitialContext ic = new InitialContext(); converter = (Converter) ic.lookup(Converter.class.getName()); } catch (Exception ex) { System.out.println("Couldn’t create converter bean."+ ex.getMessage()); } } 

  22. <% String amount = request.getParameter("amount"); if ( amount != null && amount.length() > 0 ) { BigDecimal d = new BigDecimal(amount);  BigDecimal yenAmount = converter.dollarToYen(d); %> <p> <%= amount %> dollars are <%= yenAmount %> Yen. <p> <% BigDecimal euroAmount = converter.yenToEuro(yenAmount); %> <%= amount %> Yen are <%= euroAmount %> Euro. <% } %> </body> </html> Compiling - The Application Server automatically compiles web clients

  23. Deploying in NetBeans IDE • In NetBeans IDE, make sure the converter application is open. • In the Projects tab, right-click the converter project and select Undeploy and Deploy. You will see the output in the Output tab.

  24. Running Application Server in NetBeans IDE • In NetBeans IDE, make sure the converter application is open. • In the Projects tab, right-click the converter project and select Run. You will see the following output in the Output tab: ... $100.00 is 11258.00 Yen. 11258.00 Yen is 78.81 Euro. ...

  25. Running Web Client • To run the web client, point your browser at the following URL. Replace host with the name of the host running the Application Server. If your browser is running on the same host as the Application Server, you can replace host with localhost. • http://host:8080/converter • After entering 100 in the input field and clicking Submit, you should see the screen shown in

More Related