background image

15

CHAPTER 2

JRun Programming Model

JRun is a complete Java application server for developing and deploying J2EE enterprise 
applications. This chapter describes the JRun programming model, the major 
components of JRun, and JRun support for J2EE enterprise applications.

Contents

Enterprise application architecture......................................................................... 16

JRun programming environment........................................................................... 19

JRun servers........................................................................................................... 20

Web servers............................................................................................................ 25

JRun support for J2EE applications ....................................................................... 26

Содержание 38000382 - Macromedia JRun - Mac

Страница 1: ...Getting Started with JRun...

Страница 2: ...adenames of Macromedia Inc or other entities and may be registered in certain jurisdictions including internationally This product includes code licensed from RSA Data Security This guide contains lin...

Страница 3: ...tures 8 Development tools 13 Dreamweaver MX 13 Using JRun with your Java IDE 13 Installing the Enterprise Deployment Wizard in your Java IDE 13 What to do next 14 CHAPTER 2 JRun Programming Model 15 E...

Страница 4: ...orization Service 1 0 36 Java Naming and Directory Interface 36 Common Object Request Broker Architecture compliance 36 Additional resources 36 CHAPTER 4 Using Servlets and JSP 37 Using Java Servlets...

Страница 5: ...60 Mappings 60 Application mappings 61 Developing web applications 62 Creating a web application 62 Adding web application components 62 Deploying web applications 65 Deploying a web application acro...

Страница 6: ...95 What s next 95 LESSON 4 Web Services Tutorial 97 Using JRun web services 98 TravelNet web services application 98 Setting up the development environment 99 Getting started with JRun 100 Adding a JR...

Страница 7: ...ion to JRun and J2EE Part II contains tutorials to show you how to build a simple J2EE application In the tutorial lessons you add a JRun server and write the code for servlets JSPs JavaBeans and EJBs...

Страница 8: ...e you can post messages and read replies on many subjects relating to JRun Developer Resources http www macromedia com desdev devel oper http www macromedia com desdev developer a All of the resources...

Страница 9: ...he PDF files are included on the JRun CD and installed in the JRun docs directory although they are an optional part of the installation You can access them by clicking the Product Documentation link...

Страница 10: ...vaServer Pages a Marty Hall Prentice Hall PTR 2000 ISBN 0130893404 Java Servlet Programming Second Edition Jason Hunter and William Crawford O Reilly Associates 2001 ISBN 0596000405 http www servletgu...

Страница 11: ...Sons 2002 ISBN 0471417114 Enterprise JavaBeans Third Edition Richard Monson Haefel O Reilly Associates 2001 ISBN 0596002262 Professional EJB Rahim Adatia et al Wrox Press 2001 ISBN 1861005083 Special...

Страница 12: ...EE Connector Architecture and Enterprise Application Integration Rahul Sharma et al Addison Wesley 2001 ISBN 0201775808 Building Web Services with Java Making Sense of XML SOAP WSDL and UDDI Sim Simeo...

Страница 13: ...r resources xiii Server Side http www theserverside comhttp www theserversid e com a Dot Com Builder http dcb sun comhttp dcb sun com a Servlet Forum http www servletforum com http www servletforum co...

Страница 14: ...tp webforums macromedia comhttp webforums macrom edia com a at any time Sales Toll Free 888 939 2545 Tel 617 219 2100 Fax 617 219 2101 E mail mailto sales macromedia comsales macromedia com a Web http...

Страница 15: ...roduction This part contains an introduction to JRun and J2EE Welcome to JRun 3 JRun Programming Model 15 Introduction to J2EE 29 Using Servlets and JSP 37 Introduction to EJB 47 Developing Web Applic...

Страница 16: ......

Страница 17: ...at you use during application development and deployment It also includes a description of different types of JRun users and pointers to the JRun documentation where each type of user can find additio...

