[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: 2011-12-07 13:19:47 +0000 (Wed, 07 Dec 2011) $ |
---|
| 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 | |
---|
| 18 | Python |
---|
| 19 | ------ |
---|
| 20 | |
---|
| 21 | You'll find here information needed to deploy your own Python Services Provider. |
---|
| 22 | |
---|
| 23 | Python 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. |
---|
| 28 | |
---|
| 29 | The ZCFG file should contain the following : |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | serviceType |
---|
| 33 | Python |
---|
| 34 | serviceProvider |
---|
| 35 | The name of the Python module to use as a ZOO Service Provider. For instance, if your |
---|
| 36 | script, located in the same directory as your ZOO Kernel, was named ``my_module.py`` then |
---|
| 37 | you should use ``my_module`` (the Python module name) for the serviceProvider value in ZCFG file. |
---|
| 38 | |
---|
| 39 | Python Data Structure used |
---|
| 40 | ************************** |
---|
| 41 | |
---|
| 42 | The Python module's function to be used as a service must: |
---|
| 43 | |
---|
| 44 | - take three arguments : the main configuration, inputs and outputs maps are passed to the |
---|
| 45 | Python module as dictionaries. |
---|
| 46 | - return an integer : corresponding to the service status code. |
---|
| 47 | |
---|
| 48 | Sample Data Structure |
---|
| 49 | ********************* |
---|
| 50 | |
---|
| 51 | In the following you'll find a sample argument passed to the Python module's function for |
---|
| 52 | the two first main configuration file' sections. |
---|
| 53 | |
---|
| 54 | :: |
---|
| 55 | |
---|
| 56 | main={ |
---|
| 57 | "main": {"encoding": "utf-8", |
---|
| 58 | "version": "1.0.0", |
---|
| 59 | "serverAddress": "http://www.zoo-project.org/zoo/", |
---|
| 60 | "lang": "fr-FR,en-CA"}, |
---|
| 61 | "identification": {"title": "The Zoo WPS Development Server", |
---|
| 62 | "abstract": "Development version of ZooWPS.", |
---|
| 63 | "fees": "None", |
---|
| 64 | "accessConstraints": "none", |
---|
| 65 | "keywords": "WPS,GIS,buffer"} |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | Sample ZOO Python Services Provider |
---|
| 69 | *********************************** |
---|
| 70 | |
---|
| 71 | The following code represents a simple ZOO Python Services Provider which provides only one |
---|
| 72 | Service, the HelloPy one. |
---|
| 73 | |
---|
| 74 | .. code-block:: python |
---|
| 75 | |
---|
| 76 | import sys |
---|
| 77 | def HelloPy(conf,inputs,outputs): |
---|
| 78 | outputs["Result"]["value"]="Hello "+inputs["a"]["value"]+" from Python World !" |
---|
| 79 | return 3 |
---|
| 80 | |
---|
| 81 | PHP |
---|
| 82 | --- |
---|
| 83 | |
---|
| 84 | .. code-block:: php |
---|
| 85 | |
---|
| 86 | <? |
---|
| 87 | function HelloPHP(&$main_conf,&$inputs,&$outputs){ |
---|
| 88 | $outputs["Result"]["value"]="Hello ".$inputs[S][value]." from PHP world !"; |
---|
| 89 | return 3; |
---|
| 90 | } |
---|
| 91 | ?> |
---|
| 92 | |
---|
| 93 | Java |
---|
| 94 | ---- |
---|
| 95 | |
---|
| 96 | .. code-block:: java |
---|
| 97 | |
---|
| 98 | import java.util.*; |
---|
| 99 | public class HelloJava { |
---|
| 100 | public static int HelloWorldJava(HashMap conf,HashMap inputs, HashMap outputs) { |
---|
| 101 | HashMap hm1 = new HashMap(); |
---|
| 102 | hm1.put("dataType","string"); |
---|
| 103 | HashMap tmp=(HashMap)(inputs.get("S")); |
---|
| 104 | java.lang.String v=tmp.get("value").toString(); |
---|
| 105 | hm1.put("value","Hello "+v+" from JAVA WOrld !"); |
---|
| 106 | outputs.put("Result",hm1); |
---|
| 107 | System.err.println("Hello from JAVA WOrld !"); |
---|
| 108 | return 3; |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | Javascript |
---|
| 113 | ---------- |
---|
| 114 | |
---|
| 115 | .. code-block:: javascript |
---|
| 116 | |
---|
| 117 | function hellojs(conf,inputs,outputs){ |
---|
| 118 | outputs=new Array(); |
---|
| 119 | outputs={}; |
---|
| 120 | outputs["result"]["value"]="Hello "+inputs["S"]["value"]+" from JS World !"; |
---|
| 121 | return Array(3,outputs); |
---|
| 122 | } |
---|