[Zoo-discuss] Doubts about java services

andrea antonello andrea.antonello at gmail.com
Thu Nov 13 07:43:37 PST 2014


Hi Gerald,

> For being able to use your ZooJavaWps which is in the org.jgrasstools package, you have first to add both org.zip and
> zoo_java_dependencies.jar in the CLASSPATH definition in the [env] section of your main.cfg file. You should be sure
> that the files are readable by apache user. If you place your file in /usr/lib/cgi-bin, then you can use the following definition:
>
> [env]
> CLASSPATH=/usr/lib/cgi-bin/zoo_java_dependencies.jar:/usr/lib/cgi-bin/org.zip

ok, which makes me think that I do not need to have the wps wrapper
class loose in the cgi folder, it can be also inside a jar with any
other wrapper module.

> About the ZooJavaBuilder.zcfg file you created, you should use the full class name in the serviceProvider
> definition (org.jgrasstools.ZooJavaWps), like in the following:
>
> serviceProvider = org/jgrasstools/ZooJavaWps

ah, ok, in the past I used:
org.jgrasstools.ZooJavaWps
instead of
org/jgrasstools/ZooJavaWps

ok, I will change this.

> Note that when I tried to use your binaries with the following request [1], I got error messages in the apache error log:
>
> java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
>     at org.jgrasstools.ZooJavaWps.ZooJavaBuilder(ZooJavaWps.java:11)
>
> I guess there is something wrong in the way HashMap are handled in the ZooJavaBuilder method. Here I cannot be
> of any help as I don’t have access to the source code.

Yes, I will look into it now. i would prefer to finalize the code
completely based on your suggestions and make it available then, so
that I can write down and maintain the documentation page for java in
the zoo-project wiki, if that is ok for you.

> Side-note: I’m not sure how the service is handling the raster file as we can only provide string. I guess we can pass in inPath
> the full path of the raster file on the server. Using the file name as input parameter will imply limitations, the most obvious
> is that you cannot pass the value by reference (except if you have a file on a distant server which know what files are on your WPS server…).

I think I have a quite common usecase here. The only thing that
changes, is that I do not want to use gdal for IO, since I use already
geotools.
Just as an example, I might be working on LiDAR data, for which the
jgrasstools library has a way to create an indexed file from a folder
of las and work with that.
It is not possible to upload the data or make them handle by gdal.

In these cases how should I proceed?
Ideally I should be able to select the input (maybe a relative path
against a data-folder), define an output and run the module. Possible
view the output through the mapserver integration and in case download
the result once I like it.

> You asked if the work you made can be used as a sample zoo-service. I’m not sure about what you exactly ask here, do you
> mean that you would like me to use the hello-java service using a package or integrate your code directly ?

I would like to have it as example zoo-service for java. Also example
2 for java is ok. I can then maintain it if necessary.

> I hope this helps and you will provide feedbacks about your Java ZOO-Services implementations.

It sure helps. Right now I am installing a new virtual machine on
which I want to compile the svn trunk in order to be able to discuss
with you the java part based on my possible failures :-)
I will get back as soon as it works.

Thanks,
Andrea