Страница 18: ...own built in web server For more information see Installing JRun Benefits of server side Java Java Servlets JSPs and EJBs are all examples of server side Java that is Java code that executes on an ap...

Страница 19: ...J2EE offers a number of benefits for application programmers including the following Rich set of standard APIs and services High performance Integration with backend infrastructure such as Relational...

Страница 20: ...on of J2EE servers with enterprise information systems such as Enterprise Resource Planning ERP systems mainframe transaction processing systems and legacy database systems JSP 1 2 Supports several ad...

Страница 21: ...Java standards including the following Java Management Extensions JMX Specifications for managing Java environments JMX defines the architecture and APIs for a scalable system that you can integrate...

Страница 22: ...clet integration Pointbase database server JDBC Drivers Sample applications Web services Dynamic deployment of J2EE components JRun provides auto deploy and hot deploy features for dynamic deployment...

Страница 23: ...e Help Web Server Configuration tool JRun provides native connectors for most major web servers Using the Web Server Configuration tool you can connect one or more web servers to each JRun server The...

Страница 24: ...authorized web clients have access to the resources on a website For more information on web application security see JRun Administrator s Guide EJB security JRun provides a configurable mechanism fo...

Страница 25: ...all Java database used with the JRun sample applications You can use this database server for your evaluation and development work For more information on the PointBase database see the PointBase doc...

Страница 26: ...pplication also contains an admin module The world music application illustrates many common design patterns using JSP servlet and JavaBean programming The world music sample application uses the worl...

Страница 27: ...ng the JRun server main method jrunx kernel JRun contained in jrun_root lib jrun jar Note The jrun_root directory is the directory into which you installed JRun The working directory jrun_root bin The...

Страница 28: ...ble shows the books to read after the introductory chapters depending on your role in developing and deploying JRun applications Role Description For more information All JRun developers Performs comm...

Страница 29: ...J2EE enterprise applications This chapter describes the JRun programming model the major components of JRun and JRun support for J2EE enterprise applications Contents Enterprise application architect...

Страница 30: ...hanisms For more information on application design patterns see JRun Programmer s Guide Dividing an enterprise application into tiers supports an enterprise application s design goals with layers that...

Страница 31: ...nterprise resources planning systems mainframe transaction processors legacy systems and enterprise integration technologies usually reside in the data tier Other tiers access the data tier with a dri...

Страница 32: ...the page is translated into a Java Servlet The scripting portion of a JSP lets you present dynamic content back to the client In addition you can access servlets custom tag libraries and EJBs from JSP...

Страница 33: ...ives a client request and delivers a response containing web content This content can be static web pages or dynamically generated by a Java Servlet or a JSP processed by JRun You can connect one or m...

Страница 34: ...ollowing advantages Increased stability of the web server The ability to start and stop a web server independently of JRun The ability to modify an application without restarting the web server The ab...

Страница 35: ...er after starting your system If you do not run JRun as a service it runs as an application For more information on starting and stopping a JRun server see JRun Administrator s Guide or the JMC online...

Страница 36: ...gure shows the configuration of the admin and default servers Option Description start Starts JRun stop Stops JRun restart Restarts JRun status Displays status information for all JRun servers or for...

Страница 37: ...the administrative applications shipped with JRun including the JRun Management Console JMC You are not limited to running the JMC on this server or at this port location You access the JMC applicatio...

Страница 38: ...world music application illustrates many common design patterns using JSP servlet and JavaBean programming The world music sample application uses the worldmusic database accessing it directly through...

Страница 39: ...for an application resource the connector on the web server opens a network connection to the JRun connection module residing within the JRun server The connection module serves as a transparent comm...

Страница 40: ...shows the components in a J2EE enterprise application Prior to deploying a component you must package its constituent parts in the appropriate directory structure and create the component s deploymen...

Страница 41: ...mic servlet compilation and reloading When you distribute a web application you can distribute it as the expanded directory structure or you can distribute it as a single compressed file called a Web...

