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

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

move information about return code

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