source: trunk/docs/services/howtos.txt @ 396

Last change on this file since 396 was 396, checked in by lucadelu, 11 years ago

improve documentation for python services

  • Property svn:eol-style set to native
  • Property svn:keywords set to HeadURL Date Author Id Rev
  • Property svn:mime-type set to text/plain
File size: 5.1 KB
Line 
1.. _services-howtos:
2
3How To Setup ZOO Services
4=========================
5
6:Authors: Nicolas Bozon, Gérald Fenoy, Jeff McKenna
7:Last Updated: $Date: 2013-03-26 16:10:36 +0000 (Tue, 26 Mar 2013) $
8
9ZOO Services are quite easy to create once you have installed the ZOO Kernel and have
10chosen code (in the language of your choice) to turn into a ZOO service. Here are some
11HelloWorlds in Python, PHP, Java  and JavaScript with links to their corresponding
12``.zcfg`` files.
13
14.. contents:: Table of Contents
15    :depth: 3
16    :backlinks: top
17
18Python
19------
20
21You'll find here information needed to deploy your own Python Services Provider.
22
23Python ZCFG requirements
24************************
25
26.. Note:: For each Service provided by your ZOO Python Services Provider, the ZCFG File
27          must be named the same as the Python module function name (also the case of
28          characters is important).
29
30The ZCFG file should contain the following :
31
32
33serviceType
34    Python
35serviceProvider
36    The name of the Python module to use as a ZOO Service Provider. For instance, if your
37    script, located in the same directory as your ZOO Kernel, was named ``my_module.py`` then
38    you should use ``my_module`` (the Python module name) for the serviceProvider value in ZCFG file.
39
40Python Data Structure used
41**************************
42
43The Python module's function to be used take three arguments: the main configuration, inputs and outputs.
44All this values are passed to the Python module as dictionaries.
45
46Following you'll find an example for each parameters
47
48Main configuration
49^^^^^^^^^^^^^^^^^^^^^
50Main configuration contains several informations, some of them are really useful to develop your service.
51Following an example ::
52
53  {
54  'main': {'lang': 'en-UK',
55           'language': 'en-US',
56           'encoding': 'utf-8',
57           'dataPath': '/var/www/tmp',
58           'tmpPath': '/var/www/tmp',
59           'version': '1.0.0',
60           'mapserverAddress': 'http://localhost/cgi-bin/mapserv',
61           'isSoap': 'false',
62           'tmpUrl': 'http://localhost/tmp/',
63           'serverAddress': 'http://localhost/zoo'
64          },
65  'identification': {'keywords': 'WPS,GIS',
66                     'abstract': 'WPS services for testing ZOO',
67                     'fees': 'None',
68                     'accessConstraints': 'none',
69                     'title': 'testing services'
70                    },
71  'lenv': {'status': '0',
72           'soap': 'false',
73           'cwd': '/usr/lib/cgi-bin',
74           'sid': '24709'
75          },
76  'env': {'DISPLAY': 'localhost:0'},
77  'provider': {'addressCountry': 'it',
78               'positionName': 'Developer',
79               'providerName': 'Name of provider',
80               'addressAdministrativeArea': 'False',
81               'phoneVoice': 'False',
82               'addressCity': 'City',
83               'providerSite': 'http://www.your.site',
84               'addressPostalCode': '38122',
85               'role': 'Developer',
86               'addressDeliveryPoint': 'False',
87               'phoneFacsimile': 'False',
88               'addressElectronicMailAddress': 'your@email.com',
89               'individualName': 'Your Name'
90              }
91  }
92
93Inputs
94^^^^^^^^^^^^
95The inputs are somethings like this ::
96
97  {
98  'variable_name': {'minOccurs': '1',
99                    'DataType': 'string',
100                    'value': 'this_is_the_value',
101                    'maxOccurs': '1',
102                    'inRequest': 'true'
103                   }
104  }
105
106The access to the value you have to require for the ``value`` parameter, something like this ::
107
108  yourVariable = inputs['variable_name']['value']
109
110Outputs
111^^^^^^^^^^^^^
112The outputs data as a structure really similar to the inputs one ::
113
114  {
115  'result': {'DataType': 'string',
116             'inRequest': 'true',
117            }
118  }
119
120There is no ``'value'`` parameter before you assign it ::
121
122  inputs['result']['value'] = yourOutputDataVariable
123
124The return statement has to be an integer: corresponding to the service status code.
125
126The module should **return 3 if the process successfully ended otherwise it should return 4**.
127To add a message for the wrong result you can add the massage to ``conf["lenv"]["message"]``,
128for example:
129
130.. code-block:: python
131
132  conf["lenv"]["message"] = 'Your module return an error'
133
134Sample ZOO Python Services Provider
135***********************************
136
137The following code represents a simple ZOO Python Services Provider which provides only one
138Service, the HelloPy one.
139
140.. code-block:: python
141
142  import sys
143  def HelloPy(conf,inputs,outputs):
144     outputs["Result"]["value"]="Hello "+inputs["a"]["value"]+" from Python World !"
145     return 3
146
147PHP
148---
149
150.. code-block:: php
151
152  <?
153  function HelloPHP(&$main_conf,&$inputs,&$outputs){
154     $outputs["Result"]["value"]="Hello ".$inputs[S][value]." from PHP world !";
155     return 3;
156  }
157  ?>
158
159Java
160----
161
162.. code-block:: java
163
164  import java.util.*;
165  public class HelloJava {
166    public static int HelloWorldJava(HashMap conf,HashMap inputs, HashMap outputs) {
167       HashMap hm1 = new HashMap();
168       hm1.put("dataType","string");
169       HashMap tmp=(HashMap)(inputs.get("S"));
170       java.lang.String v=tmp.get("value").toString();
171       hm1.put("value","Hello "+v+" from JAVA WOrld !");
172       outputs.put("Result",hm1);
173       System.err.println("Hello from JAVA WOrld !");
174       return 3;
175    }
176  }
177
178Javascript
179----------
180
181.. code-block:: javascript
182
183  function hellojs(conf,inputs,outputs){
184     outputs=new Array();
185     outputs={};
186     outputs["result"]["value"]="Hello "+inputs["S"]["value"]+" from JS World !";
187     return Array(3,outputs);
188  }
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png