SlideShare a Scribd company logo
V4.1
                                                                                                   Instructor Exercises Guide



EXempty   Exercise 8. Debug a Web Application

          Estimated time
                                  00:45


          What this exercise is about
                                  In this exercise, you debug the Web application running in the
                                  integrated test environment. IBM Rational Application Developer (V7
                                  and later) includes an integrated testing and debugging environment
                                  that can be used to debug J2EE applications.


          What you should be able to do
                                  At the end of the exercise, you will be able to:
                                   • Set up the Test Environment for debugging
                                   • Debug the application in Rational Application Developer


          Introduction
                                  The J2EE application that is debugged in this exercise is the library
                                  book renewal application. It is composed of a Web application with an
                                  associated Java utility module. Before the application can be
                                  debugged, the server needs to be started in debug mode.


          Requirements
                                  This exercise requires that the library Web project be implemented
                                  (Labs 1-4) and the library database installed (Lab 1).
                                  If the earlier labs were not completed, import the
                                  <LAB_FILES>DatabasesolutionDatabaseSolution.zip file.
                                  The library database needs to be re-installed, but this will be done as
                                  part of this exercise.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application         8-1
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide



Instructor exercise overview
In this exercise students will discover an error into the library enterprise application, and will
use the debugging features of IBM Rational Application Developer to find the source of the
error.


Students discover that renewals are being processed even if no renewal period was
requested. This is caused by the renewRequested variable keeping a value of true once it
has been set. The solution is to add a line of code to reset the variable to false as soon as
the request has been processed.


Students reset the LIBRARY Apache Derby database to its initial state. They then run the
application in order to discover the problem. The server is restarted in debug mode,
breakpoints are added, and the students uses the Step Over, Step Into and Step Return
options to view the execution.


Once the problem has been fixed by adding the line of code, the Step-by-Step debug mode
is used to check that the solution works.




8-2   Developing Web Applications                                                 © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty   Exercise instructions
          Preface
          Open the workspace and if necessary import the required projects (they will already be
          there if you are continuing from the previous lab).
          The following reference in the exercise instructions represents the directory location in your
          workstation:
                   • <LAB_FILES>: C:LabFiles70




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application         8-3
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide



8.1. Prepare the Workspace
The workspace used in the previous lab (Connecting to a Database) should be used as the
starting point for this lab.
If you skipped labs 1, 3 or 4, perform follow the instructions:
__ 1. Start Rational Application Developer.
      __ a. In the Workspace Launcher dialog, specify <LAB_FILES>workspace as the
            new workspace directory.
      __ b. Click OK to open the workspace.
      __ c. Import the <LAB_FILES>DatasolutionDatabaseSolution.zip file. If you need
            assistance, refer to the instructions in the Appendix, Install the Library
            Application in a New Workspace.




8-4    Developing Web Applications                                                © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty   8.2. Reset the Database to Its Default Values
          __ 2. Ensure that the Server is stopped, because the Derby database can only serve one
                client. When the server is running, the data source is the client, so no other program
                can access the database.
              __ a. Open the Servers view by selecting Window                       Show View          Servers.
              __ b. In the Servers view, make sure that the WebSphere Application Server V6.1
                    status is Stopped. If the status is Started, right-click the server and select Stop
                    to stop the server.




          __ 3. Run SetUpLibraryDatabase.java.
              __ a. In the Project Explorer view, expand LibraryDatabaseSetup                           driver.
              __ b. Right-click SetUpLibraryDatabase.java and select Run As                            Java
                    Application.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application         8-5
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide


      __ c. The result should be displayed in the Console view.




      __ d. The message indicates that the library database has successfully reverted to its
            original values.




8-6    Developing Web Applications                                                © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty   8.3. Discover the Problem with Consecutive Check Outs
          __ 4. Search for the Patron with e-mail dv@bogus.ibm.com.
              __ a. In the Project Explorer, expand LibraryWeb                    WebContent.
              __ b. Right click search.jsp and select Run As                   Run on Server.
              __ c. Once the server has started and the search page is loaded in the Web browser,
                    enter dv@bogus.ibm.com as the Search Phrase and select E-mail as the
                    Criteria.




              __ d. Click Search.
          __ 5. Perform consecutive renewal for a different set of items.
              __ a. In the search result page, take note of the due date for the items, then select the
                    first and second check box.




              __ b. Click Renew.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application         8-7
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide




              Note

