[348] | 1 | .. _services-howtos: |
---|
| 2 | |
---|
| 3 | How 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 | |
---|
| 9 | ZOO Services are quite easy to create once you have installed the ZOO Kernel and have |
---|
| 10 | chosen code (in the language of your choice) to turn into a ZOO service. Here are some |
---|
| 11 | HelloWorlds 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] | 18 | Common 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] | 24 | Python |
---|
| 25 | ------ |
---|
| 26 | |
---|
| 27 | You'll find here information needed to deploy your own Python Services Provider. |
---|
| 28 | |
---|
| 29 | Python 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 | |
---|
| 36 | The ZCFG file should contain the following : |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | serviceType |
---|
| 40 | Python |
---|
| 41 | serviceProvider |
---|
| 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 | |
---|
| 46 | Python Data Structure used |
---|
| 47 | ************************** |
---|
| 48 | |
---|
[396] | 49 | The Python module's function to be used take three arguments: the main configuration, inputs and outputs. |
---|
| 50 | All this values are passed to the Python module as dictionaries. |
---|
[348] | 51 | |
---|
[396] | 52 | Following you'll find an example for each parameters |
---|
[348] | 53 | |
---|
[396] | 54 | Main configuration |
---|
| 55 | ^^^^^^^^^^^^^^^^^^^^^ |
---|
| 56 | Main configuration contains several informations, some of them are really useful to develop your service. |
---|
| 57 | Following 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] | 99 | Inputs |
---|
| 100 | ^^^^^^^^^^^^ |
---|
| 101 | The 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] | 112 | The access to the value you have to require for the ``value`` parameter, something like this :: |
---|
| 113 | |
---|
| 114 | yourVariable = inputs['variable_name']['value'] |
---|
| 115 | |
---|
| 116 | Outputs |
---|
| 117 | ^^^^^^^^^^^^^ |
---|
| 118 | The outputs data as a structure really similar to the inputs one :: |
---|
| 119 | |
---|
| 120 | { |
---|
| 121 | 'result': {'DataType': 'string', |
---|
| 122 | 'inRequest': 'true', |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | There is no ``'value'`` parameter before you assign it :: |
---|
| 127 | |
---|
| 128 | inputs['result']['value'] = yourOutputDataVariable |
---|
| 129 | |
---|
| 130 | The return statement has to be an integer: corresponding to the service status code. |
---|
| 131 | |
---|
| 132 | To add a message for the wrong result you can add the massage to ``conf["lenv"]["message"]``, |
---|
| 133 | for example: |
---|
| 134 | |
---|
| 135 | .. code-block:: python |
---|
| 136 | |
---|
| 137 | conf["lenv"]["message"] = 'Your module return an error' |
---|
| 138 | |
---|
[348] | 139 | Sample ZOO Python Services Provider |
---|
| 140 | *********************************** |
---|
| 141 | |
---|
| 142 | The following code represents a simple ZOO Python Services Provider which provides only one |
---|
| 143 | Service, 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 | |
---|
| 152 | PHP |
---|
| 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 | |
---|
| 164 | Java |
---|
| 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 | |
---|
| 183 | Javascript |
---|
| 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 | } |
---|