[Zoo-discuss] java service example 2
Fenoy Gerald
gerald.fenoy at geolabs.fr
Mon Nov 17 05:40:51 PST 2014
Hi Andrea,
thanks for your reply.
My answer inline bellow.
> Le 17 nov. 2014 à 13:41, andrea antonello <andrea.antonello at gmail.com> a écrit :
>
> Hi Gerald,
>
>> I confirm that the initial issue was correct. In this file [1] we can see on line 11 and 12 that you are expecting to access the value of
>> an input directly by accessing it using its name. Nevertheless, it is the same structure as the one used in other languages, so in
>> Java it will be HashMap of HashMap of String rather than simply HashMap of String. So when you use the following,it will return a HashMap:
> [...]
>> As I used the same variable names, I guess this should work after applying this correction to the source code.
>>
>> I hope this solve the issue and you can confirm that this fix work for the service.
>
> I now get the problem in the syntax. I did the changes in the example.
> I still get a jvm crash.
>
> 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.
I noted that in the HelloWorldJava example we used the toString method [2]. Maybe this can solve the issue you faced. But anyway, what are the error messages displayed in the apache error log when you try to run the service exactly ? We should have more informations there.
>
>> [1] https://github.com/moovida/zoo-java-example-service/blob/master/ZooJavaMain/src/org/jgrasstools/ZooJavaWps.java
>
> Another question: is the part:
> outputOutPathMap.put("dataType", "string");
> necessary for the outputs?
>
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.
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.
> 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.
>
> 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
More information about the Zoo-discuss
mailing list