Страница 42: ...r creates the standard deployment descriptor file ra xml You use jrun ra xml when you require more than one managed connection to specify the resource adapter s JNDI name configuration properties secu...

Страница 43: ...uction to J2EE This chapter familiarizes you with the Java 2 Platform Enterprise Edition J2EE and its related technologies Contents J2EE environment 30 J2EE platform technologies 31 J2EE APIs 33 Addit...

Страница 44: ...buted applications are two tier client server three tier client middleware server and multitier client multiple middleware multiple servers The tiers have the following characteristics Client tier Sup...

Страница 45: ...plication with its related classes and files and communicates with other components The J2EE platform supports the following types of components Containers Before a component can be executed it must b...

Страница 46: ...he following types of communication technologies Internet protocols Includes Transport Control Protocol over Internet Protocol TCP IP Hypertext Transfer Protocol HTTP 1 0 and Secure Socket Layer SSL 3...

Страница 47: ...se application Enterprise JavaBeans components called enterprise beans are scalable transactional and secure An enterprise bean is a body of code with fields to implement modules of business logic Ent...

Страница 48: ...based document that contains two types of text static template data which can be expressed in any text based format such as HTML WML and XML and JSP elements that determine how the page constructs dy...

Страница 49: ...ate JavaBeans component to perform those operations JavaMail uses JAF Java API for XML 1 1 XML is a language for representing and describing text based data so the data can be read and handled by any...

Страница 50: ...ifying standard for writing distributed object systems The standard is completely neutral with respect to platform language and vendor and incorporates a variety of important technologies useful for a...

Страница 51: ...va and JSPs It highlights concepts and objects common to both environments It includes sample code for a Java Servlet and a JSP as well as a summary of changes in the servlet API Contents Using Java S...

Страница 52: ...to write sophisticated applications without being encumbered by the complexities and platform specific behaviors of a specific web server implementation The servlet API supports the building blocks of...

Страница 53: ...ability Using JRun servlets adhere to the industry standard servlet specification and are portable to any other web server that supports the servlet standard or uses JRun Portability is important for...

Страница 54: ...servlet that you write using JRun on any other web server that uses JRun or any web server that supports the J2EE servlet standard JRun supports the Java Servlet 2 3 specification which introduces two...

Страница 55: ...nformation stored within the HTTP request process the information and return results to the client as part of an HTTP response The following figure shows the anatomy of a HTTP request and response HTT...

Страница 56: ...ining user preferences the servlet might set the display color of the browser based on stored preference information You return information through the HTTP response in the following ways Servlets use...

Страница 57: ...e information on using event listeners see JRun Programmer s Guide Handling exceptions Exceptions are errors detected within your servlet Exceptions can occur when JRun translates a JSP to a Java clas...

Страница 58: ...ts use this key value to look up the previously stored session information Cookies are stored on the server and referenced with a session ID that is passed back and forth between the client and the se...

Страница 59: ...ct Writing servlets in Java The following example shows the complete source code for a functioning Java Servlet import java io import javax servlet import javax servlet http public class SimpleServlet...

Страница 60: ...rst time JRun translates it into a Java source file and then compiles the file into a Java class file So you can create servlets without writing a line of Java code Because the runtime image of a JSP...

Страница 61: ...ter describes fundamental Enterprise JavaBean EJB elements and concepts and JRun specific EJB features JRun Programmer s Guide explains these features in detail Contents EJB Overview 48 Container serv...

Страница 62: ...on server that supports EJBs lets Java developers concentrate on implementing the business logic of an enterprise application as reusable components The EJB programming model is best suited for experi...

Страница 63: ...ommodate these types of single request business processes Stateless session beans are particularly useful in the session entity facade pattern A facade is a high level interface that masks lower level...

Страница 64: ...epresent objects that persist through a server shutdown The data representing an instance of an entity bean is typically stored in rows and tables of a relational database which you access using a JDB...

