1 | |
---|
2 | |
---|
3 | <!DOCTYPE html> |
---|
4 | <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]--> |
---|
5 | <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]--> |
---|
6 | <head> |
---|
7 | <meta charset="utf-8"> |
---|
8 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
---|
9 | |
---|
10 | <title>Creating your first ZOO Service — ZOO-Project 1.4a0 documentation</title> |
---|
11 | |
---|
12 | <link href="http://fonts.googleapis.com/css?family=Days+One" rel="stylesheet" type="text/css"> |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | <link rel="search" type="application/opensearchdescription+xml" title="Search within ZOO-Project 1.4a0 documentation" href="../../_static/opensearch.xml"/> |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | <link rel="top" title="ZOO-Project 1.4a0 documentation" href="../../index.html"/> |
---|
35 | |
---|
36 | |
---|
37 | <script src="_static/js/modernizr.min.js"></script> |
---|
38 | |
---|
39 | </head> |
---|
40 | |
---|
41 | <body class="wy-body-for-nav" role="document"> |
---|
42 | |
---|
43 | <div class="wy-grid-for-nav"> |
---|
44 | |
---|
45 | |
---|
46 | <nav data-toggle="wy-nav-shift" class="wy-nav-side"> |
---|
47 | <div class="wy-side-nav-search"> |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | <a class="shrink" href="../../contents.html"><img src="http://zoo-project.org/img/zoo-sun-logo.png" class="img-responsive sun" style="display: inline;"> ZOO</a> |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | </a> |
---|
56 | |
---|
57 | |
---|
58 | <div role="search"> |
---|
59 | <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> |
---|
60 | <input type="text" name="q" placeholder="Search docs" /> |
---|
61 | <input type="hidden" name="check_keywords" value="yes" /> |
---|
62 | <input type="hidden" name="area" value="default" /> |
---|
63 | </form> |
---|
64 | </div> |
---|
65 | |
---|
66 | |
---|
67 | </div> |
---|
68 | |
---|
69 | <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"> |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | <ul> |
---|
74 | <li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction</a><ul> |
---|
75 | <li class="toctree-l2"><a class="reference internal" href="../../intro.html#what-is-zoo-project">What is ZOO-Project ?</a></li> |
---|
76 | <li class="toctree-l2"><a class="reference internal" href="../../intro.html#zoo-project-components">ZOO-Project components</a></li> |
---|
77 | <li class="toctree-l2"><a class="reference internal" href="../../intro.html#open-source">Open Source</a></li> |
---|
78 | </ul> |
---|
79 | </li> |
---|
80 | <li class="toctree-l1"><a class="reference internal" href="../../install/index.html">ZOO-Project installation</a><ul> |
---|
81 | <li class="toctree-l2"><a class="reference internal" href="../../install/install-prerequisites.html">Prerequisites</a></li> |
---|
82 | <li class="toctree-l2"><a class="reference internal" href="../../install/install-download.html">Download</a></li> |
---|
83 | <li class="toctree-l2"><a class="reference internal" href="../../install/install-confoptions.html">Configuration options</a></li> |
---|
84 | <li class="toctree-l2"><a class="reference internal" href="../../install/install-installation.html">Installation on Unix/Linux</a></li> |
---|
85 | <li class="toctree-l2"><a class="reference internal" href="../../install/install-installation.html#installation-on-mac-osx">Installation on Mac OSX</a></li> |
---|
86 | <li class="toctree-l2"><a class="reference internal" href="../../install/install-installation.html#installation-on-windows">Installation on Windows</a></li> |
---|
87 | </ul> |
---|
88 | </li> |
---|
89 | <li class="toctree-l1"><a class="reference internal" href="../../kernel/index.html">ZOO-Kernel</a><ul> |
---|
90 | <li class="toctree-l2"><a class="reference internal" href="../../kernel/what.html">What is ZOO-Kernel ?</a></li> |
---|
91 | <li class="toctree-l2"><a class="reference internal" href="../../kernel/configuration.html">ZOO-Kernel configuration</a></li> |
---|
92 | <li class="toctree-l2"><a class="reference internal" href="../../kernel/mapserver.html">Optional MapServer support</a></li> |
---|
93 | <li class="toctree-l2"><a class="reference internal" href="../../kernel/orfeotoolbox.html">Optional Orfeo Toolbox support</a></li> |
---|
94 | </ul> |
---|
95 | </li> |
---|
96 | <li class="toctree-l1"><a class="reference internal" href="../../services/index.html">ZOO-Services</a><ul> |
---|
97 | <li class="toctree-l2"><a class="reference internal" href="../../services/introduction.html">What are ZOO-Services ?</a></li> |
---|
98 | <li class="toctree-l2"><a class="reference internal" href="../../services/zcfg-reference.html">ZOO-Service configuration file</a></li> |
---|
99 | <li class="toctree-l2"><a class="reference internal" href="../../services/process-profiles.html">Process profiles registry</a></li> |
---|
100 | <li class="toctree-l2"><a class="reference internal" href="../../services/howtos.html">Create your own ZOO-Services</a></li> |
---|
101 | <li class="toctree-l2"><a class="reference internal" href="../../services/status.html">ZOO Status Service</a></li> |
---|
102 | <li class="toctree-l2"><a class="reference internal" href="../../services/debug.html">How To Debug ZOO Services</a></li> |
---|
103 | <li class="toctree-l2"><a class="reference internal" href="../../services/zoo-services.html">Available ZOO-Services</a></li> |
---|
104 | </ul> |
---|
105 | </li> |
---|
106 | <li class="toctree-l1"><a class="reference internal" href="../../api/index.html">ZOO-API</a><ul> |
---|
107 | <li class="toctree-l2"><a class="reference internal" href="../../api/what.html">What is ZOO-API ?</a></li> |
---|
108 | <li class="toctree-l2"><a class="reference internal" href="../../api/howto.html">Using ZOO-API</a></li> |
---|
109 | <li class="toctree-l2"><a class="reference internal" href="../../api/classes.html">ZOO-API Classes</a></li> |
---|
110 | <li class="toctree-l2"><a class="reference internal" href="../../api/examples.html">Examples</a></li> |
---|
111 | </ul> |
---|
112 | </li> |
---|
113 | <li class="toctree-l1"><a class="reference internal" href="../../client/index.html">ZOO-Client</a><ul> |
---|
114 | <li class="toctree-l2"><a class="reference internal" href="../../client/what.html">What is ZOO-Client ?</a></li> |
---|
115 | <li class="toctree-l2"><a class="reference internal" href="../../client/howto.html">Using ZOO-Client</a></li> |
---|
116 | <li class="toctree-l2"><a class="reference internal" href="../../client/example.html">Example application</a></li> |
---|
117 | </ul> |
---|
118 | </li> |
---|
119 | </ul> |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | </div> |
---|
124 | |
---|
125 | </nav> |
---|
126 | |
---|
127 | <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> |
---|
128 | |
---|
129 | |
---|
130 | <nav class="wy-nav-top" role="navigation" aria-label="top navigation"> |
---|
131 | <i data-toggle="wy-nav-top" class="fa fa-bars"></i> |
---|
132 | <a href="../../contents.html">ZOO-Project</a> |
---|
133 | </nav> |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | <div class="wy-nav-content"> |
---|
138 | <div class="rst-content"> |
---|
139 | <div role="navigation" aria-label="breadcrumbs navigation"> |
---|
140 | <ul class="wy-breadcrumbs"> |
---|
141 | |
---|
142 | <li><a href="../../contents.html"> Docs</a> ∕  </li> |
---|
143 | |
---|
144 | <li>Creating your first ZOO Service</li> |
---|
145 | <li class="wy-breadcrumbs-aside"> |
---|
146 | |
---|
147 | <a href="../../_sources/workshop/2014/first_service.txt" rel="nofollow"> View page source</a> |
---|
148 | |
---|
149 | </li> |
---|
150 | </ul> |
---|
151 | <hr/> |
---|
152 | </div> |
---|
153 | <div role="main" class="document"> |
---|
154 | |
---|
155 | <div class="section" id="creating-your-first-zoo-service"> |
---|
156 | <span id="first-service"></span><h1><a class="toc-backref" href="#table-of-contents">Creating your first ZOO Service</a><a class="headerlink" href="#creating-your-first-zoo-service" title="Permalink to this headline">¶</a></h1> |
---|
157 | <div class="contents topic" id="table-of-contents"> |
---|
158 | <p class="topic-title first">Table of Contents</p> |
---|
159 | <ul class="simple"> |
---|
160 | <li><a class="reference internal" href="#creating-your-first-zoo-service" id="id5">Creating your first ZOO Service</a><ul> |
---|
161 | <li><a class="reference internal" href="#introduction" id="id6">Introduction</a></li> |
---|
162 | <li><a class="reference internal" href="#service-and-publication-process-overview" id="id7">Service and publication process overview</a></li> |
---|
163 | <li><a class="reference internal" href="#creating-your-first-zcfg-file" id="id8">Creating your first ZCFG file</a></li> |
---|
164 | <li><a class="reference internal" href="#test-requests" id="id9">Test requests</a><ul> |
---|
165 | <li><a class="reference internal" href="#test-the-getcapabilities-request" id="id10">Test the GetCapabilities request</a></li> |
---|
166 | <li><a class="reference internal" href="#test-the-describeprocess-request" id="id11">Test the DescribeProcess request</a></li> |
---|
167 | <li><a class="reference internal" href="#test-the-execute-request" id="id12">Test the Execute request</a></li> |
---|
168 | </ul> |
---|
169 | </li> |
---|
170 | <li><a class="reference internal" href="#implementing-the-python-service" id="id13">Implementing the Python Service</a><ul> |
---|
171 | <li><a class="reference internal" href="#general-principles" id="id14">General Principles</a></li> |
---|
172 | <li><a class="reference internal" href="#the-hello-service" id="id15">The Hello Service</a></li> |
---|
173 | </ul> |
---|
174 | </li> |
---|
175 | <li><a class="reference internal" href="#interracting-with-your-service-using-execute-requests" id="id16">Interracting with your service using Execute requests</a></li> |
---|
176 | <li><a class="reference internal" href="#conclusion" id="id17">Conclusion</a></li> |
---|
177 | </ul> |
---|
178 | </li> |
---|
179 | </ul> |
---|
180 | </div> |
---|
181 | <div class="section" id="introduction"> |
---|
182 | <h2><a class="toc-backref" href="#table-of-contents">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2> |
---|
183 | <p>In this part, you will create and publish a simple ZOO-Service named <code class="docutils literal"><span class="pre">Hello</span></code> which |
---|
184 | will simply return a hello message containing the input value provided. It will be usefull |
---|
185 | to present in deeper details general concept on how ZOO-Kernel works and handles |
---|
186 | Execute requests.</p> |
---|
187 | </div> |
---|
188 | <div class="section" id="service-and-publication-process-overview"> |
---|
189 | <h2><a class="toc-backref" href="#table-of-contents">Service and publication process overview</a><a class="headerlink" href="#service-and-publication-process-overview" title="Permalink to this headline">¶</a></h2> |
---|
190 | <p>Before starting developing a ZOO Service, you should remember that in |
---|
191 | ZOO-Project, a Service is a couple made of:</p> |
---|
192 | <blockquote> |
---|
193 | <div><ul class="simple"> |
---|
194 | <li>a metadata file: a ZOO Service Configuration File (ZCFG) containing metadata |
---|
195 | informations about a Service (providing informations about default / supported |
---|
196 | inputs and outputs for a Service)</li> |
---|
197 | <li>a Services Provider: it depends on the programming language used, but for Python it |
---|
198 | is a module and for JavaScript a script file.</li> |
---|
199 | </ul> |
---|
200 | </div></blockquote> |
---|
201 | <p>To publish your Service, which means make your ZOO Kernel aware of its presence, |
---|
202 | you should copy a ZCFG file in the directory where <code class="docutils literal"><span class="pre">zoo_loader.cgi</span></code> is located (in this workshop, <code class="docutils literal"><span class="pre">/usr/lib/cgi-bin</span></code>) or in any subdirectory.</p> |
---|
203 | <div class="admonition warning"> |
---|
204 | <p class="first admonition-title">Warning</p> |
---|
205 | <p class="last">only the ZCFG file is required for the Service to be considerate as |
---|
206 | available. So if you don’t get the Service Provider, obviously your Execute |
---|
207 | request will fail as we will discuss later.</p> |
---|
208 | </div> |
---|
209 | <p>Before publication, you should store your ongoing work, so you’ll start by |
---|
210 | creating a directory to store the files of your Services Provider:</p> |
---|
211 | <div class="highlight-none"><div class="highlight"><pre>mkdir -p /home/user/zoo-ws/ws_sp/cgi-env |
---|
212 | </pre></div> |
---|
213 | </div> |
---|
214 | <p>Once the ZCFG and the Python module are both ready, you can publish simply |
---|
215 | by copying the corresponding files in the same directory as the ZOO-Kernel.</p> |
---|
216 | </div> |
---|
217 | <div class="section" id="creating-your-first-zcfg-file"> |
---|
218 | <h2><a class="toc-backref" href="#table-of-contents">Creating your first ZCFG file</a><a class="headerlink" href="#creating-your-first-zcfg-file" title="Permalink to this headline">¶</a></h2> |
---|
219 | <p>You will start by creating the ZCFG file for the <code class="docutils literal"><span class="pre">Hello</span></code> Service. Edit the |
---|
220 | <code class="docutils literal"><span class="pre">/home/user/zoo-ws/ws_sp/cgi-env/Hello.zcfg</span></code> file |
---|
221 | and add the following content:</p> |
---|
222 | <div class="highlight-none"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1 |
---|
223 | 2 |
---|
224 | 3 |
---|
225 | 4 |
---|
226 | 5 |
---|
227 | 6 |
---|
228 | 7 |
---|
229 | 8 |
---|
230 | 9 |
---|
231 | 10 |
---|
232 | 11 |
---|
233 | 12 |
---|
234 | 13 |
---|
235 | 14 |
---|
236 | 15 |
---|
237 | 16 |
---|
238 | 17 |
---|
239 | 18 |
---|
240 | 19 |
---|
241 | 20 |
---|
242 | 21 |
---|
243 | 22 |
---|
244 | 23 |
---|
245 | 24 |
---|
246 | 25 |
---|
247 | 26 |
---|
248 | 27 |
---|
249 | 28</pre></div></td><td class="code"><div class="highlight"><pre>[Hello] |
---|
250 | Title = Return a hello message. |
---|
251 | Abstract = Create a welcome string. |
---|
252 | processVersion = 2 |
---|
253 | storeSupported = true |
---|
254 | statusSupported = true |
---|
255 | serviceProvider = test_service |
---|
256 | serviceType = Python |
---|
257 | <DataInputs> |
---|
258 | [name] |
---|
259 | Title = Input string |
---|
260 | Abstract = The string to insert in the hello message. |
---|
261 | minOccurs = 1 |
---|
262 | maxOccurs = 1 |
---|
263 | <LiteralData> |
---|
264 | dataType = string |
---|
265 | <Default /> |
---|
266 | </LiteralData> |
---|
267 | </DataInputs> |
---|
268 | <DataOutputs> |
---|
269 | [Result] |
---|
270 | Title = The resulting string |
---|
271 | Abstract = The hello message containing the input string |
---|
272 | <LiteralData> |
---|
273 | dataType = string |
---|
274 | <Default /> |
---|
275 | </LiteralData> |
---|
276 | </DataOutputs> |
---|
277 | </pre></div> |
---|
278 | </td></tr></table></div> |
---|
279 | <div class="admonition note"> |
---|
280 | <p class="first admonition-title">Note</p> |
---|
281 | <p class="last">the name of the ZCFG file and the name between braket (here <code class="docutils literal"><span class="pre">[Hello]</span></code>) |
---|
282 | should be the same and correspond to the function name you will define in your |
---|
283 | Services provider.</p> |
---|
284 | </div> |
---|
285 | <p>As you can see in the ZOO Service Configuration File presented above it is divided into |
---|
286 | three distinct sections:</p> |
---|
287 | <blockquote> |
---|
288 | <div><ol class="arabic simple"> |
---|
289 | <li>Main Metadata information (from line 2 to 8)</li> |
---|
290 | <li>List of Inputs metadata information (from 9 line to 19)</li> |
---|
291 | <li>List of Outputs metadata information (from line 20 to 28)</li> |
---|
292 | </ol> |
---|
293 | </div></blockquote> |
---|
294 | <p>You can get more informations about ZCFG from <a class="reference external" href="http://zoo-project.org/docs/services/zcfg-reference.html">the reference documentation</a>.</p> |
---|
295 | <p>If you copy the <code class="docutils literal"><span class="pre">Hello.zcfg</span></code> file in the same directory as your ZOO Kernel |
---|
296 | then you will be able to request for DescribeProcess using the <code class="docutils literal"><span class="pre">Hello</span></code> |
---|
297 | <code class="docutils literal"><span class="pre">Identifier</span></code>. The <code class="docutils literal"><span class="pre">Hello</span></code> service should also be listed from Capabilities |
---|
298 | document.</p> |
---|
299 | </div> |
---|
300 | <div class="section" id="test-requests"> |
---|
301 | <h2><a class="toc-backref" href="#table-of-contents">Test requests</a><a class="headerlink" href="#test-requests" title="Permalink to this headline">¶</a></h2> |
---|
302 | <p>In this section you will tests each WPS requests : GetCapabilities, |
---|
303 | DescribeProcess and Execute. Note that only GetCapabilities and DescribeProcess |
---|
304 | should work at this step.</p> |
---|
305 | <div class="section" id="test-the-getcapabilities-request"> |
---|
306 | <h3><a class="toc-backref" href="#table-of-contents">Test the GetCapabilities request</a><a class="headerlink" href="#test-the-getcapabilities-request" title="Permalink to this headline">¶</a></h3> |
---|
307 | <p>If you run the <code class="docutils literal"><span class="pre">GetCapabilities</span></code> request:</p> |
---|
308 | <div class="highlight-none"><div class="highlight"><pre>http://localhost/cgi-bin/zoo_loader.cgi?request=GetCapabilities&service=WPS |
---|
309 | </pre></div> |
---|
310 | </div> |
---|
311 | <p>Now, you should find your Hello Service in a <code class="docutils literal"><span class="pre">Process</span></code> node in |
---|
312 | <code class="docutils literal"><span class="pre">ProcessOfferings</span></code>:</p> |
---|
313 | <div class="highlight-xml"><div class="highlight"><pre><span class="nt"><wps:Process</span> <span class="na">wps:processVersion=</span><span class="s">"2"</span><span class="nt">></span> |
---|
314 | <span class="nt"><ows:Identifier></span>Hello<span class="nt"></ows:Identifier></span> |
---|
315 | <span class="nt"><ows:Title></span>Return a hello message.<span class="nt"></ows:Title></span> |
---|
316 | <span class="nt"><ows:Abstract></span>Create a welcome string.<span class="nt"></ows:Abstract></span> |
---|
317 | <span class="nt"></wps:Process></span> |
---|
318 | </pre></div> |
---|
319 | </div> |
---|
320 | </div> |
---|
321 | <div class="section" id="test-the-describeprocess-request"> |
---|
322 | <h3><a class="toc-backref" href="#table-of-contents">Test the DescribeProcess request</a><a class="headerlink" href="#test-the-describeprocess-request" title="Permalink to this headline">¶</a></h3> |
---|
323 | <p>You can access the <code class="docutils literal"><span class="pre">ProcessDescription</span></code> of the <code class="docutils literal"><span class="pre">Hello</span></code> service using the |
---|
324 | following <code class="docutils literal"><span class="pre">DescribeProcess</span></code> request:</p> |
---|
325 | <div class="highlight-none"><div class="highlight"><pre>http://localhost/cgi-bin/zoo_loader.cgi?request=DescribeProcess&service=WPS&version=1.0.0&Identifier=Hello |
---|
326 | </pre></div> |
---|
327 | </div> |
---|
328 | <p>You should get the following response:</p> |
---|
329 | <div class="highlight-xml"><div class="highlight"><pre><span class="nt"><wps:ProcessDescriptions</span> <span class="na">xmlns:ows=</span><span class="s">"http://www.opengis.net/ows/1.1"</span> <span class="na">xmlns:wps=</span><span class="s">"http://www.opengis.net/wps/1.0.0"</span> <span class="na">xmlns:xlink=</span><span class="s">"http://www.w3.org/1999/xlink"</span> <span class="na">xmlns:xsi=</span><span class="s">"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="na">xsi:schemaLocation=</span><span class="s">"http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd"</span> <span class="na">service=</span><span class="s">"WPS"</span> <span class="na">version=</span><span class="s">"1.0.0"</span> <span class="na">xml:lang=</span><span class="s">"en-US"</span><span class="nt">></span> |
---|
330 | <span class="nt"><ProcessDescription</span> <span class="na">wps:processVersion=</span><span class="s">"2"</span> <span class="na">storeSupported=</span><span class="s">"true"</span> <span class="na">statusSupported=</span><span class="s">"true"</span><span class="nt">></span> |
---|
331 | <span class="nt"><ows:Identifier></span>Hello<span class="nt"></ows:Identifier></span> |
---|
332 | <span class="nt"><ows:Title></span>Return a hello message.<span class="nt"></ows:Title></span> |
---|
333 | <span class="nt"><ows:Abstract></span>Create a welcome string.<span class="nt"></ows:Abstract></span> |
---|
334 | <span class="nt"><DataInputs></span> |
---|
335 | <span class="nt"><Input</span> <span class="na">minOccurs=</span><span class="s">"1"</span> <span class="na">maxOccurs=</span><span class="s">"1"</span><span class="nt">></span> |
---|
336 | <span class="nt"><ows:Identifier></span>name<span class="nt"></ows:Identifier></span> |
---|
337 | <span class="nt"><ows:Title></span>Input string<span class="nt"></ows:Title></span> |
---|
338 | <span class="nt"><ows:Abstract></span>The string to insert in the hello message.<span class="nt"></ows:Abstract></span> |
---|
339 | <span class="nt"><LiteralData></span> |
---|
340 | <span class="nt"><ows:DataType</span> <span class="na">ows:reference=</span><span class="s">"http://www.w3.org/TR/xmlschema-2/#string"</span><span class="nt">></span>string<span class="nt"></ows:DataType></span> |
---|
341 | <span class="nt"><ows:AnyValue/></span> |
---|
342 | <span class="nt"></LiteralData></span> |
---|
343 | <span class="nt"></Input></span> |
---|
344 | <span class="nt"></DataInputs></span> |
---|
345 | <span class="nt"><ProcessOutputs></span> |
---|
346 | <span class="nt"><Output></span> |
---|
347 | <span class="nt"><ows:Identifier></span>Result<span class="nt"></ows:Identifier></span> |
---|
348 | <span class="nt"><ows:Title></span>The resulting string<span class="nt"></ows:Title></span> |
---|
349 | <span class="nt"><ows:Abstract></span>The hello message containing the input string<span class="nt"></ows:Abstract></span> |
---|
350 | <span class="nt"><LiteralOutput></span> |
---|
351 | <span class="nt"><ows:DataType</span> <span class="na">ows:reference=</span><span class="s">"http://www.w3.org/TR/xmlschema-2/#string"</span><span class="nt">></span>string<span class="nt"></ows:DataType></span> |
---|
352 | <span class="nt"></LiteralOutput></span> |
---|
353 | <span class="nt"></Output></span> |
---|
354 | <span class="nt"></ProcessOutputs></span> |
---|
355 | <span class="nt"></ProcessDescription></span> |
---|
356 | <span class="nt"></wps:ProcessDescriptions></span> |
---|
357 | </pre></div> |
---|
358 | </div> |
---|
359 | </div> |
---|
360 | <div class="section" id="test-the-execute-request"> |
---|
361 | <h3><a class="toc-backref" href="#table-of-contents">Test the Execute request</a><a class="headerlink" href="#test-the-execute-request" title="Permalink to this headline">¶</a></h3> |
---|
362 | <p>Obviously, you cannot run your Service because the Python file was not published |
---|
363 | yet. If you try the following <code class="docutils literal"><span class="pre">Execute</span></code> request:</p> |
---|
364 | <div class="highlight-none"><div class="highlight"><pre>http://localhost/cgi-bin/zoo_loader.cgi?request=Execute&service=WPS&version=1.0.0&Identifier=Hello&DataInputs=name=toto |
---|
365 | </pre></div> |
---|
366 | </div> |
---|
367 | <p>You should get an ExceptionReport similar to the one provided in the following, |
---|
368 | which is normal behavior:</p> |
---|
369 | <div class="highlight-xml"><div class="highlight"><pre><span class="nt"><ows:ExceptionReport</span> <span class="na">xmlns:ows=</span><span class="s">"http://www.opengis.net/ows/1.1"</span> <span class="na">xmlns:xsi=</span><span class="s">"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="na">xmlns:xlink=</span><span class="s">"http://www.w3.org/1999/xlink"</span> <span class="na">xsi:schemaLocation=</span><span class="s">"http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"</span> <span class="na">xml:lang=</span><span class="s">"en-US"</span> <span class="na">version=</span><span class="s">"1.1.0"</span><span class="nt">></span> |
---|
370 | <span class="nt"><ows:Exception</span> <span class="na">exceptionCode=</span><span class="s">"NoApplicableCode"</span><span class="nt">></span> |
---|
371 | <span class="nt"><ows:ExceptionText></span>Python module test_service cannot be loaded.<span class="nt"></ows:ExceptionText></span> |
---|
372 | <span class="nt"></ows:Exception></span> |
---|
373 | <span class="nt"></ows:ExceptionReport></span> |
---|
374 | </pre></div> |
---|
375 | </div> |
---|
376 | </div> |
---|
377 | </div> |
---|
378 | <div class="section" id="implementing-the-python-service"> |
---|
379 | <h2><a class="toc-backref" href="#table-of-contents">Implementing the Python Service</a><a class="headerlink" href="#implementing-the-python-service" title="Permalink to this headline">¶</a></h2> |
---|
380 | <div class="section" id="general-principles"> |
---|
381 | <h3><a class="toc-backref" href="#table-of-contents">General Principles</a><a class="headerlink" href="#general-principles" title="Permalink to this headline">¶</a></h3> |
---|
382 | <p>The most important thing you must know when implementing a new ZOO-Services |
---|
383 | using the Python language is that the function corresponding to your Service |
---|
384 | returns an integer value representing the status of execution |
---|
385 | (<code class="docutils literal"><span class="pre">SERVICE_FAILED</span></code> <a class="footnote-reference" href="#f1" id="id1">[1]</a> or <code class="docutils literal"><span class="pre">SERVICE_SUCCEEDED</span></code> <a class="footnote-reference" href="#f2" id="id2">[2]</a>) and takes three |
---|
386 | arguments (<a class="reference external" href="http://docs.python.org/tutorial/datastructures.html#dictionaries">Python dictionaries</a>):</p> |
---|
387 | <blockquote> |
---|
388 | <div><ul class="simple"> |
---|
389 | <li><code class="docutils literal"><span class="pre">conf</span></code> : the main environment configuration (corresponding to the main.cfg content)</li> |
---|
390 | <li><code class="docutils literal"><span class="pre">inputs</span></code> : the requested / default inputs (used to access input values)</li> |
---|
391 | <li><code class="docutils literal"><span class="pre">outputs</span></code> : the requested / default outputs (used to store computation result)</li> |
---|
392 | </ul> |
---|
393 | </div></blockquote> |
---|
394 | <div class="admonition note"> |
---|
395 | <p class="first admonition-title">Note</p> |
---|
396 | <p class="last">when your service return <code class="docutils literal"><span class="pre">SERVICE_FAILED</span></code> you can set |
---|
397 | <code class="docutils literal"><span class="pre">conf["lenv"]["message"]</span></code> to add a personalized message in the ExceptionReport |
---|
398 | returned by the ZOO Kernel in such case.</p> |
---|
399 | </div> |
---|
400 | <p>You get in the following a sample <code class="docutils literal"><span class="pre">conf</span></code> value based on the <code class="docutils literal"><span class="pre">main.cfg</span></code> file you |
---|
401 | saw <a class="reference external" href="using_zoo_from_osgeolivevm.html#zoo-kernel-configuration">before</a>.</p> |
---|
402 | <div class="highlight-javascript"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1 |
---|
403 | 2 |
---|
404 | 3 |
---|
405 | 4 |
---|
406 | 5 |
---|
407 | 6 |
---|
408 | 7 |
---|
409 | 8 |
---|
410 | 9 |
---|
411 | 10 |
---|
412 | 11 |
---|
413 | 12 |
---|
414 | 13 |
---|
415 | 14 |
---|
416 | 15 |
---|
417 | 16 |
---|
418 | 17 |
---|
419 | 18 |
---|
420 | 19 |
---|
421 | 20 |
---|
422 | 21 |
---|
423 | 22 |
---|
424 | 23 |
---|
425 | 24 |
---|
426 | 25 |
---|
427 | 26 |
---|
428 | 27 |
---|
429 | 28 |
---|
430 | 29 |
---|
431 | 30 |
---|
432 | 31 |
---|
433 | 32 |
---|
434 | 33</pre></div></td><td class="code"><div class="highlight"><pre><span class="p">{</span> |
---|
435 | <span class="s2">"main"</span><span class="o">:</span> <span class="p">{</span> |
---|
436 | <span class="nx">language</span><span class="o">:</span> <span class="s2">"en-US"</span><span class="p">,</span> |
---|
437 | <span class="nx">lang</span><span class="o">:</span> <span class="s2">"fr-FR,ja-JP"</span><span class="p">,</span> |
---|
438 | <span class="nx">version</span><span class="o">:</span> <span class="s2">"1.0.0"</span><span class="p">,</span> |
---|
439 | <span class="nx">encoding</span><span class="o">:</span> <span class="s2">"utf-8"</span><span class="p">,</span> |
---|
440 | <span class="nx">serverAddress</span><span class="o">:</span> <span class="s2">"http://localhost/cgi-bin/zoo_loader.cgi"</span><span class="p">,</span> |
---|
441 | <span class="nx">dataPath</span><span class="o">:</span> <span class="s2">"/var/data"</span><span class="p">,</span> |
---|
442 | <span class="nx">tmpPath</span><span class="o">:</span> <span class="s2">"/var/www/temp"</span><span class="p">,</span> |
---|
443 | <span class="nx">tmpUrl</span><span class="o">:</span> <span class="s2">"../temp"</span><span class="p">,</span> |
---|
444 | <span class="nx">cacheDir</span><span class="o">:</span> <span class="s2">"/var/www/temp/"</span> |
---|
445 | <span class="p">},</span> |
---|
446 | <span class="s2">"identification"</span><span class="o">:</span> <span class="p">{</span> |
---|
447 | <span class="nx">title</span><span class="o">:</span> <span class="s2">"ZOO-Project Workshop - FOSS4G 2014"</span><span class="p">,</span> |
---|
448 | <span class="nx">keywords</span><span class="o">:</span> <span class="s2">"WPS,GIS,buffer"</span><span class="p">,</span> |
---|
449 | <span class="kr">abstract</span><span class="o">:</span> <span class="s2">"Deploying Web Processing Services using ZOO-Project – Examples of Python based WPS using PgRouting"</span><span class="p">,</span> |
---|
450 | <span class="nx">accessConstraints</span><span class="o">:</span> <span class="s2">"none"</span><span class="p">,</span> |
---|
451 | <span class="nx">fees</span><span class="o">:</span> <span class="s2">"None"</span> |
---|
452 | <span class="p">},</span> |
---|
453 | <span class="s2">"provider"</span><span class="o">:</span> <span class="p">{</span> |
---|
454 | <span class="nx">positionName</span><span class="o">:</span> <span class="s2">"Developer"</span><span class="p">,</span> |
---|
455 | <span class="nx">providerName</span><span class="o">:</span> <span class="s2">"ZOO-Project"</span><span class="p">,</span> |
---|
456 | <span class="nx">addressAdministrativeArea</span><span class="o">:</span> <span class="s2">"Lattes"</span><span class="p">,</span> |
---|
457 | <span class="nx">addressCountry</span><span class="o">:</span> <span class="s2">"fr"</span><span class="p">,</span> |
---|
458 | <span class="nx">phoneVoice</span><span class="o">:</span> <span class="s2">"False"</span><span class="p">,</span> |
---|
459 | <span class="nx">addressPostalCode</span><span class="o">:</span> <span class="s2">"34970"</span><span class="p">,</span> |
---|
460 | <span class="nx">role</span><span class="o">:</span> <span class="s2">"Dev"</span><span class="p">,</span> |
---|
461 | <span class="nx">providerSite</span><span class="o">:</span> <span class="s2">"http://www.zoo-project.org"</span><span class="p">,</span> |
---|
462 | <span class="nx">phoneFacsimile</span><span class="o">:</span> <span class="s2">"False"</span><span class="p">,</span> |
---|
463 | <span class="nx">addressElectronicMailAddress</span><span class="o">:</span> <span class="s2">"gerald.fenoy@geolabs.fr"</span><span class="p">,</span> |
---|
464 | <span class="nx">addressCity</span><span class="o">:</span> <span class="s2">"Denver"</span><span class="p">,</span> |
---|
465 | <span class="nx">individualName</span><span class="o">:</span> <span class="s2">"Gérald FENOY"</span> |
---|
466 | <span class="p">}</span> |
---|
467 | </pre></div> |
---|
468 | </td></tr></table></div> |
---|
469 | <p>In the following you get a sample outputs value passed to a Python or a JavaScript Service:</p> |
---|
470 | <div class="highlight-javascript"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1 |
---|
471 | 2 |
---|
472 | 3 |
---|
473 | 4 |
---|
474 | 5 |
---|
475 | 6 |
---|
476 | 7</pre></div></td><td class="code"><div class="highlight"><pre><span class="p">{</span> |
---|
477 | <span class="s1">'Result'</span><span class="o">:</span> <span class="p">{</span> |
---|
478 | <span class="s1">'mimeType'</span><span class="o">:</span> <span class="s1">'application/json'</span><span class="p">,</span> |
---|
479 | <span class="s1">'inRequest'</span><span class="o">:</span> <span class="s1">'true'</span><span class="p">,</span> |
---|
480 | <span class="s1">'encoding'</span><span class="o">:</span> <span class="s1">'UTF-8'</span> |
---|
481 | <span class="p">}</span> |
---|
482 | <span class="p">}</span> |
---|
483 | </pre></div> |
---|
484 | </td></tr></table></div> |
---|
485 | <div class="admonition note"> |
---|
486 | <p class="first admonition-title">Note</p> |
---|
487 | <p class="last">the <code class="docutils literal"><span class="pre">inRequest</span></code> value is set internally by the ZOO-Kernel and can be used to determine from the Service if the key was provided in the request.</p> |
---|
488 | </div> |
---|
489 | <p>ZOO-Project provide a ZOO-API which was originally only available for |
---|
490 | JavaScript services, but thanks to the work of the ZOO-Project |
---|
491 | community, now you have also access to a ZOO-API when using |
---|
492 | the Python language. Thanks to the Python ZOO-API you don’t have to remember anymore |
---|
493 | the value of SERVICE_SUCCEDED and SERVICE_FAILED, you |
---|
494 | have the capability to translate any string from your Python service |
---|
495 | by calling the <code class="docutils literal"><span class="pre">_</span></code> function (ie: <code class="docutils literal"><span class="pre">zoo._('My</span> <span class="pre">string</span> <span class="pre">to</span> |
---|
496 | <span class="pre">translate')</span></code>) or to update the current status of a running service by |
---|
497 | using the <code class="docutils literal"><span class="pre">update_status</span></code> <a class="footnote-reference" href="#f4" id="id3">[3]</a> function the same way you use it from |
---|
498 | JavaScript or C services.</p> |
---|
499 | </div> |
---|
500 | <div class="section" id="the-hello-service"> |
---|
501 | <h3><a class="toc-backref" href="#table-of-contents">The Hello Service</a><a class="headerlink" href="#the-hello-service" title="Permalink to this headline">¶</a></h3> |
---|
502 | <p>You can copy and paste the following into the |
---|
503 | <code class="docutils literal"><span class="pre">/home/user/zoo-ws/ws_sp/cgi-env/test_service.py</span></code> file.</p> |
---|
504 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">zoo</span> |
---|
505 | <span class="k">def</span> <span class="nf">Hello</span><span class="p">(</span><span class="n">conf</span><span class="p">,</span><span class="n">inputs</span><span class="p">,</span><span class="n">outputs</span><span class="p">):</span> |
---|
506 | <span class="n">outputs</span><span class="p">[</span><span class="s">"Result"</span><span class="p">][</span><span class="s">"value"</span><span class="p">]</span><span class="o">=</span>\ |
---|
507 | <span class="s">"Hello "</span><span class="o">+</span><span class="n">inputs</span><span class="p">[</span><span class="s">"name"</span><span class="p">][</span><span class="s">"value"</span><span class="p">]</span><span class="o">+</span><span class="s">" from the ZOO-Project Python world !"</span> |
---|
508 | <span class="k">return</span> <span class="n">zoo</span><span class="o">.</span><span class="n">SERVICE_SUCCEEDED</span> |
---|
509 | </pre></div> |
---|
510 | </div> |
---|
511 | <p>Once you finish editing the file, you should copy it in the <code class="docutils literal"><span class="pre">/usr/lib/cgi-bin</span></code> directory:</p> |
---|
512 | <div class="highlight-none"><div class="highlight"><pre>sudo cp /home/user/zoo-ws/ws_sp/cgi-env/* /usr/lib/cgi-bin |
---|
513 | </pre></div> |
---|
514 | </div> |
---|
515 | </div> |
---|
516 | </div> |
---|
517 | <div class="section" id="interracting-with-your-service-using-execute-requests"> |
---|
518 | <h2><a class="toc-backref" href="#table-of-contents">Interracting with your service using Execute requests</a><a class="headerlink" href="#interracting-with-your-service-using-execute-requests" title="Permalink to this headline">¶</a></h2> |
---|
519 | <p>Now, you can request for Execute using the following basic url:</p> |
---|
520 | <div class="highlight-none"><div class="highlight"><pre>http://localhost/cgi-bin/zoo_loader.cgi?request=Execute&service=WPS&version=1.0.0&Identifier=Hello&DataInputs=name=toto |
---|
521 | </pre></div> |
---|
522 | </div> |
---|
523 | <p>You can request the WPS Server to return a XML WPS Response containing the result of |
---|
524 | your computation, requesting for ResponseDocument or you can access the data directly |
---|
525 | requesting for RawDataOutput.</p> |
---|
526 | <ul class="simple"> |
---|
527 | <li>Sample request using the RawDataOutput parameter:</li> |
---|
528 | </ul> |
---|
529 | <div class="highlight-none"><div class="highlight"><pre>http://localhost/cgi-bin/zoo_loader.cgi?request=Execute&service=WPS&version=1.0.0&Identifier=Hello&DataInputs=name=toto&RawDataOutput=Result |
---|
530 | </pre></div> |
---|
531 | </div> |
---|
532 | <ul class="simple"> |
---|
533 | <li>Sample request using the default ResponseDocument parameter:</li> |
---|
534 | </ul> |
---|
535 | <div class="highlight-none"><div class="highlight"><pre>http://localhost/cgi-bin/zoo_loader.cgi?request=Execute&service=WPS&version=1.0.0&Identifier=Hello&DataInputs=name=toto&ResponseDocument=Result |
---|
536 | </pre></div> |
---|
537 | </div> |
---|
538 | <p>When you are using ResponseDocument there is specific attribut you can use to ask |
---|
539 | the ZOO Kernel to store the result: <code class="docutils literal"><span class="pre">asReference</span></code>. You can use the following example:</p> |
---|
540 | <div class="highlight-none"><div class="highlight"><pre>http://localhost/cgi-bin/zoo_loader.cgi?request=Execute&service=WPS&version=1.0.0&Identifier=Hello&DataInputs=name=toto&ResponseDocument=Result@asReference=true |
---|
541 | </pre></div> |
---|
542 | </div> |
---|
543 | <p>When computation take long time, the client should request the |
---|
544 | execution of a Service by setting both <code class="docutils literal"><span class="pre">storeExecuteResponse</span></code> and |
---|
545 | <code class="docutils literal"><span class="pre">status</span></code> parameter to true to force asynchronous execution. This |
---|
546 | will make the ZOO-Kernel return, without waiting for the Service execution |
---|
547 | completion but after starting another ZOO-Kernel process responsible |
---|
548 | of the Service execution, a ResponseDocument containing a <code class="docutils literal"><span class="pre">statusLocation</span></code> |
---|
549 | attribute which can be used to access the status of an ongoing service |
---|
550 | or the result when the process ended <a class="footnote-reference" href="#f3" id="id4">[4]</a>.</p> |
---|
551 | <div class="highlight-none"><div class="highlight"><pre>http://localhost/cgi-bin/zoo_loader.cgi?request=Execute&service=WPS&version=1.0.0&Identifier=Hello&DataInputs=name=toto&ResponseDocument=Result&storeExecuteResponse=true&status=true |
---|
552 | </pre></div> |
---|
553 | </div> |
---|
554 | </div> |
---|
555 | <div class="section" id="conclusion"> |
---|
556 | <h2><a class="toc-backref" href="#table-of-contents">Conclusion</a><a class="headerlink" href="#conclusion" title="Permalink to this headline">¶</a></h2> |
---|
557 | <p>Even if this first service was really simple it was useful to illustrate how the |
---|
558 | ZOO-Kernel fill <code class="docutils literal"><span class="pre">conf</span></code>, <code class="docutils literal"><span class="pre">inputs</span></code> and <code class="docutils literal"><span class="pre">outputs</span></code> parameter prior to load |
---|
559 | and run your function service, how to write a ZCFG file, how to publish a Services |
---|
560 | Provider by placing the ZCFG and Python files in the same directory as the |
---|
561 | ZOO-Kernel, then how to interract with your service using both |
---|
562 | <code class="docutils literal"><span class="pre">GetCapabilities</span></code>, <code class="docutils literal"><span class="pre">DescribeProcess</span></code> and <code class="docutils literal"><span class="pre">Execute</span></code> requests. We will see |
---|
563 | in the <a class="reference external" href="building_blocks_presentation.html">next section</a> how to write similar requests |
---|
564 | using the XML syntax.</p> |
---|
565 | <p class="rubric">Footnotes</p> |
---|
566 | <table class="docutils footnote" frame="void" id="f1" rules="none"> |
---|
567 | <colgroup><col class="label" /><col /></colgroup> |
---|
568 | <tbody valign="top"> |
---|
569 | <tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td><code class="docutils literal"><span class="pre">SERVICE_FAILED=4</span></code></td></tr> |
---|
570 | </tbody> |
---|
571 | </table> |
---|
572 | <table class="docutils footnote" frame="void" id="f2" rules="none"> |
---|
573 | <colgroup><col class="label" /><col /></colgroup> |
---|
574 | <tbody valign="top"> |
---|
575 | <tr><td class="label"><a class="fn-backref" href="#id2">[2]</a></td><td><code class="docutils literal"><span class="pre">SERVICE_SUCCEEDED=3</span></code></td></tr> |
---|
576 | </tbody> |
---|
577 | </table> |
---|
578 | <table class="docutils footnote" frame="void" id="f4" rules="none"> |
---|
579 | <colgroup><col class="label" /><col /></colgroup> |
---|
580 | <tbody valign="top"> |
---|
581 | <tr><td class="label"><a class="fn-backref" href="#id3">[3]</a></td><td>sample use of update_status is available <a class="reference external" href="http://zoo-project.org/trac/browser/trunk/zoo-project/zoo-services/utils/status/cgi-env/service.py#L1">here</a></td></tr> |
---|
582 | </tbody> |
---|
583 | </table> |
---|
584 | <table class="docutils footnote" frame="void" id="f3" rules="none"> |
---|
585 | <colgroup><col class="label" /><col /></colgroup> |
---|
586 | <tbody valign="top"> |
---|
587 | <tr><td class="label"><a class="fn-backref" href="#id4">[4]</a></td><td>To get on-going status url in <code class="docutils literal"><span class="pre">statusLocation</span></code>, you’ll |
---|
588 | need to setup the <a class="reference external" href="http://www.zoo-project.org/trac/browser/trunk/zoo-project/zoo-services/utils/status">utils/status</a> |
---|
589 | Service. If you don’t get this service available, the ZOO-Kernel will |
---|
590 | simply give the url to a flat XML file stored on the server which will |
---|
591 | contain, at the end of the execution, the result of the Service |
---|
592 | execution. For more informations please take a look into the |
---|
593 | reference <a class="reference external" href="http://zoo-project.org/docs/services/status.html">documentation</a>.</td></tr> |
---|
594 | </tbody> |
---|
595 | </table> |
---|
596 | </div> |
---|
597 | </div> |
---|
598 | |
---|
599 | |
---|
600 | </div> |
---|
601 | <footer> |
---|
602 | |
---|
603 | |
---|
604 | <hr/> |
---|
605 | <div class="pfoot"> |
---|
606 | <div role="contentinfo"> |
---|
607 | <p> |
---|
608 | © Copyright 2009-2015, ZOO-Project team. |
---|
609 | </p> |
---|
610 | </div> |
---|
611 | Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> inspired by <a href="https://readthedocs.org">Read the Docs</a>. |
---|
612 | </div> |
---|
613 | </footer> |
---|
614 | |
---|
615 | </div> |
---|
616 | </div> |
---|
617 | |
---|
618 | </section> |
---|
619 | |
---|
620 | </div> |
---|
621 | |
---|
622 | |
---|
623 | |
---|
624 | |
---|
625 | |
---|
626 | <script type="text/javascript"> |
---|
627 | var DOCUMENTATION_OPTIONS = { |
---|
628 | URL_ROOT:'../../', |
---|
629 | VERSION:'1.4a0', |
---|
630 | COLLAPSE_INDEX:false, |
---|
631 | FILE_SUFFIX:'.html', |
---|
632 | HAS_SOURCE: true |
---|
633 | }; |
---|
634 | </script> |
---|
635 | <script type="text/javascript" src="../../_static/jquery.js"></script> |
---|
636 | <script type="text/javascript" src="../../_static/underscore.js"></script> |
---|
637 | <script type="text/javascript" src="../../_static/doctools.js"></script> |
---|
638 | |
---|
639 | |
---|
640 | |
---|
641 | |
---|
642 | |
---|
643 | <script type="text/javascript" src="../../_static/js/theme.js"></script> |
---|
644 | |
---|
645 | |
---|
646 | |
---|
647 | |
---|
648 | <script type="text/javascript"> |
---|
649 | jQuery(function () { |
---|
650 | SphinxRtdTheme.StickyNav.enable(); |
---|
651 | }); |
---|
652 | </script> |
---|
653 | |
---|
654 | |
---|
655 | </body> |
---|
656 | </html> |
---|