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