Internet Technologies:cxp

Debugging a CXP page Foundation

In this chapter you will learn how to debug an CXP based Web application.

Overview

When executing a Web target via the Shift+F9 shortcut, a Web browser instance is started to load the default CXP page associated with the target. This generates an implicit request which generates the HTML code for the page using the CXP infrastructure. The HTML code is then displayed in the Web browser.

Debugging a CXP page occurs in a similar fashion. The CXP page is first loaded into a Web browser instance created for this purpose. However, the CXP application is also loaded into the debugger, so that the Xbase++ code which runs inside the CXP page can be analyzed. For example, breakpoints can be set to halt execution at certain locations in the code so that variable field values can be examined at runtime.

A Web application consists of several elements:

The application front-end running in the Web browser
The application code running in the CXP page
Potential intermediate layers, such as a Web server.

Unlike with a monolithic desktop application, only some of these elements are under application control and hence are accessible from within the development tool. For example, only the Xbase++ code which executes inside a CXP page can be debugged in the Xbase++ Workbench. The application front-end running inside the Web browser cannot be analyzed this way.

The HTML and Javascript code making up the application front-end cannot be debugged inside the Xbase++ Workbench. The tools provided in the browser or some other means must be used to do this.

Example

The following paragraphs outline the basic steps required for debugging a CXP page.

1 Start the administrator version of the Xbase++ Workbench ("Xbase++ Workbench (Admin)".

Web servers are often installed so that administrator privileges are required for changing files located in the site root (document root) folder of your website. The administrator version of the version Workbench is started with elevated privileges, allowing you to access your files even if the site root folder is inaccessible to normal users.

2 Create an empty Web page project by choosing File -> New -> Web Target, and select Empty Web Pagein the list that is shown. Specify "debug_test" as the name for the new project. Click OK to have the project created for you.

3 Open the CXP page in source code editor. To do this, double-click on the .CXP file which is now shown in Project Manager. The file is named something like default1.cxp.

4 Locate the <body> element in the HTML code and add Xbase++ code for displaying the famous "hello World" legend a couple of times. Your <body> element should now look like this:

<body> 
<!--- Page content goes here ---> 
<% 
 c := "Hello World" 
 FOR i:=1 TO 5 
    ? c 
 NEXT 
%> 
</body> 

5 Press F8 to load the CXP into the debugger. A new Web browser window opens to load the page. In addition, the debugger cursor should be displayed next to the first line which you've entered. Take a minute to familiarize yourself with the information that is presented.

6 Press F5 to set a breakpoint on the line containing the opening statement of the FOR loop. The line should now be marked as a breakpoint with a different background color and a little red bullet placed next to the line number.

7 Press F9 to continue executing the page. "Hello World" should now appear in the Web browser window.

Some Web browsers display an error message if the application does not respond within a certain timeframe. This is an operating system setting and does not imply something is wrong with your CXP page. Simply proceed to the next step if you see a "page cannot be loaded" message.

8 Press F5 in the Web browser or use the respective browser command to reload the page. This generates another request for the CXP page and execution should again stop at the breakpoint that was set in step 5 above.

9 Press F8 repeatedly to step through the FOR loop which you've coded in your page. Note how the value of the variable i increases with each iteration. Also note that no output becomes visible in the Web browser yet. This is because you are debugging the code which generates a HTML response which is sent back to the Web browser once your page code exits.

10 When you are done debugging the demo page, press Ctrl+F2 to reset the program and end the debugging session. Notice that the browser window which was opened at the beginning of the debugging is closed automatically when your application is terminated.

Prerequisites

By default, the system starts an instance of the standard Web browser configured for the computer to load a CXP page for execution and for debugging. This reflects the user's choice and should be suitable for development in most cases. However, a different browser application may need to be used in some cases. For example, company policy sometimes dictates usage of a certain Web browser, which then may have to be used for development and testing. In this case, the corresponding executable must be specified in the environment options of the Workbench, see Tools -> Environment Options -> Web Applications.

When debugging a Web target, the development Web server uses a certain port for communicating with the Web browser. If this port is already in use by another application or if the port is blocked by the system's firewall, an alternate port must be configured for the debugger, see Tools -> Debugger Options -> Web Applications.

The default Web browser application on the Windows platform is Microsoft Internet Explorer. If another Web browser is configured for executing Web targets, care must be taken to specify the correct parameters to ensure that only a single instance (process) is created per browser window. Some Web browsers off-load processing to newly spawned processes which may break the binding to a debugging session. Debugging may not work correctly in this case. Please consult the documentation of your Web browser to learn more about the available command line parameters.

Debugging CXP pages on other devices

In order to initiate a debugging session on a development machine, the Workbench first creates a Web browser instance to load the CXP page associated with the respective target. The resulting page request then causes debugging to commence once execution steps into the page code.

If the front-end of a CXP application runs on another device such as a smartphone, however, the client browser no longer is under the control of the Xbase++ Workbench. In this case, the page request initiating the debugging session must be issued on the device itself. To do this, the URL of the initial CXP page may have to be entered into the address bar of the client browser, or the page request must be triggered via some other means. The URL for loading a CXP page into the debugger has the following form:

http://<machine name>:5000/<CXP page> 

Example: http://W8-VM:5000/cxpinfo.cxp 

In addition, the normal spawning of a new Web browser instance must be switched off. To do this, uncheck the appropriate check box in the debugger options, see Tools -> Debugger Options -> Web Applications.

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.