Results may vary, based upon the date the database was last refreshed and the date when
Renew is clicked.
This applies to all subsequent results displayed in this lab.



      __ c. The first two items are updated with Renewal Status, and the Due Date for the
            second book has been extended.
            Select the third check box, leaving the first two items unchecked.




      __ d. Click Renew again.
      __ e. Notice this time, even though the second item was not selected for Renewal, the
            minute recorded for the transaction time has been extended again. As well, the
            first item still shows the Maximum number of renewals exceeded message when
            it was not requested for renewal.




      __ f.   This time leave all the check boxes cleared, and click Renew twice. The
              following screen appears. Notice the second item is declared to exceed the


8-8    Developing Web Applications                                                © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty               maximum number of renewals even though it was never selected for renewal
                      after the first trial.




              __ g. Clearly, submitting the form several times consecutively produces logical errors
                    in the program. You will now debug this application to determine the cause of the
                    error.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application         8-9
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide



8.4. Debug the Application
__ 6. In order to duplicate the scenario, you must reset the database to its default values.
      You can do so by following the instructions outlined in Section 7.2.
__ 7. Restart the WebSphere Application Server in debug mode.
    __ a. Open the Servers view.
    __ b. Right-click the WebSphere Application Server V6.1 entry and select Debug if the
          server is stopped or Restart Debug if the server is already running.
    __ c. When the server has restarted, you will notice the status of the server now
          indicates that the server is running in debug mode.




__ 8. Since the logic error occurs when renewing the items, the error is likely to be in the
      RenewItems servlet or in an object called from that servlet. Set breakpoints in the
      RenewItems servlet.
    __ a. In the Project Explorer view, navigate to LibraryWeb                       Java Resources: src
             com.ibm.library.servlets.
    __ b. Double-click RenewItems to open it in the editor.
    __ c. The logic in RenewItems is concentrated in the processRequest method. So
          the breakpoint should be set inside that method.
          Further examining of the method reveals that the first few statements are general
          setup statements. They should not cause any problems. The breakpoint should
          therefore be placed at the first statement in the try block.
    __ d. Type CTRL-L and enter 74 in the Go to Line dialog to reach the following
          statement:
                    Collection loanList =
                    (Collection)session.getAttribute("itemList");




8-10 Developing Web Applications                                                  © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty       __ e. Double-click the vertical ruler on the left of the editor, next to line 74 of the code,
                    to set a breakpoint at this line. A breakpoint marker now appears on the mark
                    bar.




              __ f.   A good practice when debugging is to set breakpoints further down in the source
                      than your original stopping point. This way, when you determine the problem is
                      not in the section you are currently debugging, you can click the run button to
                      skip to the next breakpoint without stopping. Scroll down to line 91 (you can use
                      CTRL-L) and place a breakpoint beside the following statement:
                              context.getRequestDispatcher("/listitems.jsp").forward(req,
                              resp);




          __ 9. Debug the Library application on the server.
              __ a. In the Project Explorer view, expand LibraryWeb                      WebContent.
              __ b. Right-click search.jsp and select Debug As                     Debug on Server from the
                    pop-up menu.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application       8-11
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide


    __ c. Once the search page shows up in the browser, enter dv@bogus.ibm.com as
          the Search Phrase and select E-mail as the Criteria. Click Search.




    __ d. The item list page now shows up. Select the first and second item, and click
          Renew.




    __ e. When asked to switch to the Debug perspective, click Yes.
    __ f.   The RenewItems servlet is triggered and the first breakpoint is hit. Click the
            RenewItems.java tab and scroll to line 74, the breakpoint line is highlighted.




8-12 Developing Web Applications                                                  © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty       __ g. You know the renewal process is fine the first time, so you can skip over to the
                    next breakpoint by clicking the Resume button in the Debug view.




              __ h. With the current execution halted on the context.getRequestDispatcher
                    statement, you can examine the variables resulting from the previous
                    statements.
              __ i.   In the Variables view, expand loanList elementData [0], and note the
                      renewAccomplished, renewMessage, and renewRequested variables.
                      Those are the ones of interest to this debugging session.




              __ j.   Expand element [1] and [2] in the elementData array and examine their fields.
                      Notice that the renewRequested variable is set to true, true, false for
                      the three items in the array.
              __ k. Click the Resume button run the servlet to completion.
              __ l.   Switch to the Web browser, it should now display the Renewal Status for the
                      first two items.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application       8-13
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide


    __ m. Select the third row, and leave the first two rows clear. Click Renew.




    __ n. The debugger should take you to the first breakpoint in RenewItems.java again.
__ 10. Use the various Step commands to examine the variables in the servlet. Note that
       loanList is not yet declared.
    __ a. Click Step Over in the Debug view toolbar to go to the next statement in the
          processRequest method.



    __ b. Now loanList should appear in the Variables view. Expand it to examine the
          items in the list. Notice for elementData[0], the renewRequested value is still
          set to true.




8-14 Developing Web Applications                                                  © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty
                      Note

          Note that the ids in the previous Variables view, will vary between executions and
          workspaces.



              __ c. Click the Step Over button to step over the statement String[] renewList
                    = req.getParameterValues("RENEW_ITEM");.
              __ d. Examine the renewList variable in the Variables view. It should just contain
                    one element, and that element has a value of 4.




              __ e. With the execution halted on the markRenewed method, click Step Into in the
                    Debug view to move the execution to the first line of the markRenewed method.



              __ f.   In the markRenewed method, highlight the line
                      if (Integer.valueOf(renewList[i]).intValue() == itemId) {
                      Right-click it and select Run to Line to move the execution to this particular
                      statement.




              __ g. You can also evaluate the current if statement without stepping over it. Open
                    the Display view by selecting Window Show View Display. Copy and paste
                    the if statement Integer.valueOf(renewList[i]).intValue() ==
                    itemId to the Display view. Highlight the expression in Display view and select
                    Display from the pop-up menu. The result should be displayed on the next line.
                    The value false means that the first item does not match the renew list.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application       8-15
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide


    __ h. Back in the RenewItems.java editor, highlight the line
          copy.setRenewRequested(true);. Right-click it and select Run to Line.
    __ i.   In the Variables view, expand copy = LoanedCopy to see that its itemId
            matches the itemId local variable.




    __ j.   Click Step Return in the Debug view to return the execution back to the
            processRequest method.



    __ k. The Debug Current Instruction Pointer should now point to the
          patron.renew(loanList); line. This instruction will execute the renew
          command on database, so you need to make sure the data passed in are setup
          correctly.
__ 11. Change the variable values in a debugging session.
    __ a. In the Variables view, expand loanList elementData [0], [1], [2]. Notice that
          the renewRequested variable is set to true, true, true for the three




8-16 Developing Web Applications                                                  © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty               LoanedCopy elements. Since you only requested that the third book be
                      renewed, the correct values should be false, false, true.




              __ b. Right-click the renewRequested variable under elementData                              [0] and select
                    Change Value.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application       8-17
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide


    __ c. In the Set Value dialog, enter false. Click OK.




    __ d. Similarly, right-click elementData [1] renewRequested and select Change
          Value. Enter false in the Set Value dialog, and click OK.
    __ e. Now the Variables view should have the three renewRequested variables at
          false, false, true as desired.
    __ f.   Click Step Over to execute the patron.renew instruction.
    __ g. Back in the Variables view, you should see that elementData[1] has
          renewMessage= "&nbsp;". Meaning this copy did not get renewed
          unnecessarily.
    __ h. Click the Resume button twice to finish executing the servlet.
    __ i.   Switch to the Web browser and the following screen should show. This is the
            correct behavior for renewing the third item.




8-18 Developing Web Applications                                                  © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty   8.5. Fix the Mistake
          By setting the renewRequested variable to false for the non-selected LoanedCopy
          elements, you corrected the logic error in the debugging session.
          To implement this change in the code, you need to reset all the renewRequested
          variables to false by default.
          __ 12. One way to do this is to add the line copy.setRenewRequested(false); at the
                 end of the first while loop of the markRenew method. The change should look like
                 the following.




          __ 13. Save the changes.

                      Note

          The new class should be automatically republished by the server.
          There is no need to manually restart the server or application.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application       8-19
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide



8.6. Step-by-Step Debugging
__ 14. Perform Step-by-Step debugging.
    __ a. Open the Breakpoints view (on the same tab set as the Variables view), and
          clear all of the check boxes to temporarily disable the breakpoints.




    __ b. Click on the listitems tab to select the Web browser, type
          http://localhost:9080/Library/search.jsp in the address bar, press
          ENTER.
    __ c. In the search page, enter dv@bogus.ibm.com in Search Phrase, select
          E-mail, and click Search. The list items page should now be loaded in the
          browser.
    __ d. In the Web browser, select all three books for renewal, and click Renew.
    __ e. In the Debug view, select the root element WebSphere Application Server
          v6.1, and click the Enable Step-by-Step Mode icon.




    __ f.   In the Web browser, leave all of the check boxes clear, and click Renew.




8-20 Developing Web Applications                                                  © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty       __ g. A Step-by-Step Debug dialog appears asking you whether to step into the
                    com.ibm.library.servlets.RenewItems.doPost method. Select Step
                    into, and click OK.




              __ h. The execution should now be halted on the processRequest(req, resp);
                    line of the doPost method.
              __ i.   Scroll down the page to line 90, session.setAttribute("itemList",
                      loanList);. Highlight the line and select Run to Line to move the execution
                      just before the session attribute is set.
              __ j.   In the Variables view, examine the content of loanlist. The renewMessage
                      and renewRequested variables should have the values of &nbsp and false.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application       8-21
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide


            Having these results means that the previous logical error of submitting empty
            check boxes has been fixed.




    __ k. Click the Resume button in Debug view to continue execution.
__ 15. Debug a JSP page.




8-22 Developing Web Applications                                                  © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.
V4.1
                                                                                                   Instructor Exercises Guide



EXempty       __ a. A Step-by-Step Debug dialog appears again, asking whether to step into
                    com.ibm._jsp._listitems._jspService. Select Step Into and click OK
                    to step into the JSP page.




              __ b. The JSP page listitems.jsp is loaded in the editor. Click Step Over twice to
                    reach the <jsp:getProperty> tag.
              __ c. Notice in the Variables view, a PATRON object becomes available as a result of
                    the <jsp:useBean> tag.




              __ d. Click Resume to continue executing the JSP page.




          © Copyright IBM Corp. 2004, 2007                                    Exercise 8. Debug a Web Application       8-23
                                      Course materials may not be reproduced in whole or in part
                                             without the prior written permission of IBM.
Instructor Exercises Guide


    __ e. Switch to the Web browser, there should be no messages under the Renew
          Status column.




__ 16. Stop the Server. In the Servers view, right-click the server and select Stop.

End of exercise




8-24 Developing Web Applications                                                  © Copyright IBM Corp. 2004, 2007
                             Course materials may not be reproduced in whole or in part
                                    without the prior written permission of IBM.

More Related Content

PDF
Lab 2) develop a java application
PDF
Lab 4) working with databases
PDF
Lab 6) package and deploy a j2 ee application
PDF
Lab 5b) create a java server faces application
PDF
How to deploy a j2ee application
PDF
Part 2 java development
PDF
Tutorial for netbeans
PDF
Part 1 workbench basics
Lab 2) develop a java application
Lab 4) working with databases
Lab 6) package and deploy a j2 ee application
Lab 5b) create a java server faces application
How to deploy a j2ee application
Part 2 java development
Tutorial for netbeans
Part 1 workbench basics

What's hot (20)

PDF
Lab4 RTC Builds
PDF
EMC Documentum xCP 2.0 Design Patterns
PDF
EMC Documentum - xCP 2.x Troubleshooting
PDF
Lab3 RTC Source Control
PDF
Lab2 RTC Work Items
PDF
Lab1 RTC Overview
PPS
Dacj 2-2 a
PDF
EMC Documentum xCP 2.x Tips for application migration v1.1
PPT
Module 3: Working with Jazz Source Control
PPT
Module 2: Managing Work Items in Rational Team Concert
DOC
Resource lab
PDF
Java EE 7 Recipes
PDF
Tutorial: Create a custom work item in Rational Team Concert
PDF
Create software builds with jazz team build
PDF
Business Solutions Using Office Share Point Server2007
PDF
Portal at the Speed of Light
PDF
Migration & upgrades best practice upgrade pathways to emc documentum 7
PDF
Lab5 RTC reports and Dashboards
PPT
9.16.2013 Enlightenment Series - Managing parallel development with RTC: A st...
PPT
PowerPoint Presentation
Lab4 RTC Builds
EMC Documentum xCP 2.0 Design Patterns
EMC Documentum - xCP 2.x Troubleshooting
Lab3 RTC Source Control
Lab2 RTC Work Items
Lab1 RTC Overview
Dacj 2-2 a
EMC Documentum xCP 2.x Tips for application migration v1.1
Module 3: Working with Jazz Source Control
Module 2: Managing Work Items in Rational Team Concert
Resource lab
Java EE 7 Recipes
Tutorial: Create a custom work item in Rational Team Concert
Create software builds with jazz team build
Business Solutions Using Office Share Point Server2007
Portal at the Speed of Light
Migration & upgrades best practice upgrade pathways to emc documentum 7
Lab5 RTC reports and Dashboards
9.16.2013 Enlightenment Series - Managing parallel development with RTC: A st...
PowerPoint Presentation
Ad

Similar to Lab 7a) debug a web application (20)

PDF
Lab 7b) test a web application
PDF
Lab 5a) create a struts application
PDF
Part 6 debugging and testing java applications
PDF
Lab 3) create a web application
PDF
Part 3 web development
PDF
F7 wc9 zu3701lsg_ai
DOC
Resourceslab fixed
PDF
Part 5 running java applications
PDF
Business Solutions Using Office Share Point Server2007
PDF
os-php-wiki5-a4
PDF
os-php-wiki5-a4
PDF
Tivoli perfviewer
PDF
Bea weblogic job_interview_preparation_guide
PDF
Free EJB Tutorial | VirtualNuggets
DOC
Security lab
PPTX
Modular enablement
PDF
Installing ibm tivoli directory server v6.0 (web sphere partner gateway v6.1 ...
PDF
Building-with-React-Native-Dont-Make-These-Mistakes.pdf
PDF
WebLogic FAQs
PDF
Refresh controller
Lab 7b) test a web application
Lab 5a) create a struts application
Part 6 debugging and testing java applications
Lab 3) create a web application
Part 3 web development
F7 wc9 zu3701lsg_ai
Resourceslab fixed
Part 5 running java applications
Business Solutions Using Office Share Point Server2007
os-php-wiki5-a4
os-php-wiki5-a4
Tivoli perfviewer
Bea weblogic job_interview_preparation_guide
Free EJB Tutorial | VirtualNuggets
Security lab
Modular enablement
Installing ibm tivoli directory server v6.0 (web sphere partner gateway v6.1 ...
Building-with-React-Native-Dont-Make-These-Mistakes.pdf
WebLogic FAQs
Refresh controller
Ad

More from techbed (18)

PDF
1456.base boot
PDF
1455.ata atapi standards - 1-7
PDF
1454.ata features
PPT
1432.encoding concepts
PDF
Flash cs4 tutorials_2009
PDF
Photoshop tut
PDF
What is struts_en
PDF
Part 7 packaging and deployment
PDF
First java-server-faces-tutorial-en
PDF
Part 4 working with databases
PDF
Lab 1) rad installation
PPT
6) debugging and testing
PPT
7) packaging and deployment
PPT
5) running applications
PPT
4) databases
PPT
3) web development
PPT
2009 ibm academic initiative
PPT
2) java development
1456.base boot
1455.ata atapi standards - 1-7
1454.ata features
1432.encoding concepts
Flash cs4 tutorials_2009
Photoshop tut
What is struts_en
Part 7 packaging and deployment
First java-server-faces-tutorial-en
Part 4 working with databases
Lab 1) rad installation
6) debugging and testing
7) packaging and deployment
5) running applications
4) databases
3) web development
2009 ibm academic initiative
2) java development

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PDF
RMMM.pdf make it easy to upload and study
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Classroom Observation Tools for Teachers
PDF
Trump Administration's workforce development strategy
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Computing-Curriculum for Schools in Ghana
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
VCE English Exam - Section C Student Revision Booklet
RMMM.pdf make it easy to upload and study
2.FourierTransform-ShortQuestionswithAnswers.pdf
Anesthesia in Laparoscopic Surgery in India
Classroom Observation Tools for Teachers
Trump Administration's workforce development strategy
Final Presentation General Medicine 03-08-2024.pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
A systematic review of self-coping strategies used by university students to ...
O5-L3 Freight Transport Ops (International) V1.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Computing-Curriculum for Schools in Ghana
Weekly quiz Compilation Jan -July 25.pdf
Final Presentation General Medicine 03-08-2024.pptx
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Chinmaya Tiranga quiz Grand Finale.pdf
Orientation - ARALprogram of Deped to the Parents.pptx