Страница 65: ...Note JRun 4 also supports the automatic deployment of JRun 3 1 style CMP beans For more information on EJB 1 1 support see JRun Programmer s Guide Message driven beans A message driven bean MDB acts a...

Страница 66: ...jrun ejb jar xml file to false Note JRun does not enable EJB clustering for local beans For more information see JRun Administrator s Guide Deployment feature Description Hot deploy If hot deploy is...

Страница 67: ...r s Guide The Enterprise Deployment Wizard The JRun Enterprise Deployment Wizard streamlines the process of developing and deploying EJBs Using its Swing based graphical user interface you can create...

Страница 68: ...54 Chapter 5 Introduction to EJB...

Страница 69: ...ses a web application and the resources in it It also describes how to create package and deploy a web application Contents Introduction to web applications 56 About the web application directory stru...

Страница 70: ...rver from where it was developed JRun fully implements the web application architecture described in the Java Servlet 2 3 specification You can develop a web application using JRun and deploy the appl...

Страница 71: ...s you develop web applications you must decide whether to divide applications between multiple JRun servers use a single JRun server to host all of your applications or to define a cluster of servers...

Страница 72: ...ure Directory Description Web_app Contains the WEB INF directory and all files that must be accessible to the client request such as JSPs HTML pages cascading style sheets images and JavaScript files...

Страница 73: ...mation used by the application for execution on an application server The Java Servlet specification defines the contents of web xml so it is not specific to JRun All platforms that support J2EE compl...

Страница 74: ...ee JRun Assembly and Deployment Guide Web applications JRun servers and web servers One of your tasks when developing a web application is to deploy your application on a JRun server Note Do not deplo...

Страница 75: ...JSPs and servlets The following table describes the mappings that the JRun configuration files define Application mappings An application mapping relates a context path to the name and directory path...

Страница 76: ...es Flash swf files images tag libraries JavaBeans Enterprise JavaBeans and other application resources As part of developing a web application you add these components to the directory structure of th...

Страница 77: ...Servlets are represented by a class file The procedure for adding a servlet to a web application depends on where you store the servlet Typically you store the servlet in one of the following location...

Страница 78: ...mapping in your production systems Adding tag libraries The JavaServer Pages specification describes a framework for tag libraries Tag libraries let developers encapsulate sets of related functionali...

Страница 79: ...next time you start the server The deployment is dynamically updated when you modify a module archive file or deployment descriptor In a production environment it is best to deploy archive files for g...

Страница 80: ...tory create directories called classes and lib 4 Copy the application servlets and any other unarchived class files to the WEB INF classes directory 5 If the web application uses JSP tag libraries cop...

Страница 81: ...n server and write the code for Java Servlets JSPs JavaBeans and EJBs You learn how to combine these elements to produce a flexible and scalable J2EE application In the final tutorial lesson you use w...

Страница 82: ......

Страница 83: ...esson you set up the development environment add a JRun server for the tutorial and deploy the tutorial template application In the first procedure you code the logon servlet that provides the busines...

Страница 84: ...n the jrun_root docs tutorialfiles directory referred to as tutorial_root 3 Optional Set up your Java IDE to work with JRun For more information see Using JRun with your Java IDE on page 13 Software R...

Страница 85: ...e JRun Management Console JMC You use the JMC for the initial tutorial procedures adding a JRun application server and defining a JDBC data source To start the JRun Management Console 1 Start the JMC...

Страница 86: ...JRun The JRun home page appears In the next section you use the JMC to add a JRun server for the tutorial application Adding a JRun server During installation JRun creates three servers admin default...

Страница 87: ...ervers by type of user For example having production QA and admin JRun servers can help organize your development workflow The JMC lets you easily establish and manage server clusters JRun automatical...

Страница 88: ...nter the server name jrun home servers tutorial The server creation process replaces the symbolic variable jrun home with the directory in which you installed JRun 3 Click Create Server The Port Setti...

