CHAPTER 1 INTRODUCTION TO THE EJB ARCHITECTURE Administrating the GlassFish Application Server NetBeans provides us with a graphical interface to perform various GlassFish server-related administrative tasks. You can restart,start,and stop the GlassFish server from the Services tab,as shown in Figure 1-10. File Edit View Navigate Source Refactor Run Debug Profile Team Tool 份幻名与 习T彩 Projects Files Services -目Databases 由Web Services 白目Servers GlassFish Server3用 Repositories Start Start in Debug Mode 中-6 Hudson Builders Start in Profile Mode 由宿Issue Trackers Restart Stop Refresh Remove View Domain Admin Console View Domain Server Log View Domain Update Cente Properties Figure 1-10.Administrating the Glassfish application server Once GlassFish has successfully started,you can test whether the server is able to accept the basic HITP requests.To do so,open a browser,type in the URL http://localhost:8080/and,if the server is up and running. you will be able to see the page shown in Figure 1-11. Gog图百vC。·音口 Server 3.1 Your server is now running rpet folder of this senver The docu ment root folder for this server is the do tory of this senver's domair aoe a server on the local wth the detosdt a Get Oracle GlassFish Server with Premier Support Figure i-11.Testing glassFish server 19
Chapter 1 ■ IntroduCtIon to the eJB arChIteCture 19 Administrating the GlassFish Application Server NetBeans provides us with a graphical interface to perform various GlassFish server-related administrative tasks. You can restart, start, and stop the GlassFish server from the Services tab, as shown in Figure 1-10. Figure 1-10. Administrating the Glassfish application server Figure 1-11. Testing GlassFish server Once GlassFish has successfully started, you can test whether the server is able to accept the basic HTTP requests. To do so, open a browser, type in the URL http://localhost:8080/ and, if the server is up and running, you will be able to see the page shown in Figure 1-11
CHAPTER 1 INTRODUCTION TO THE EJB ARCHITECTURE Note Substitute localhost with the machine name or IP address if you are trying to access it from a machine other than the one on which GlassFish is installed.If you changed the port number during installation,use that port instead of 8080. The next step is to test the access to the administration console of the GlassFish server.Make sure that the GlassFish server is up and running,and then select the View Domain Admin Console menu option from the context menu,as shown in Figure 1-10.NetBeans will launch the default browser and open the administrator console. Alternatively,you can type in the URLhttp://localhost:4848/,and you will be able to see the administration console page,as shown in Figure 1-12 C天 GlassFish-Server Open Source Edition Common Tasks lassFish News stration Gude List Deplc Jpdate Cente Deploy an Application Add-Ons Other Tasks Figure 1-12.The GlassFish administration console Note Substitute localhost with the machine name or IP address if you are trying to gain access from a machine other than the one on which GlassFish is installed.You will have to enter the username and password on the administration console login page.If you changed the port number during installation,use that port instead of 4848. Troubleshooting Even after precisely following the steps mentioned in this chapter and taking the utmost care while installing and configuring the NetBeans IDE along with its integrated GlassFish application server,you may face problems while running the sample code that accompanies this book.This section will try to highlight issues that you may come across and provides information on how to mitigate them. 20
Chapter 1 ■ Introduction to the EJB Architecture 20 ■ Note Substitute localhost with the machine name or IP address if you are trying to access it from a machine other than the one on which GlassFish is installed. If you changed the port number during installation, use that port instead of 8080. The next step is to test the access to the administration console of the GlassFish server. Make sure that the GlassFish server is up and running, and then select the View Domain Admin Console menu option from the context menu, as shown in Figure 1-10. NetBeans will launch the default browser and open the administrator console. Alternatively, you can type in the URL http://localhost:4848/, and you will be able to see the administration console page, as shown in Figure 1-12. Figure 1-12. The GlassFish administration console ■ Note Substitute localhost with the machine name or IP address if you are trying to gain access from a machine other than the one on which GlassFish is installed. You will have to enter the username and password on the administration console login page. If you changed the port number during installation, use that port instead of 4848. Troubleshooting Even after precisely following the steps mentioned in this chapter and taking the utmost care while installing and configuring the NetBeans IDE along with its integrated GlassFish application server, you may face problems while running the sample code that accompanies this book. This section will try to highlight issues that you may come across and provides information on how to mitigate them
CHAPTER 1 INTRODUCTION TO THE EJB ARCHITECTURE "No Compatible JDK was found"warning during installation You get a No compatible DK was found warning message on the first page of the NetBeans installer wizard. Diagnosis Samples in this book require NetBeans version7.3or later.NetBeans73inturn requires Java Platform(K)7. You will get a No compatible JDK was found warning message if Java Platform(JDK)7 is not installed on your macnine Solution You will have to exit the wizard and install Java Platform(JDK)7after downloading it from the following location http://www.oracle.com/technetwork/java/javase/downloads/index.html Unable to see GlassFish server's test page Diagnosis You may not able to see the test page because of the following reasons: GlassFish server is not running. Browser is unable to resolve the server's hostname. Incorrect port number is mentioned in the URL. Solution Start/restart the GlassFish server using the context menu as shown in Figure 1-10. Verify that the machine name or the IP address that is used in the URLis correct.You can find your machine's IP address by executing the ipconfig command on your Wind ws machine ot.If you are using I st then verify that the browser is able to resolve it by loopingit back to your machine's IP address. Verify that the port number used in the URL is correct.Thissolution is explained in asection that follows Unable to resolve“localhost'”hostname Your browser or the NetBeans IDE's tester is able to run the GlassFish server's test page using the machine name or the IP address but is unable to resolve the localhost hostname. Diagnosis The NetBeans IDE's tester or the browser is unable to loopback to your machine using localhost. 21
Chapter 1 ■ Introduction to the EJB Architecture 21 “No Compatible JDK was found” warning during installation You get a No compatible JDK was found warning message on the first page of the NetBeans installer wizard. Diagnosis Samples in this book require NetBeans version 7.3 or later. NetBeans 7.3 in turn requires Java Platform (JDK) 7. You will get a No compatible JDK was found warning message if Java Platform (JDK) 7 is not installed on your machine. Solution You will have to exit the wizard and install Java Platform (JDK) 7 after downloading it from the following location. http://www.oracle.com/technetwork/java/javase/downloads/index.html Unable to see GlassFish server’s test page You are unable to see the GlassFish server’s test page as shown in Figure 1-11, after installing the NetBeans IDE and its integrated GlassFish application server. Diagnosis You may not able to see the test page because of the following reasons: • GlassFish server is not running. • Browser is unable to resolve the server’s hostname. • Incorrect port number is mentioned in the URL. Solution • Start/restart the GlassFish server using the context menu as shown in Figure 1-10. • Verify that the machine name or the IP address that is used in the URL is correct. You can find your machine’s IP address by executing the ipconfig command on your Windows machine’s command prompt. If you are using localhost then verify that the browser is able to resolve it by looping it back to your machine’s IP address. • Verify that the port number used in the URL is correct. This solution is explained in a section that follows. Unable to resolve “localhost” hostname Your browser or the NetBeans IDE’s tester is able to run the GlassFish server’s test page using the machine name or the IP address but is unable to resolve the localhost hostname. Diagnosis The NetBeans IDE’s tester or the browser is unable to loopback to your machine using localhost
CHAPTER 1 INTRODUCTION TO THE EJB ARCHITECTURE Solution Update theC:\Windows\System32\drivers\etclhosts file of your Windows machine to add an entry that maps the IP address of your machine to localhost. localhost name resolution is handled within DNS itself. #127.0.0.1 localhost #::1 localhost <IP address of your machine> localhost Browser is unable to connect to“808o”port The host name part of your URL is correct,but your browser is unable to connect to the GlassFish application server at port 8080 Diagnosis Your browser will be unable to use the 808o ort number for the glassFish application server if it is used by anothe application.Duri ng installation the config first try to assign the 080 port to the GlassFish ap ication ver,but if it dete cts that the 8080 port number is unavailable then it will assign a different port number to it. Solution You can find the port at which GlassFish application server is running with the following steps: Navigate to the Services tab of the NetBeans IDE and invoke the context menu on the GlassFish server node as shown in Figure 1-10. Select the Properties menu option to open the Servers dialog. Select the GlassFish server instance in the left panel. The Location text field,under the Common tab,will show the port number at which the GlassFish application server is running. Errors while compiling or executing sample application projects You get compilation errors after opening the sample application project,or the sample application project doesno execute as expected Diagnosis The samples provided as oart of this book are tested with NetBeans version 7 3 and lava platform (IDK)7. You might get the"javac:invalid target release:1.7"error while compiling the sample application projects provided with this book if the NetBeans IDE is not configured to use Java Platform(JDK)7. The sample application code contains hard-coded port numbers corresponding to the NetBeans installation on which they were created.The sample will not execute as expected if the port number hard-coded in the sample code is different from your NetBeans installation. 22
Chapter 1 ■ Introduction to the EJB Architecture 22 Solution Update the C:\Windows\System32\drivers\etc\hosts file of your Windows machine to add an entry that maps the IP address of your machine to localhost. # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost <IP address of your machine> localhost Browser is unable to connect to “8080” port The host name part of your URL is correct, but your browser is unable to connect to the GlassFish application server at port 8080. Diagnosis Your browser will be unable to use the 8080 port number for the GlassFish application server if it is used by another application. During installation the configuration tool will first try to assign the 8080 port to the GlassFish application server, but if it detects that the 8080 port number is unavailable then it will assign a different port number to it. Solution You can find the port at which GlassFish application server is running with the following steps: • Navigate to the Services tab of the NetBeans IDE and invoke the context menu on the GlassFish server node as shown in Figure 1-10. • Select the Properties menu option to open the Servers dialog. • Select the GlassFish server instance in the left panel. • The Location text field, under the Common tab, will show the port number at which the GlassFish application server is running. Errors while compiling or executing sample application projects You get compilation errors after opening the sample application project, or the sample application project does not execute as expected. Diagnosis The samples provided as part of this book are tested with NetBeans version 7.3 and Java Platform (JDK) 7. You might get the “javac: invalid target release: 1.7” error while compiling the sample application projects provided with this book if the NetBeans IDE is not configured to use Java Platform (JDK) 7. The sample application code contains hard-coded port numbers corresponding to the NetBeans installation on which they were created. The sample will not execute as expected if the port number hard-coded in the sample code is different from your NetBeans installation
CHAPTER 1 INTRODUCTION TO THE EJB ARCHITECTURE Solution To resolve the"javac:invalid target release:1.7"error,you have to verify that NetBeans is using lava Platform ares Yone as th n gettflepiOidedwiheachanpleaplicationforadionalinfoamaion Unable to send or receive the "wine order"mail You are unable to send or receive the"wine order"mail while executing the sample application project. Diagnosis send out a mail as part of their execution.You may have trouble sending the mail and mayno 。 You have not updated the from and toe-mail addresses in the sample code You are running the sample on a machine that is behind a firewall. JMS Resource configuration is incorrect. .JavaMail Session configuration is incorrect. Solution Before you execute the sample application project that sends out a mail,verify that: You have created and configured the MS Resource as shown in Chapter 5. You have created and configured the JavaMail Session as shown in Chapter 5. You have updated the from and toe-mail addresses in the sample's source code You are not behind a firewall. etail you are fac any more on the is aegproblaminsemdngoroetingthealheneheckthe Conclusion This chapter opened with an introduction to this book and EJB.This orientation covered essential information abou tures of EJB,the ElB framework, opment mod and the yo trib eide whic ary ol strate the general flov uld you w ich its in which has the refer entation c the lates正p cificati erify that the installation was su cessful.Having mpleted this task,you now have the req quired software run the code sa nples in this book and to e the many features of EJB th roughout the subsequent chapters. 23
Chapter 1 ■ Introduction to the EJB Architecture 23 Solution To resolve the “javac: invalid target release: 1.7” error, you have to verify that NetBeans is using Java Platform (JDK) 7. You may have to install it from the URL mentioned in the earlier sections. If the sample application is not working as expected, then verify that the port numbers used by the sample code are same as that of your NetBeans installation. You can consult the Readme.txt file provided with each sample application for additional information. Unable to send or receive the “wine order” mail You are unable to send or receive the “wine order” mail while executing the sample application project. Diagnosis Few sample projects send out a mail as part of their execution. You may have trouble sending the mail and may not receive it because of the following reasons: • You have not updated the from and to e-mail addresses in the sample code. • You are running the sample on a machine that is behind a firewall. • JMS Resource configuration is incorrect. • JavaMail Session configuration is incorrect. Solution Before you execute the sample application project that sends out a mail, verify that: • You have created and configured the JMS Resource as shown in Chapter 5. • You have created and configured the JavaMail Session as shown in Chapter 5. • You have updated the from and to e-mail addresses in the sample’s source code. • You are not behind a firewall. You can consult the Readme.txt file provided with the sample application of Chapter 5 for information on how to configure JavaMail Session properties for popular mail services. Even after verifying these details, if you are facing problems in sending or receiving the mail, then check the GlassFish server log for any more details on the issue. Conclusion This chapter opened with an introduction to this book and EJB. This orientation covered essential information about the core features of EJB, the EJB framework, and the component model. It included a brief overview of the history of EJB, the EJB 3 simplified development model, and the EJB distributed computing model. In the “How This Book Is Organized” section, we provided a summary of each chapter to illustrate the general flow of the book, and to help you decide which areas to focus on first, should you wish to read the chapters out of sequence. The chapter concluded with a “Getting Started” section to help you install and configure the NetBeans IDE and its integrated GlassFish application server, which has the reference implementation of the latest Java EE specifications, and to verify that the installation was successful. Having completed this task, you now have the required software infrastructure to run the code samples in this book and to examine the many features of EJB throughout the subsequent chapters