source: branches/PublicaMundi_David-devel/docs/services/howtos.txt @ 544

Last change on this file since 544 was 406, checked in by lucadelu, 12 years ago

add more information about Javascript 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: 6.3 KB
Line 
1.. _services-howtos:
2
3How To Setup ZOO Services
4=========================
5
6:Authors: Nicolas Bozon, Gérald Fenoy, Jeff McKenna, Luca Delucchi
7:Last Updated: $Date: 2013-03-28 11:51:45 +0000 (Thu, 28 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
18Common informations
19----------------------
20
21The function of the process for each programming language take three arguments: the main
22configuration, inputs and outputs.
23
24.. Note:: The service has to **return 3 if the process run successfully instead it
25          return 4** if the process end with an error.
26
27Python
28------
29
30You'll find here information needed to deploy your own Python Services Provider.
31
32Python ZCFG requirements
33************************
34
35.. Note:: For each Service provided by your ZOO Python Services Provider, the ZCFG File
36          must be named the same as the Python module function name (also the case of
37          characters is important).
38
39The ZCFG file should contain the following :
40
41
42serviceType
43    Python
44serviceProvider
45    The name of the Python module to use as a ZOO Service Provider. For instance, if your
46    script, located in the same directory as your ZOO Kernel, was named ``my_module.py`` then
47    you should use ``my_module`` (the Python module name) for the serviceProvider value in ZCFG file.
48
49Python Data Structure used
50**************************
51The three parameters of the function are passed to the Python module as dictionaries.
52
53Following you'll find an example for each parameters
54
55Main configuration
56^^^^^^^^^^^^^^^^^^^^^
57Main configuration contains several informations, some of them are really useful to develop your service.
58Following an example ::
59
60  {
61  'main': {'lang': 'en-UK',
62           'language': 'en-US',
63           'encoding': 'utf-8',
64           'dataPath': '/var/www/tmp',
65           'tmpPath': '/var/www/tmp',
66           'version': '1.0.0',
67           'mapserverAddress': 'http://localhost/cgi-bin/mapserv',
68           'isSoap': 'false',
69           'tmpUrl': 'http://localhost/tmp/',
70           'serverAddress': 'http://localhost/zoo'
71          },
72  'identification': {'keywords': 'WPS,GIS',
73                     'abstract': 'WPS services for testing ZOO',
74                     'fees': 'None',
75                     'accessConstraints': 'none',
76                     'title': 'testing services'
77                    },
78  'lenv': {'status': '0',
79           'soap': 'false',
80           'cwd': '/usr/lib/cgi-bin',
81           'sid': '24709'
82          },
83  'env': {'DISPLAY': 'localhost:0'},
84  'provider': {'addressCountry': 'it',
85               'positionName': 'Developer',
86               'providerName': 'Name of provider',
87               'addressAdministrativeArea': 'False',
88               'phoneVoice': 'False',
89               'addressCity': 'City',
90               'providerSite': 'http://www.your.site',
91               'addressPostalCode': '38122',
92               'role': 'Developer',
93               'addressDeliveryPoint': 'False',
94               'phoneFacsimile': 'False',
95               'addressElectronicMailAddress': 'your@email.com',
96               'individualName': 'Your Name'
97              }
98  }
99
100Inputs
101^^^^^^^^^^^^
102The inputs are somethings like this ::
103
104  {
105  'variable_name': {'minOccurs': '1',
106                    'DataType': 'string',
107                    'value': 'this_is_the_value',
108                    'maxOccurs': '1',
109                    'inRequest': 'true'
110                   }
111  }
112
113The access to the value you have to require for the ``value`` parameter, something like this ::
114
115  yourVariable = inputs['variable_name']['value']
116
117Outputs
118^^^^^^^^^^^^^
119The outputs data as a structure really similar to the inputs one ::
120
121  {
122  'result': {'DataType': 'string',
123             'inRequest': 'true',
124            }
125  }
126
127There is no ``'value'`` parameter before you assign it ::
128
129  inputs['result']['value'] = yourOutputDataVariable
130
131The return statement has to be an integer: corresponding to the service status code.
132
133To add a message for the wrong result you can add the massage to ``conf["lenv"]["message"]``,
134for example:
135
136.. code-block:: python
137
138  conf["lenv"]["message"] = 'Your module return an error'
139
140Sample ZOO Python Services Provider
141***********************************
142
143The following code represents a simple ZOO Python Services Provider which provides only one
144Service, the HelloPy one.
145
146.. code-block:: python
147
148  import sys
149  def HelloPy(conf,inputs,outputs):
150     outputs["Result"]["value"]="Hello "+inputs["a"]["value"]+" from Python World !"
151     return 3
152
153PHP
154---
155
156.. code-block:: php
157
158  <?
159  function HelloPHP(&$main_conf,&$inputs,&$outputs){
160     $outputs["Result"]["value"]="Hello ".$inputs[S][value]." from PHP world !";
161     return 3;
162  }
163  ?>
164
165Java
166----
167
168.. code-block:: java
169
170  import java.util.*;
171  public class HelloJava {
172    public static int HelloWorldJava(HashMap conf,HashMap inputs, HashMap outputs) {
173       HashMap hm1 = new HashMap();
174       hm1.put("dataType","string");
175       HashMap tmp=(HashMap)(inputs.get("S"));
176       java.lang.String v=tmp.get("value").toString();
177       hm1.put("value","Hello "+v+" from JAVA WOrld !");
178       outputs.put("Result",hm1);
179       System.err.println("Hello from JAVA WOrld !");
180       return 3;
181    }
182  }
183
184Javascript
185----------
186
187ZOO API
188*********
189
190If you need to use :ref:`ZOO API <api>` in your service, you have first to copy ``zoo-api.js``
191and ``zoo-proj4js.js`` where your services are located (for example in Unix system probably in
192``/usr/lib/cgi-bin/``
193
194Javascript ZCFG requirements
195**********************************
196
197.. Note:: For each Service provided by your ZOO Javascript Services Provider, the ZCFG File
198          must be named the same as the Javascript function name (also the case of
199          characters is important).
200
201The ZCFG file should contain the following :
202
203serviceType
204    JS
205serviceProvider
206    The name of the JavaScript file to use as a ZOO Service Provider. For instance, if your
207    script, located in the same directory as your ZOO Kernel, was named ``my_module.js`` then
208    you should use ``my_module.js``.
209
210
211Javascript Data Structure used
212********************************
213
214The three parameters of the function are passed to the JavaScript function as Object.
215
216Sample ZOO Javascript Services Provider
217******************************************
218
219.. code-block:: javascript
220
221  function hellojs(conf,inputs,outputs){
222     outputs=new Array();
223     outputs={};
224     outputs["result"]["value"]="Hello "+inputs["S"]["value"]+" from JS World !";
225     return Array(3,outputs);
226  }
227
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