[Zoo-discuss] java service example 2

Fenoy Gerald gerald.fenoy at geolabs.fr
Thu Nov 20 05:02:05 PST 2014


Hi Andrea,
thanks a lot for coming back on this issue.

> Le 20 nov. 2014 à 13:36, andrea antonello <andrea.antonello at gmail.com> a écrit :
> 
> Hi Gerald,
> sorry for the late reply, couldn't get on this until now.
> 
> [...]
>>> Can you double-check the syntax please? It should really be ok now.
>> 
>> In the code, on line 9 [1], you have conf, inputs and outputs defined as HashMap<String,HashMap<String,String>>.
>> 
>> So when you access the inputs named inPath, on line 12 you will have access to a HashMap<String,String> instance. Same for outPath on line 15.
> 
> Ok, so the inputs are always string. This means that each module has
> to do the conversion to its own datatype? I was expecting to have the
> declared type. Is that the same for the other languages or is it due
> to missing java support?

Indeed the inputs are always « string » (I quote the string cause it can contains binary content also which is not really a string, in such a case you will have the optional size attribute accessible for being able to read binary data). You are right, the service implementer have the responsibility  to define their own methods to convert those « strings » to  whatever is of use in their language. For the C language there are an API to read and write the output using OGR directly but this was never generalized to other languages and I have to admit that I do not see how the implementation can handle this on its own, as some may need to use OGR and other may prefer to use another library to parse the input.

I’m not sure about the declared type you speak about, if you search for mimeType, so yes you have access to this kind of information from the HashMap corresponding to your input. In other case I don’t know what do you expect here ?

> 
> Anyways I did the changes in the example and  added also a double
> parameter in order to make this clear.
> 
> Rigth now I am not able to run the process because I do not know the
> url syntax to use to add a second parameter.
> If I do:
> 
> http://127.0.0.1/cgi-bin/zoo_loader.cgi?ServiceProvider=&metapath=zoojavatest&Service=WPS&request=Execute&Version=1.0.0&Identifier=ZooJavaBuilder&DataInputs=inPath=/mypath/dtm.asc&DataInputs=inParameter=3.0
> 
> it complains about inParameter missing. And if I do:
> 
> http://127.0.0.1/cgi-bin/zoo_loader.cgi?ServiceProvider=&metapath=zoojavatest&Service=WPS&request=Execute&Version=1.0.0&Identifier=ZooJavaBuilder&DataInputs=inParameter=3.0&DataInputs=inPath=/mypath/dtm.asc
> 
> it crashes. Which would be the proper syntax?
> 

I am interested a lot in having more informations about the messages you have when it crashed. Nevertheless, you should use the following syntaxe (based on your example request and  if I understood it well):

http://127.0.0.1/cgi-bin/zoo_loader.cgi?metapath=zoojavatest&Service=WPS&request=Execute&Version=1.0.0&Identifier=ZooJavaBuilder&DataInputs=inParameter=3.0;inPath=/mypath/dtm.asc

So as you noticed, when you have more than one DataInputs, you should separate each input name by using semicolon (« ; »). 

side-note: As explained in a different thread today, you can also use the prefixed service name: zoojavatest. ZooJavaBuilder as Identifier value in your request.

> [...]
>> No, it is not necessary. You can but don’t have to define all the informations about dataType, mimeType or any other informations. The ZOO-Kernel
>> is filling the data structures (so the conf, input and output HashMap in this case) prior to call your service, so everything should be correctly
>> set for you. You can still override any value in your service code.
> 
> ok
> 
>> I’ve just updated the sample Java service source code [3] to illustrate the proper way to set the result in a Java
>> service (without setting all metadata informations already set by the ZOO-Kernel before invoking your service). Note that
>> you should only override the value field of your output HashMap.
> 
> ok, that helped.
> 
>>> And will the same be always available in the input hashmaps? This
>>> might be helpful to check on the inputs before processing?
>> 
>> The HashMap of each inputs will contain the metadata informations defined in the ZCFG (as shown here [4]). This means that for each inputs provided in the request but not present in the ZCFG, you won’t have access to any metadata informations attached to the input.
>> 
>> You can use the inRequest field in the input HashMap to know if a value was present in the request or not.
> 
> ok, thanks.
> 
> Andrea
> 
>> 
>>> 
>>> Thanks,
>>> Andrea
>>> 
>> 
>> I hope this helps.
>> 
>> Best regards,
>> 
>> [1] https://github.com/moovida/zoo-java-example-service/blob/master/ZooJavaMain/src/org/jgrasstools/ZooJavaWps.java#L9
>> [2] http://www.zoo-project.org/trac/browser/trunk/zoo-project/zoo-services/hello-java/HelloJava.java#L31
>> [3] http://www.zoo-project.org/trac/changeset/537
>> [4] http://zoo-project.org/docs/services/howtos.html#inputs
>> 
>> 
>> 
>> Gérald Fenoy
>> http://wiki.osgeo.org/wiki/User:Djay
>> 

Thanks again for your help,
Best regards,


Gérald Fenoy
http://wiki.osgeo.org/wiki/User:Djay



More information about the Zoo-discuss mailing list