PJ44844 - Calling z/TPF applications from Java
DanGritter 270005HHS2 Visits (4974)
PJ44844 provides a new optimized call interface to simplify and enhance the ability to integrate Java as part of existing z/TPF application logic. Prior to this APAR, you could still calling z/TPF applications from Java, however it required using a local network connection.
With this support, calling a z/TPF application from Java no longer uses a network connection so reduces latency and CPU overhead.
Setting up TPF services to be callable from Java
With PJ44281 on PUT14, z/TPF supports REST provider for z/TPF applications. This is a prerequisite to calling z/TPF applications for Java, as the REST provider artefacts provide the description necessary for the Java interface. This allows translation to be done from Java to native structures and vice-versa, eliminating the sometimes error-prone process of manually sequencing the Java structures or the cpu-intensive process of retrieving field values using JNI.
Choosing a call method
There are two mechanisms a Java programmer can use to call a z/TPF application with this new support. Both of these methods leverage Apache CXF - one using the WebClient api, and the other using the swagger code generator to build proxy classes.
Using the proxy classes is the most straightforward path calling a z/TPF application in Java. However, there may be scenarios where the data interface cannot be represented as a Java class. The WebClient api is the preferred method for these complex structures, however requires more code as the programmer has to manually build the request and parse the response. The WebClient api may also be useful when only individual fields are necessary from a very large response.
Generating the Proxy classes
Leveraging the swagger specification for documentation of REST services allows an application programmer to automatically create client interfaces using the swagger-codegen project.
Swagger codegen provides code generators for multiple programming languages and is useful outside of the scope of this new support. There are many different front ends, from command line, to web-ui. It also has a plugin for Maven, which allows you to incorporate code generation as part of your build procedure.
Calling the service using the new optimized interface
Once you've coded up a WebClient access or generated the proxy classes and created a client call, your Java application can target the optimized interface by specifying "localhost" as the hostname. With the z/TPF provided tpfclient.jar as part of the classpath for your Java runtime environment, this allows z/TPF to process the client using the z/TPF specific connector.
When using a network connection, it is a prerequisite to add the swagger descriptor to the URL program map on z/TPF, however when using the optimized interface this is not required. This allows you to define services that are only callable from z/TPF. You just have to have the swagger descriptor deployed using the ZMDES DEPLOY command.
For more information on PJ44844 as well as details of some of the topics above, please see the APEDIT and the updated Knowledge Center information.