This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 39beca8 [CAMEL-16907] camel-jt400 program call usability and doc
improvements (#6019)
39beca8 is described below
commit 39beca84c5d82d0cd0e717e34e4dcadf0f20cfce
Author: Jesse Gorzinski <[email protected]>
AuthorDate: Wed Sep 1 23:41:39 2021 -0500
[CAMEL-16907] camel-jt400 program call usability and doc improvements
(#6019)
* camel-jt400: handle string and int types more elegantly
* camel-jt400: remove 'remote program' terminology from doc
* camel-jt400: remove unneeded 'type' path parameter from the doc
* camel-jt400: add applied example for program call
* stop handling input parms based on binary/text mode
* fix/clarify description of parameter handling
---
.../camel-jt400/src/main/docs/jt400-component.adoc | 56 ++++++++++++++++------
.../camel/component/jt400/Jt400PgmProducer.java | 15 +++++-
2 files changed, 56 insertions(+), 15 deletions(-)
diff --git a/components/camel-jt400/src/main/docs/jt400-component.adoc
b/components/camel-jt400/src/main/docs/jt400-component.adoc
index 9406a46..eb6320b 100644
--- a/components/camel-jt400/src/main/docs/jt400-component.adoc
+++ b/components/camel-jt400/src/main/docs/jt400-component.adoc
@@ -43,7 +43,7 @@ To send or receive messages from a message queue
jt400://user:password@system/QSYS.LIB/LIBRARY.LIB/QUEUE.MSGQ[?options]
----------------------------------------------------------------------
-To call remote program
+To call program
-----------------------------------------------------------------------
jt400://user:password@system/QSYS.LIB/LIBRARY.LIB/program.PGM[?options]
@@ -124,7 +124,6 @@ with the following path and query parameters:
| *password* | *Required* Returns the password of the IBM i user. | | String
| *systemName* | *Required* Returns the name of the IBM i system. | | String
| *objectPath* | *Required* Returns the fully qualified integrated file system
path name of the target object of this endpoint. | | String
-| *type* | *Required* Whether to work with data queues or remote program call.
There are 4 enums and the value can be one of: DTAQ, PGM, SRVPGM, MSGQ | |
Jt400Type
|===
@@ -174,14 +173,14 @@ with the following path and query parameters:
== Usage
When configured as a data queue consumer endpoint, the endpoint will poll a
data
-queue on a remote system. For every entry on the data queue, a new
+queue on an IBM i system. For every entry on the data queue, a new
`Exchange` is sent with the entry's data in the _In_ message's body,
formatted either as a `String` or a `byte[]`, depending on the format.
For a provider endpoint, the _In_ message body contents will be put on
the data queue as either raw bytes or text.
When configured as a message queue consumer endpoint, the endpoint will poll
-a message queue on a remote system. For every entry on the queue, a new
+a message queue on an IBM i system. For every entry on the queue, a new
`Exchange` is sent with the entry's data in the _In_ message's body. The
data is always formatted as a `String`. Note that only new messages will
be processed. That is, any existing messages on the queue that have already
@@ -199,16 +198,19 @@ Inquiry messages or messages requiring a message ID are
not supported.
You can explicit configure a connection pool on the Jt400Component, or as an
uri option
on the endpoint.
-=== Remote program call
+=== Program call
-This endpoint expects the input to be either a String array or byte[]
-array (depending on format) and handles all the CCSID handling through
-the native jt400 library mechanisms. A parameter can be _omitted_ by
-passing null as the value in its position (the remote program has to
-support it). After the program execution the endpoint returns either a
-String array or byte[] array with the values as they were returned by
-the program (the input only parameters will contain the same data as the
-beginning of the invocation). This endpoint does not implement a provider
endpoint!
+This endpoint expects the input to be an `Object[]`, whose object types are
+`int`, `long`, `CharSequence` (such as `String`), or `byte[]`. All other
+data types in the input array will be converted to `String`. For character
+inputs, CCSID handling is performed through the native jt400 library
+mechanisms. A parameter can be _omitted_ by passing null as the value in
+its position (the program has to support it). After the program execution,
+the endpoint returns an `Object[]` in the message body. Depending on
+_format_, the returned array will be populated with `byte[]` or `String`
+objects representing the values as they were returned by the program. Input
+only parameters will contain the same data as the beginning of the invocation.
+This endpoint does not implement a provider endpoint!
== Message headers
@@ -265,7 +267,7 @@ public class Jt400RouteBuilder extends RouteBuilder {
}
-------------------------------------------------------------------------------------------------------
-=== Remote program call example
+=== Program call examples
In the snippet below, the data Exchange sent to the direct:work endpoint
will contain three string that will be used as the arguments for the
@@ -283,6 +285,32 @@ public class Jt400RouteBuilder extends RouteBuilder {
}
---------------------------------------------------------------------------------------------------------------------------------------------------------
+In this example, the camel route will call the QUSRTVUS API to retrieve
+16 bytes from data area "MYUSRSPACE" in the "MYLIB" library.
+
+[source,java]
+---------------------------------------------------------------------------------------------------------------------------------------------------------
+public class Jt400RouteBuilder extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ from("timer://foo?period=60000")
+ .process( exchange -> {
+ String usrSpc = "MYUSRSPACEMYLIB ";
+ Object[] parms = new Object[] {
+ usrSpc, // Qualified user space name
+ 1, // starting position
+ 16, // length of data
+ "" // output
+ };
+ exchange.getIn().setBody(parms);
+ })
+
.to("jt400://*CURRENT:*CURRENt@localhost/qsys.lib/QUSRTVUS.PGM?fieldsLength=20,4,4,16&outputFieldsIdx=3")
+ .setBody(simple("${body[3]}"))
+ .to("direct:foo");
+ }
+}
+---------------------------------------------------------------------------------------------------------------------------------------------------------
+
=== Writing to keyed data queues
[source,java]
diff --git
a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java
b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java
index 7cd4fda..2c24ae1 100644
---
a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java
+++
b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java
@@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.List;
import com.ibm.as400.access.AS400;
+import com.ibm.as400.access.AS400Bin4;
+import com.ibm.as400.access.AS400Bin8;
import com.ibm.as400.access.AS400ByteArray;
import com.ibm.as400.access.AS400DataType;
import com.ibm.as400.access.AS400Message;
@@ -123,9 +125,20 @@ public class Jt400PgmProducer extends DefaultProducer {
if (input) {
if (param != null) {
AS400DataType typeConverter;
- if (getISeriesEndpoint().getFormat() ==
Jt400Configuration.Format.binary) {
+ if (param instanceof CharSequence) {
+ param = param.toString();
+ typeConverter = new AS400Text(length, iSeries);
+ } else if (param instanceof char[]) {
+ param = new String((char[]) param);
+ typeConverter = new AS400Text(length, iSeries);
+ } else if (param instanceof Integer) {
+ typeConverter = new AS400Bin4();
+ } else if (param instanceof Long) {
+ typeConverter = new AS400Bin8();
+ } else if (param instanceof byte[]) {
typeConverter = new AS400ByteArray(length);
} else {
+ param = param.toString(); // must be a String for
AS400Text class
typeConverter = new AS400Text(length, iSeries);
}
inputData = typeConverter.toBytes(param);