Java client

We will develop a simple java client and call some methods in the queue API. It's assumed that you have some basic knowledge about programming in Java.

Java (wsimport)

Generate proxy classes for the queue API using wsimport:

mkdir classes sources
wsimport -d classes -s sources -p batchelor.soap http://chemgps.bmc.uu.se/batchelor/api/soap/?wsdl=1
parsing WSDL...
Generating code...
Compiling code...

Add main class

Change directory to sources and use your favorite editor to create a file named client.java inside the batchelor directory.

cd sources
jed batchelor/client.java

This class will contain our main() method, the starting point when running the application.

Compiling

The compiled SOAP proxy classes is located in the classes directory and need to be included:

javac -cp ../classes batchelor/client.java

Running

When running the application, both classes and current directory need to be included to satisfy packages search path.

java -cp ../classes:. batchelor/Client

Examples

First code example simply retrieves the API version from remote server, while the second is a bit more complex and both fetches queued jobs and enqueue a new job.

package batchelor;

import batchelor.soap.*;

/**
 * Simple client using the SOAP proxy client.
 */
public class Client {

    SoapServiceHandlerService service = new SoapServiceHandlerService();
    SoapServiceHandlerPortType client = service.getSoapServiceHandlerPort();

    public Client() {

    }

    void version() {
        System.out.println(client.version());
    }

    void queue() {
        client.queue("started", "none").
                forEach((job) -> {
                    dump(job);
                });
    }

    void submit(String data) {
        JobData indata = new JobData();
        indata.setType("data");
        indata.setData(data);

        QueuedJob job = client.enqueue(indata);
        dump(job);
    }

    void dump(QueuedJob job) {
        JobSubmit submit = job.getSubmit();
        JobStatus status = job.getStatus();
        DateTime queued = status.getQueued();

        System.out.println("Task: " + submit.getTask() + " (" + submit.getName() + ")");
        System.out.println("    Queued: " + queued.getDate() + "[" + queued.getTimezone() + "]");
        System.out.println("    State: " + status.getState().getValue());
    }

    public static void main(String[] args) {
        Client client = new Client();
        client.version();
        client.queue();
        client.submit("hello world");
    }
}

Output from running client2.java should look something like this:

    2.0
Task: default (Job 2)
    Queued: 2018-11-14 13:05:20.082591[Europe/Stockholm]
    State: crashed
Task: default (Job 2)
    Queued: 2018-11-14 13:03:14.603137[Europe/Stockholm]
    State: crashed
Task: default (Job 2)
    Queued: 2018-11-14 12:59:25.445768[Europe/Stockholm]
    State: success
Task: default (Job 1)
    Queued: 2018-11-14 12:43:35.872742[Europe/Stockholm]
    State: success
        ...
Task: default ()
    Queued: 2018-11-15 16:12:39.264869[Europe/Stockholm]
    State: pending