Страница 89: ...ry on the target server The default autodeploy directory is jrun_root servers jrun_server The name of the JRun server on which you are deploying the application is tutorial JMC deploy In the JMC click...

Страница 90: ...r containing the deployed tutorial compass enterprise application Adding JDBC data sources Using the JMC you can add remove edit and test JDBC data sources The JMC provides an interface to the data so...

Страница 91: ...and click JDBC Data Sources The JDBC Data Sources window appears 2 In Data Source Name enter compass Select Pointbase Server in the Database Driver drop down list box Click Add The Data Source Settin...

Страница 92: ...on compassdb bat Linux UNIX Run the compassdb shell script 6 Restart the tutorial server in one of the following ways In the JMC click the Restart icon next to the tutorial server In the JRun Launche...

Страница 93: ...g URL http localhost 8101 compass logon jsp Note Use 8101 or the web server port number that JRun assigned when you created the tutorial server View the tutorial application login page In subsequent t...

Страница 94: ...ure shows how to write a servlet that accesses a database To code the logon servlet 1 Open a text editor or Java IDE and copy and paste the following code package compass import javax servlet import j...

Страница 95: ...ord validLogon true firstName rs getString first_name lastName rs getString last_name catch Exception e System out println e throw new ServletException e finally try rs close ps close connection close...

Страница 96: ...ote There are two users defined in the compass database john password john and mary password mary 7 Click the Logon button If the login is valid a blank Adventure Trips home page appears Summary In th...

Страница 97: ...Pages JSPs that comprise the body of the Compass Travel tutorial application You build a JSP with embedded Java code to access database information and develop a JSP that uses a JavaBean Contents Cre...

Страница 98: ...a JSP page JSP scripting elements to query a database and define statements evaluated on the server before sending the page output to the client Home jsp displays a list of trips a customer can book...

Страница 99: ...td td class contentBG trips getString teaser td td class contentBG nf format trips getDouble price td tr catch Exception e out println e finally connection close 3 Save home jsp and open a web browser...

Страница 100: ...tion about a selected trip To instantiate a JavaBean 1 Open the file tripdetail jsp located in jrun_root servers tutorial compass ear compass war 2 Where indicated in the file add the following JSP co...

Страница 101: ...thod which accesses the database and retrieves trip detail for the passed tripID public void retrieve int id The next procedure reuses TripBean Java code and presents the retrieved data in a different...

Страница 102: ...to get the trip name start date end date and price and presents the data in a different format Summary In this lesson you added JSP code in the Compass Travel home page including JSP directives and sc...

Страница 103: ...of booking a trip reservation including validating a credit card payment and creating an order You learn how to invoke an EJB from a JSP and how to write an EJB that invokes other EJBs Contents Using...

Страница 104: ...Description remote home interface EJBHome Defines the EJBs life cycle methods that can be accessed from applications outside the EJB container methods to create obtain find or remove an EJB instance l...

Страница 105: ...er javax naming InitialContext ctx new javax naming InitialContext The lookup method lets you query a name server to locate the EJB and returns a reference to the home interface Object obj ctx lookup...

Страница 106: ...piration field Reservation jsp displays a confirmation ID if the reservation is successful or an error message if a problem occurred You often use session beans to coordinate interactions between EJBs...

Страница 107: ...mote interface lists the business methods available in the EJB This EJB has only one business method called reserve that allows you to book a trip ReservationHomeRemote java This EJB is instantiated u...

Страница 108: ...l compass ear creditcard META INF It defines the credit card EJB as a stateless session bean This procedure shows how to write a simple session bean Examining the code for the order EJB You can review...

Страница 109: ...tutorial and deployed the Compass tutorial application EAR file In subsequent lessons you coded a Java Servlet and added Java code to JavaServer Pages JSPs You accessed a JavaBean and EJB from a JSP Y...

Страница 110: ...96 Lesson 3 EJB Tutorial...

