1 | .. _services-debug: |
---|
2 | |
---|
3 | Debugging ZOO Services |
---|
4 | ========================= |
---|
5 | |
---|
6 | Several methods can be used in order to debug :ref:`services_index`. The most common solutions are web or command line. |
---|
7 | |
---|
8 | Web |
---|
9 | ---- |
---|
10 | |
---|
11 | Any problem can be checked in the Apache server log file when using http WPS requests. |
---|
12 | |
---|
13 | On Unix, the log files is usually located in ``/var/log/apache2`` and |
---|
14 | the relevant one is named *error_log*. A simple way to read this file is to use the ``tail`` command, |
---|
15 | as it allows to see the file updates for each request :: |
---|
16 | |
---|
17 | tail -f /var/log/apache2/error_log |
---|
18 | |
---|
19 | If the log is not clear enough, you still have the possibility to add |
---|
20 | more debug information to your source code, writing to standard errors. |
---|
21 | |
---|
22 | Python |
---|
23 | ******** |
---|
24 | Using Python, you can for example do this: |
---|
25 | |
---|
26 | .. code-block:: python |
---|
27 | |
---|
28 | import sys |
---|
29 | |
---|
30 | #add this line when you want see an own message |
---|
31 | sys.stderr.write("My message") |
---|
32 | |
---|
33 | .. _web_javascript: |
---|
34 | |
---|
35 | Javascript |
---|
36 | ************ |
---|
37 | |
---|
38 | Using JavaScript, you can use ``alert`` to print a string to standard error, for example: |
---|
39 | |
---|
40 | .. code-block:: javascript |
---|
41 | |
---|
42 | // add this line when you want to see own message |
---|
43 | alert('My message') |
---|
44 | // you can debug value of inputs, outputs or conf |
---|
45 | alert(inputs["S"]["value"]) |
---|
46 | |
---|
47 | .. note:: If you try to pass an object it will only return ``[object Object]`` |
---|
48 | |
---|
49 | Command line |
---|
50 | -------------- |
---|
51 | |
---|
52 | :ref:`kernel_index` (*zoo_loader.cgi*) can also be used from command line. This is really useful for debugging services in a deeper way, for example:. |
---|
53 | |
---|
54 | .. code-block:: bash |
---|
55 | |
---|
56 | # in order to use it you have to copy test_service.py and HelloPy.zcfg from |
---|
57 | # the example services |
---|
58 | ./zoo_loader.cgi "service=wps&version=1.0.0&request=execute&identifier=HelloPy&datainputs=a=your name&responsedocument=Result" |
---|
59 | |
---|
60 | Working this way you can use the standard debug system of the actual |
---|
61 | programming language used to develop your service. |
---|
62 | |
---|
63 | In case you should simulate POST requests, you can use the following |
---|
64 | command to tell the ZOO-Kernel to use the file ``/tmp/req.xml`` as the |
---|
65 | input XML request: |
---|
66 | |
---|
67 | .. code-block:: guess |
---|
68 | |
---|
69 | # Define required environment settings |
---|
70 | export REQUEST_METHOD=POST |
---|
71 | export CONTENT_TYPE=text/xml |
---|
72 | # Run the request stored in a file |
---|
73 | ./zoo_loader.cgi < /tmp/req.xml |
---|
74 | |
---|
75 | |
---|
76 | GDB |
---|
77 | ***** |
---|
78 | From command line you can use also the command line tool `GDB <http://www.gnu.org/software/gdb/>`_ |
---|
79 | to debug ``zoo_loader.cgi``, you have to run: |
---|
80 | |
---|
81 | .. code-block:: bash |
---|
82 | |
---|
83 | # launch zoo_loader.cgi from gdb |
---|
84 | gdb zoo_loader.cgi |
---|
85 | # now run your request |
---|
86 | run "service=wps&version=1.0.0&request=execute&identifier=HelloPy&datainputs=a=your name&responsedocument=Result" |
---|
87 | |
---|
88 | .. note:: |
---|
89 | You can use the same parameter used before to simulate POST |
---|
90 | requests when running from gdb. |
---|
91 | |
---|
92 | If nothing helped, you can ask help at the `ZOO mailing list |
---|
93 | <http://lists.osgeo.org/cgi-bin/mailman/listinfo/zoo-discuss>`_ |
---|
94 | copying the result of the command. |
---|
95 | |
---|
96 | Python |
---|
97 | ********** |
---|
98 | For Python, you can use ``pdb``, more info at http://docs.python.org/2/library/pdb.html |
---|
99 | |
---|
100 | .. code-block:: python |
---|
101 | |
---|
102 | import pdb |
---|
103 | |
---|
104 | # add this line when you want investigate your code in more detail |
---|
105 | pdb.set_trace() |
---|
106 | |
---|
107 | Javascript |
---|
108 | ************ |
---|
109 | |
---|
110 | You can use ``alert`` also to print in the console, more info in the :ref:`web_javascript` web section |
---|