>
> Best regards,
>
> [1] http://localhost/cgi-bin/zoo_loader.cgi?request=Execute&service=WPS&version=1.0.0&Identifier=ZooJavaBuilder&DataInputs=inPath=/home/djay/Downloads/dtm.asc
>
>> Le 11 nov. 2014 à 21:46, andrea antonello <andrea.antonello at gmail.com> a écrit :
>>
>> Hi Gerald,
>> thanks for the reply.
>>
>> I created a small and simple java wps service that has also a
>> dependency library.
>>
>> You can find everything here:
>> http://ge.tt/1TmhSI42?c
>>
>> The files are:
>>
>> * dtm.asc
>> * dtm.prj
>> * dtm.sld
>>
>> which is a very small raster file. It is small but works well. This
>> has to be used as input map.
>>
>> * org.zip
>>
>> which is the folder of the compiled service class ZooJavaWps.
>> I made ZooJavaWps on purpose inside a package, since that is the most
>> probable confguration in reality.
>>
>> * zoo_java_dependency.jar
>>
>> A jar library which represents the dependency. Inside here we have a
>> Class that is called from the ZooJavaWps class.
>>
>> * ZooJavaBuilder.zcfg
>>
>> The zoo configuration file.
>>
>> I didn't implement the status update yet, because I didn't have a
>> compiles trunk version of zoo, so I was missing the necessary ZOO
>> class.
>>
>> Please let me know if this is ok to be used as sample zoo-service.
>> I think there is everything in there.
>>
>> Cheers,
>> Andrea
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Wed, Nov 5, 2014 at 1:34 PM, Fenoy Gerald <gerald.fenoy at geolabs.fr> wrote:
>>> Hello Andrea,
>>> sorry for answering this question lately.
>>>
>>>
>>>> Le 29 oct. 2014 à 01:12, andrea antonello <andrea.antonello at gmail.com> a écrit :
>>>>
>>>> Hi everyone,
>>>> I am trying to understand how to expose java modules as WPS service
>>>> and need some pointers to get started.
>>>>
>>>> In the docs related to java, I find a class and a config file, but no
>>>> real documentation about them.
>>>>
>>>
>>> I just quickly updated the Java documentation at [1] to reflect the latest modifications made for the Java support.
>>>
>>>> Given the class from the documentation:
>>>>
>>>> public class HelloJava {
>>>> 29    public static int HelloWorldJava(HashMap conf,HashMap inputs,
>>>> HashMap outputs) {
>>>> 30        HashMap hm1 = new HashMap();
>>>> 31        hm1.put("dataType","string");
>>>> 32        HashMap tmp=(HashMap)(inputs.get("S"));
>>>> 33        String v=tmp.get("value").toString();
>>>> 34        hm1.put("value","Hello "+v+" from JAVA World !!");
>>>> 35        outputs.put("Result",hm1);
>>>> 36        return 3;
>>>> 37  }
>>>> 38}
>>>>
>>>> I find in the config:
>>>>
>>>> 1[HelloWorldJava]
>>>> 2 Title = Display a string
>>>> 3 Abstract = Display a string which contains an hello message
>>>> 4 processVersion = 1
>>>> 5 storeSupported = true
>>>> 6 statusSupported = true
>>>> 7 serviceProvider = HelloJava
>>>> 8 serviceType = Java
>>>>
>>>> So line 1 seems to represent the method to execute, right? -> [HelloWorldJava]
>>>
>>> Correct.
>>>
>>>> While line 7 seems to represent the class name? -> serviceProvider = HelloJava
>>>
>>> Correct.
>>>
>>>> Does this mean that it is on line 7 that the fully qualified name goes
>>>> and that the example has been made without a package?
>>>> Ex: org.jgrasstoools.modules.whatevergisdoit
>>>
>>> Yes, it should work for package too.
>>> Note that the ZOO-Kernel define simply the CLASSPATH by using the directory of you ServiceProvioder (which can be the same directory as the ZOO-Kernel or subdirectory, for calling service using Identifier jgrasstools.MyService for MyService public method defined in a class located in the jgrasstools). You should probably use global environment variables to overwrite this value as it is doable in Python language (and required sometime like when using ZOO-Kernel on windows for instance).
>>>
>>>>
>>>> Also I figured there should be the possibility to pass the processing
>>>> progress on to the client. Can this be done from java, I do not see
>>>> any way in the class?
>>>
>>> So, the answer at the time you sent this email was no you cannot. But after discussing we decided to add this capability. So finally yes, from the Java language you can now use the ZOO-API to update the current status of a running process. I published a simple example (something similar to the longProcess example for other languages) here [2] illustrating its use.
>>>
>>>>
>>>> Last question. If I for example am simply reading a raster and
>>>> producing a new raster as output, then basically I will have no
>>>> output, right. There will be two string inputs defining the input and
>>>> output map (I am using geotools for IO, not gdal). Is that right?
>>>
>>> For each ZOO-Service, you need to define at least one process output, which can be simply a file name of the produced file for instance.
>>>
>>>>
>>>> Last last question.
>>>> storeSupported = true
>>>> statusSupported = true
>>>> what do these two mean. I have some idea, but would love to hear the truth. :-)
>>>>
>>>
>>> Well, this define if your ServiceProvider support to store its result (storeSupported). Indeed, WPS define the optional parameter storeExecuteResult which can take the value true or false and define if the WPS Server should store the result or not. I have to admit that whatever you will define here, as it is transparent to the Service implementation in the ZOO-Project implementation of WPS, the ZOO-Kernel will always be able to store the result and will do.
>>>
>>> For the second one, it should define if your Service is able to report its status. Nevertheless, one more time, ZOO-Kernel is handling status in a way that even if there is no update, it still works, so whatever you defined here, the client can call your service to be run as a background task (when both storeExecuteResponse and status are set to true).
>>>
>>>> Thanks,
>>>> Andrea
>>>>
>>>>
>>>> PS: on the page: http://zoo-project.org/docs/services/zcfg-reference.html
>>>> The link "ZOO-Project SVN source tree" is broken.
>>>
>>> Thanks for completeness, this was fixed in r529 [3].
>>>
>>> As you pointed out, I still have to fix this issue [4] for the Java support.
>>>
>>> Best regards,
>>>
>>>
>>> Gérald Fenoy
>>> http://wiki.osgeo.org/wiki/User:Djay
>>>
>>>
>>>
>>>
>>> [1] http://www.zoo-project.org/docs/services/howtos.html#java
>>> [2] http://zoo-project.org/trac/browser/trunk/zoo-project/zoo-services/hello-java/HelloJava.java#L38
>>> [3] http://zoo-project.org/trac/changeset/529
>>> [4] http://zoo-project.org/trac/ticket/105
>> _______________________________________________
>> Zoo-discuss mailing list
>> Zoo-discuss at lists.osgeo.org
>> http://lists.osgeo.org/cgi-bin/mailman/listinfo/zoo-discuss
>
>
>
> Gérald Fenoy
> http://wiki.osgeo.org/wiki/User:Djay
>


More information about the Zoo-discuss mailing list