Страница 111: ...application You can do the web services tutorial lesson without having completed the servlet JSP or EJB tutorial lessons in the preceding chapters Contents Using JRun web services 98 Getting started w...

Страница 112: ...tes the Java code is not necessarily the person who publishes it as a web service Deployer The web service deployer might also be the web service publisher The deployer generates the Web Services Desc...

Страница 113: ...t up your development environment To set up the development environment 1 Install the following software 2 The tutorial files are located in the jrun_root docs tutorialfiles directory referred to as t...

Страница 114: ...in order to use the JRun Management Console JMC You use the JMC for the initial tutorial procedure adding a JRun application server To start the JRun Management Console 1 Start the JMC in one of the...

Страница 115: ...next section you use the JMC to add a JRun server for the tutorial application Adding a JRun server During installation JRun creates three servers admin default and samples The admin server hosts the...

Страница 116: ...ick Create New Server The Creating a New JRun Application Server window appears 2 Keep the default Host Name localhost enter the JRun Server Name for the tutorial application tutorial and the JRun Ser...

Страница 117: ...ake a note of the web server port number You use it to access the TravelNet application on the tutorial server 4 Keep the default port settings and click Finish 5 After the JMC refreshes you see the t...

Страница 118: ...deployments page Click the Add button in the Enterprise Applications table browse to or enter the path to the EAR file and click Deploy Additionally JRun lets you deploy an enterprise application fro...

Страница 119: ...name of the Java implementation class and methodName is the name of the allowed methods TravelNet running on the tutorial server consumes these web services from the Compass Travel application running...

Страница 120: ...service by appending WSDL to its endpoint URL In the next tutorial procedure you generate a WSDL file from the Compass Travel application on the samples server and save it in the TravelNet application...

Страница 121: ...rop down list box select All Files before you click Save or xml is appended to the filename 5 Save the file in the jrun_root servers tutorial travelnet ear travelnet war WEB INF classes directory 6 En...

Страница 122: ...Proxy clients invoke web service operations A proxy client calls methods on a local proxy generated from the WSDL file for a specific web service The proxy object handles interaction with the remote w...

Страница 123: ...tains method signatures for the web service operations ReservationService ServiceName java A factory interface that the ServiceNameLocator java class implements The interface name is derived from the...

Страница 124: ...pdetail jsp tripId trips i getId trips i getName a td td class contentBG trips i getTeaser td td class contentBG trips i getPrice td TripService ServiceName java A factory interface that the ServiceNa...

Страница 125: ...b service provided by Compass 3 Open the file jrun_root servers tutorial travelnet ear travelnet war reservationaction jsp Add the following code where indicated in the file 1 Instantiate a proxy fact...

Страница 126: ...2 Select and book a trip reservation Enter any First Name Enter any Last Name Select any credit card Enter any number in the Number field Enter any MM YY in the Expiration field Reservation jsp displa...

Страница 127: ...orial procedures you learned how to do the following Author a web service in a WSDD file Generate a WSDL file for a web service From a WSDL file generate Java proxy code Write a JSP based proxy client...

Страница 128: ...114 Lesson 4 Web Services Tutorial...

Страница 129: ...ted and online ix E EAR files 56 EJB containers 48 EJB tutorial 89 EJBs deployment model 52 Enterprise Deployment Wizard using with 27 entity beans 50 interfaces 48 90 invoking 91 JRun architecture 52...

Страница 130: ...plications 60 web servers 19 JRun Web Server JWS definition 19 using 25 jrun exe Windows 21 JSP tutorial 83 JSPs directives 84 JSP actions 86 scripting elements 84 web applications adding to 63 L laun...

Страница 131: ...ructure 58 EJBs adding 64 HTML files adding 63 invoker servlet 64 JRun servers 57 JSPs adding 63 packaging 66 root directory 58 servlets 63 tag libraries adding 64 using 57 WAR file 27 web xml file 27...

Страница 132: ...118 Index...

Отзывы: