debugging portal applications

24
Debugging Portal Applications SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 1 Debugging Portal Applications Applies to: SAP NetWeaver Portal, and developers of portal applications Summary NetWeaver Developer Studio and the AS Java provide tools for helping you debug your applications. This document provides the very basics on starting to debug applications, and provides a short, simple but clear example on how the debugging tools can be used. Author: Daniel Wroblewski Company: SAP AG Created on: 18 July 2007 Author Bio Daniel Wroblewski is an information developer for SAP, focusing on documentation for portal developers. He has been a developer ever since writing assembler code for the new Apple Macintosh in 1985 (that was cool), and was a developer for Deutsche Bank (Java, VB). He plays center for the SAP Labs Israel basketball team.

Upload: campeador2012

Post on 15-Sep-2015

234 views

Category:

Documents


0 download

DESCRIPTION

.

TRANSCRIPT

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 1

    Debugging Portal Applications

    Applies to: SAP NetWeaver Portal, and developers of portal applications

    Summary NetWeaver Developer Studio and the AS Java provide tools for helping you debug your applications. This document provides the very basics on starting to debug applications, and provides a short, simple but clear example on how the debugging tools can be used. Author: Daniel Wroblewski Company: SAP AG Created on: 18 July 2007

    Author Bio

    Daniel Wroblewski is an information developer for SAP, focusing on documentation for portal developers. He has been a developer ever since writing assembler code for the new Apple Macintosh in 1985 (that was cool), and was a developer for Deutsche Bank (Java, VB). He plays center for the SAP Labs Israel basketball team.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 2

    Table of Contents Overview.......................................................................................................................................... 3 Collecting Required Information ...................................................................................................... 4

    Message Server Port ................................................................................................................... 5 Debug Port ................................................................................................................................... 6

    Enabling Debugging ........................................................................................................................ 9 Setting the AS Java ....................................................................................................................... 10 Starting Debugging ........................................................................................................................ 12 Debugging...................................................................................................................................... 14

    Set Breakpoints.......................................................................................................................... 14 Inspect Variables........................................................................................................................ 15 Add Watches.............................................................................................................................. 16

    Example......................................................................................................................................... 17 Open Portal Project.................................................................................................................... 18 Start Debugging ......................................................................................................................... 19 Run the Application .................................................................................................................... 21

    Related Content............................................................................................................................. 23 Copyright........................................................................................................................................ 24

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 3

    Overview The debugging tools of the AS Java and NetWeaver Developer Studio can help a lot in locating problems with your applications. The following are basic instructions for debugging portal applications. Also provided is a small example of how a simple NullPointerException can be diagnosed using debugging.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 4

    Collecting Required Information To use debugging, you will need to know the following information:

    Server Name: The host name for calling the portal in a browser Server Port: The port number for calling the portal in a browser Message Server Port: The port number for calling the AS Java engine, for example, from within the IDE Debug Port: The port number when starting debugging

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 5

    Message Server Port To find the message server port:

    1. Launch the AS Java home page by entering in your browser the URL http://:/ (the same as the main portal URL without the irj).

    2. Click System Information. Information about the AS Java, such as the server name, instances and ports

    numbers, is displayed. The message server port is displayed in the upper left.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 6

    Debug Port 1. Launch the Config Tool by double-clicking configtool.bat (located in the

    C:\usr\sap\\\j2ee\configtool directory).

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 7

    2. Click . The following is displayed:

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 8

    3. Navigate to cluster_data, and click Propertysheet. A table of properties is displayed.

    The debug port is listed under DebugPort.

    Note:

    You can also see the debug mode in the J2EE Engine view of the NetWeaver Developer Studio (below), as well as from the Servers Debug tab when clicking on the instance in the Config Tool.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 9

    Enabling Debugging 1. Launch the Config Tool by double-clicking configtool.bat (located in the

    C:\usr\sap\\\j2ee\configtool directory). 2. Click on the instance, and select the Servers Debug tab.

    3. Make sure the debuggable and Enabled debug mode checkboxes are selected. 4. Save your changes, and restart the server.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 10

    Setting the AS Java 1. In NetWeaver Developer Studio, select the menu item Window Preferences. 2. Click SAP J2EE Engine, and enter the portal server and message port.

    3. Click OK. 4. Open up the J2EE Engine view by navigating to Windows Show View Other, and selecting J2EE

    J2EE Engine.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 11

    5. Click to refresh the view.

    You should now see the server you specified in the Preferences window, with the colors of the nodes indicating the servers status. The current debug mode and port are shown at right.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 12

    Starting Debugging Before starting to debug, make sure the current version of your project is deployed on the server.

    1. Select debugging by either:

    Selecting Debug under the Debug icon.

    Selecting Run Debug in the menu.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 13

    The Debug perspective is opened, and the configuration window is displayed.

    2. Select Remote Java Application, click New, and set the following:

    Project: Select the project that you want to debug. Make sure its most recent version is deployed to the server on which you are debugging.

    Server: The server on which you are debugging. Debug Port: The debug port of the server.

    3. Click Debug. You are now ready to debug.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 14

    Debugging When debugging, you set breakpoints and watches in the portal component class files, and then run your portal component by navigating in the portal to an iView from your portal component. The portal component pauses when it hits a breakpoint, and the Debug view shows where you are in the component. You can step over or into your code, and inspect variables, functions and expressions.

    Set Breakpoints 1. Make sure the class file that you want to debug is open. You can open it from Enterprise Portal

    perspective before debugging. 2. Set a breakpoint by double-clicking at the start of the line.

    Below, a breakpoint is set on the first line of code in the doContent() method:

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 15

    Inspect Variables When the debugger has stopped at a breakpoint, you can inspect all the local variables, in the Variables window.

    The variables in the window are those defined in the doContent() method up to the breakpoint.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 16

    Add Watches You specify variables, expressions and functions to a watch list to help you monitor them. The watch list is shown in the Expressions window.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 17

    Example I have written a test portal component (HelloWorldProject.testLink) that takes a parameter with a navigation target and creates a link from it. The component tests to see if the parameter starts with the string pcd but, of course, if the parameter is null, the component will crash. The code is as follows:

    public void doContent(IPortalComponentRequest request, IPortalComponentResponse response) { String target = request.getParameter("myTarget"); if (target.startsWith("pcd")) { response.write("Starts With PCD"); } // Rest of code } And the iView displays the following when no parameter is sent. The exception is caught by the Portal Runtime.

    At first, I do not know why it crashes (and I did not provide any exception handling for the sake of this example). So I choose to debug.

    In this example, I assume that debug mode is turned on for the server. To turn on debug mode, see Enabling Debugging.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 18

    Open Portal Project Open the portal project that you want to debug, and open the Java editor for the class file that contains the code to debug.

    The following shows the HelloWorldProject, with the testLink class that contains the code to debug. The J2EE Engine view is shown at the bottom right.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 19

    Start Debugging 1. Click Run Debug. 2. Select Remote Java Application, and click New. 3. Enter HelloWorldProject for the project, and enter the server and port.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 20

    4. Click Debug. The Debug perspective opens.

    A list of threads is displayed in upper left, and windows for displaying breakpoints and watches are displayed in the upper right.

    My code is also displayed in the middle.

    5. Create a breakpoint for the first line in the doContent() method.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 21

    Run the Application 1. Now I open the portal and run my iView.

    As soon as I click on the link to my iView (testLink), the debugger in the NetWeaver Developer Studio comes to life, the Debug perspective opens, and the execution stops at my breakpoint.

    The line is highlighted and an arrow is displayed next to the line.

    2. I step through the first statement, by clicking Run Step Over or pressing F6.

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 22

    3. I check the variables, and notice that target is null.

    4. I step through the next statement, and the component crashes. At the very least, I learn the statement

    that caused the crash.

    I can also check the log at this point and see that a NullPointerException caused the problem. #1.5#000BCDDCE9DE00700000000800000E2C00043584CF3F6D20#1184744435504#com.sap.portal.portal#sap.com/irj#com.sap.portal.portal#Administrator#35#####Thread[PRT-Async 3,5,PRT-Async]##0#0#Error#1#/System/Server#Java###Exception ID:07:40_18/07/07_0005_4070150 [EXCEPTION] {0}#1#com.sapportals.portal.prt.component.PortalComponentException: Error in service call of Portal Component Component : pcd:portal_content/DanielContent/DanRole/testLink Component class : testLink User : Administrator at com.sapportals.portal.prt.core.PortalRequestManager.handlePortalComponentException(PortalRequestManager.java:969) at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:343) at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136) at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189) at com.sapportals.portal.prt.core.async.AsyncPortalComponentResponse.include(AsyncPortalComponentResponse.java:355) at com.sapportals.portal.prt.core.async.AsyncPortalComponentResponse.include(AsyncPortalComponentResponse.java:310) at com.sapportals.portal.navigation.workAreaiView.doContent(workAreaiView.java:169) at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209) at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114) at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328) at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136) at com.sapportals.portal.prt.core.async.AsyncIncludeRunnable$1$DoDispatchRequest.run(AsyncIncludeRunnable.java:377) at java.security.AccessController.doPrivileged(Native Method) at com.sapportals.portal.prt.core.async.AsyncIncludeRunnable.run(AsyncIncludeRunnable.java:390) at com.sapportals.portal.prt.core.async.ThreadContextRunnable.run(ThreadContextRunnable.java:164) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:729) at java.lang.Thread.run(Thread.java:534) Caused by: java.lang.NullPointerException at testLink.doContent(testLink.java:16) at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209) at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114) at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328) ... 15 more

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 23

    Related Content Debugging J2EE Applications Debugging Tools: Log Watch, Navigation Reporter and Navigation Debugger (SAP NetWeaver 7.0

    only)

  • Debugging Portal Applications

    SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2007 SAP AG 24

    Copyright Copyright 2007 SAP AG. All rights reserved.

    No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.

    Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

    Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.

    IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation.

    Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.

    Oracle is a registered trademark of Oracle Corporation.

    UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

    Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.

    HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology.

    Java is a registered trademark of Sun Microsystems, Inc.

    JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.

    MaxDB is a trademark of MySQL AB, Sweden.

    SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

    These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.

    These materials are provided as is without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.

    SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials.

    SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages.

    Any software coding and/or code lines/strings (Code) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.

    Applies to:SummaryAuthor BioTable of ContentsOverviewCollecting Required InformationMessage Server PortDebug Port

    Enabling DebuggingSetting the AS JavaStarting DebuggingDebuggingSet BreakpointsInspect VariablesAdd Watches

    ExampleOpen Portal ProjectStart DebuggingRun the Application

    Related ContentCopyright