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