Lab 7a) debug a web application

  • 1. V4.1 Instructor Exercises Guide EXempty Exercise 8. Debug a Web Application Estimated time 00:45 What this exercise is about In this exercise, you debug the Web application running in the integrated test environment. IBM Rational Application Developer (V7 and later) includes an integrated testing and debugging environment that can be used to debug J2EE applications. What you should be able to do At the end of the exercise, you will be able to: • Set up the Test Environment for debugging • Debug the application in Rational Application Developer Introduction The J2EE application that is debugged in this exercise is the library book renewal application. It is composed of a Web application with an associated Java utility module. Before the application can be debugged, the server needs to be started in debug mode. Requirements This exercise requires that the library Web project be implemented (Labs 1-4) and the library database installed (Lab 1). If the earlier labs were not completed, import the <LAB_FILES>DatabasesolutionDatabaseSolution.zip file. The library database needs to be re-installed, but this will be done as part of this exercise. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-1 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 2. Instructor Exercises Guide Instructor exercise overview In this exercise students will discover an error into the library enterprise application, and will use the debugging features of IBM Rational Application Developer to find the source of the error. Students discover that renewals are being processed even if no renewal period was requested. This is caused by the renewRequested variable keeping a value of true once it has been set. The solution is to add a line of code to reset the variable to false as soon as the request has been processed. Students reset the LIBRARY Apache Derby database to its initial state. They then run the application in order to discover the problem. The server is restarted in debug mode, breakpoints are added, and the students uses the Step Over, Step Into and Step Return options to view the execution. Once the problem has been fixed by adding the line of code, the Step-by-Step debug mode is used to check that the solution works. 8-2 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 3. V4.1 Instructor Exercises Guide EXempty Exercise instructions Preface Open the workspace and if necessary import the required projects (they will already be there if you are continuing from the previous lab). The following reference in the exercise instructions represents the directory location in your workstation: • <LAB_FILES>: C:LabFiles70 © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-3 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 4. Instructor Exercises Guide 8.1. Prepare the Workspace The workspace used in the previous lab (Connecting to a Database) should be used as the starting point for this lab. If you skipped labs 1, 3 or 4, perform follow the instructions: __ 1. Start Rational Application Developer. __ a. In the Workspace Launcher dialog, specify <LAB_FILES>workspace as the new workspace directory. __ b. Click OK to open the workspace. __ c. Import the <LAB_FILES>DatasolutionDatabaseSolution.zip file. If you need assistance, refer to the instructions in the Appendix, Install the Library Application in a New Workspace. 8-4 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 5. V4.1 Instructor Exercises Guide EXempty 8.2. Reset the Database to Its Default Values __ 2. Ensure that the Server is stopped, because the Derby database can only serve one client. When the server is running, the data source is the client, so no other program can access the database. __ a. Open the Servers view by selecting Window Show View Servers. __ b. In the Servers view, make sure that the WebSphere Application Server V6.1 status is Stopped. If the status is Started, right-click the server and select Stop to stop the server. __ 3. Run SetUpLibraryDatabase.java. __ a. In the Project Explorer view, expand LibraryDatabaseSetup driver. __ b. Right-click SetUpLibraryDatabase.java and select Run As Java Application. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-5 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 6. Instructor Exercises Guide __ c. The result should be displayed in the Console view. __ d. The message indicates that the library database has successfully reverted to its original values. 8-6 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 7. V4.1 Instructor Exercises Guide EXempty 8.3. Discover the Problem with Consecutive Check Outs __ 4. Search for the Patron with e-mail [email protected]. __ a. In the Project Explorer, expand LibraryWeb WebContent. __ b. Right click search.jsp and select Run As Run on Server. __ c. Once the server has started and the search page is loaded in the Web browser, enter [email protected] as the Search Phrase and select E-mail as the Criteria. __ d. Click Search. __ 5. Perform consecutive renewal for a different set of items. __ a. In the search result page, take note of the due date for the items, then select the first and second check box. __ b. Click Renew. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-7 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 8. Instructor Exercises Guide Note Results may vary, based upon the date the database was last refreshed and the date when Renew is clicked. This applies to all subsequent results displayed in this lab. __ c. The first two items are updated with Renewal Status, and the Due Date for the second book has been extended. Select the third check box, leaving the first two items unchecked. __ d. Click Renew again. __ e. Notice this time, even though the second item was not selected for Renewal, the minute recorded for the transaction time has been extended again. As well, the first item still shows the Maximum number of renewals exceeded message when it was not requested for renewal. __ f. This time leave all the check boxes cleared, and click Renew twice. The following screen appears. Notice the second item is declared to exceed the 8-8 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 9. V4.1 Instructor Exercises Guide EXempty maximum number of renewals even though it was never selected for renewal after the first trial. __ g. Clearly, submitting the form several times consecutively produces logical errors in the program. You will now debug this application to determine the cause of the error. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-9 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 10. Instructor Exercises Guide 8.4. Debug the Application __ 6. In order to duplicate the scenario, you must reset the database to its default values. You can do so by following the instructions outlined in Section 7.2. __ 7. Restart the WebSphere Application Server in debug mode. __ a. Open the Servers view. __ b. Right-click the WebSphere Application Server V6.1 entry and select Debug if the server is stopped or Restart Debug if the server is already running. __ c. When the server has restarted, you will notice the status of the server now indicates that the server is running in debug mode. __ 8. Since the logic error occurs when renewing the items, the error is likely to be in the RenewItems servlet or in an object called from that servlet. Set breakpoints in the RenewItems servlet. __ a. In the Project Explorer view, navigate to LibraryWeb Java Resources: src com.ibm.library.servlets. __ b. Double-click RenewItems to open it in the editor. __ c. The logic in RenewItems is concentrated in the processRequest method. So the breakpoint should be set inside that method. Further examining of the method reveals that the first few statements are general setup statements. They should not cause any problems. The breakpoint should therefore be placed at the first statement in the try block. __ d. Type CTRL-L and enter 74 in the Go to Line dialog to reach the following statement: Collection loanList = (Collection)session.getAttribute("itemList"); 8-10 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 11. V4.1 Instructor Exercises Guide EXempty __ e. Double-click the vertical ruler on the left of the editor, next to line 74 of the code, to set a breakpoint at this line. A breakpoint marker now appears on the mark bar. __ f. A good practice when debugging is to set breakpoints further down in the source than your original stopping point. This way, when you determine the problem is not in the section you are currently debugging, you can click the run button to skip to the next breakpoint without stopping. Scroll down to line 91 (you can use CTRL-L) and place a breakpoint beside the following statement: context.getRequestDispatcher("/listitems.jsp").forward(req, resp); __ 9. Debug the Library application on the server. __ a. In the Project Explorer view, expand LibraryWeb WebContent. __ b. Right-click search.jsp and select Debug As Debug on Server from the pop-up menu. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-11 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 12. Instructor Exercises Guide __ c. Once the search page shows up in the browser, enter [email protected] as the Search Phrase and select E-mail as the Criteria. Click Search. __ d. The item list page now shows up. Select the first and second item, and click Renew. __ e. When asked to switch to the Debug perspective, click Yes. __ f. The RenewItems servlet is triggered and the first breakpoint is hit. Click the RenewItems.java tab and scroll to line 74, the breakpoint line is highlighted. 8-12 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 13. V4.1 Instructor Exercises Guide EXempty __ g. You know the renewal process is fine the first time, so you can skip over to the next breakpoint by clicking the Resume button in the Debug view. __ h. With the current execution halted on the context.getRequestDispatcher statement, you can examine the variables resulting from the previous statements. __ i. In the Variables view, expand loanList elementData [0], and note the renewAccomplished, renewMessage, and renewRequested variables. Those are the ones of interest to this debugging session. __ j. Expand element [1] and [2] in the elementData array and examine their fields. Notice that the renewRequested variable is set to true, true, false for the three items in the array. __ k. Click the Resume button run the servlet to completion. __ l. Switch to the Web browser, it should now display the Renewal Status for the first two items. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-13 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 14. Instructor Exercises Guide __ m. Select the third row, and leave the first two rows clear. Click Renew. __ n. The debugger should take you to the first breakpoint in RenewItems.java again. __ 10. Use the various Step commands to examine the variables in the servlet. Note that loanList is not yet declared. __ a. Click Step Over in the Debug view toolbar to go to the next statement in the processRequest method. __ b. Now loanList should appear in the Variables view. Expand it to examine the items in the list. Notice for elementData[0], the renewRequested value is still set to true. 8-14 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 15. V4.1 Instructor Exercises Guide EXempty Note Note that the ids in the previous Variables view, will vary between executions and workspaces. __ c. Click the Step Over button to step over the statement String[] renewList = req.getParameterValues("RENEW_ITEM");. __ d. Examine the renewList variable in the Variables view. It should just contain one element, and that element has a value of 4. __ e. With the execution halted on the markRenewed method, click Step Into in the Debug view to move the execution to the first line of the markRenewed method. __ f. In the markRenewed method, highlight the line if (Integer.valueOf(renewList[i]).intValue() == itemId) { Right-click it and select Run to Line to move the execution to this particular statement. __ g. You can also evaluate the current if statement without stepping over it. Open the Display view by selecting Window Show View Display. Copy and paste the if statement Integer.valueOf(renewList[i]).intValue() == itemId to the Display view. Highlight the expression in Display view and select Display from the pop-up menu. The result should be displayed on the next line. The value false means that the first item does not match the renew list. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-15 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 16. Instructor Exercises Guide __ h. Back in the RenewItems.java editor, highlight the line copy.setRenewRequested(true);. Right-click it and select Run to Line. __ i. In the Variables view, expand copy = LoanedCopy to see that its itemId matches the itemId local variable. __ j. Click Step Return in the Debug view to return the execution back to the processRequest method. __ k. The Debug Current Instruction Pointer should now point to the patron.renew(loanList); line. This instruction will execute the renew command on database, so you need to make sure the data passed in are setup correctly. __ 11. Change the variable values in a debugging session. __ a. In the Variables view, expand loanList elementData [0], [1], [2]. Notice that the renewRequested variable is set to true, true, true for the three 8-16 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 17. V4.1 Instructor Exercises Guide EXempty LoanedCopy elements. Since you only requested that the third book be renewed, the correct values should be false, false, true. __ b. Right-click the renewRequested variable under elementData [0] and select Change Value. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-17 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 18. Instructor Exercises Guide __ c. In the Set Value dialog, enter false. Click OK. __ d. Similarly, right-click elementData [1] renewRequested and select Change Value. Enter false in the Set Value dialog, and click OK. __ e. Now the Variables view should have the three renewRequested variables at false, false, true as desired. __ f. Click Step Over to execute the patron.renew instruction. __ g. Back in the Variables view, you should see that elementData[1] has renewMessage= "&nbsp;". Meaning this copy did not get renewed unnecessarily. __ h. Click the Resume button twice to finish executing the servlet. __ i. Switch to the Web browser and the following screen should show. This is the correct behavior for renewing the third item. 8-18 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 19. V4.1 Instructor Exercises Guide EXempty 8.5. Fix the Mistake By setting the renewRequested variable to false for the non-selected LoanedCopy elements, you corrected the logic error in the debugging session. To implement this change in the code, you need to reset all the renewRequested variables to false by default. __ 12. One way to do this is to add the line copy.setRenewRequested(false); at the end of the first while loop of the markRenew method. The change should look like the following. __ 13. Save the changes. Note The new class should be automatically republished by the server. There is no need to manually restart the server or application. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-19 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 20. Instructor Exercises Guide 8.6. Step-by-Step Debugging __ 14. Perform Step-by-Step debugging. __ a. Open the Breakpoints view (on the same tab set as the Variables view), and clear all of the check boxes to temporarily disable the breakpoints. __ b. Click on the listitems tab to select the Web browser, type http://localhost:9080/Library/search.jsp in the address bar, press ENTER. __ c. In the search page, enter [email protected] in Search Phrase, select E-mail, and click Search. The list items page should now be loaded in the browser. __ d. In the Web browser, select all three books for renewal, and click Renew. __ e. In the Debug view, select the root element WebSphere Application Server v6.1, and click the Enable Step-by-Step Mode icon. __ f. In the Web browser, leave all of the check boxes clear, and click Renew. 8-20 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 21. V4.1 Instructor Exercises Guide EXempty __ g. A Step-by-Step Debug dialog appears asking you whether to step into the com.ibm.library.servlets.RenewItems.doPost method. Select Step into, and click OK. __ h. The execution should now be halted on the processRequest(req, resp); line of the doPost method. __ i. Scroll down the page to line 90, session.setAttribute("itemList", loanList);. Highlight the line and select Run to Line to move the execution just before the session attribute is set. __ j. In the Variables view, examine the content of loanlist. The renewMessage and renewRequested variables should have the values of &nbsp and false. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-21 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 22. Instructor Exercises Guide Having these results means that the previous logical error of submitting empty check boxes has been fixed. __ k. Click the Resume button in Debug view to continue execution. __ 15. Debug a JSP page. 8-22 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 23. V4.1 Instructor Exercises Guide EXempty __ a. A Step-by-Step Debug dialog appears again, asking whether to step into com.ibm._jsp._listitems._jspService. Select Step Into and click OK to step into the JSP page. __ b. The JSP page listitems.jsp is loaded in the editor. Click Step Over twice to reach the <jsp:getProperty> tag. __ c. Notice in the Variables view, a PATRON object becomes available as a result of the <jsp:useBean> tag. __ d. Click Resume to continue executing the JSP page. © Copyright IBM Corp. 2004, 2007 Exercise 8. Debug a Web Application 8-23 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  • 24. Instructor Exercises Guide __ e. Switch to the Web browser, there should be no messages under the Renew Status column. __ 16. Stop the Server. In the Servers view, right-click the server and select Stop. End of exercise 8-24 Developing Web Applications © Copyright IBM Corp. 2004, 2007 Course materials may not be reproduced in whole or in part without the prior written permission of IBM.