camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] branch master updated: CAMEL-12055: Allow Jt400PgmProducer to call IBM i service programs
Date Tue, 05 Dec 2017 09:42:00 GMT
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 46b7bb5  CAMEL-12055: Allow Jt400PgmProducer to call IBM i service programs
46b7bb5 is described below

commit 46b7bb5256a15e3e1ee337156cca021df9e6e354
Author: Rafał Gała <rafal.gala@ingbank.pl>
AuthorDate: Tue Dec 5 10:10:04 2017 +0100

    CAMEL-12055: Allow Jt400PgmProducer to call IBM i service programs
---
 components/camel-jt400/pom.xml                     |  5 ++
 .../camel-jt400/src/main/docs/jt400-component.adoc |  3 +-
 .../camel/component/jt400/Jt400Configuration.java  | 16 ++++-
 .../camel/component/jt400/Jt400Endpoint.java       |  9 ++-
 .../camel/component/jt400/Jt400PgmProducer.java    | 21 +++++-
 .../apache/camel/component/jt400/Jt400Type.java    |  2 +-
 .../component/jt400/Jt400SrvPgmEndpointTest.java   | 74 ++++++++++++++++++++++
 7 files changed, 123 insertions(+), 7 deletions(-)

diff --git a/components/camel-jt400/pom.xml b/components/camel-jt400/pom.xml
index 88527ea..41ccf97 100644
--- a/components/camel-jt400/pom.xml
+++ b/components/camel-jt400/pom.xml
@@ -46,6 +46,11 @@
       <artifactId>jt400</artifactId>
       <version>${jt400-version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>${commons-lang3-version}</version>
+    </dependency>
 
     <!-- test dependencies -->
     <dependency>
diff --git a/components/camel-jt400/src/main/docs/jt400-component.adoc b/components/camel-jt400/src/main/docs/jt400-component.adoc
index 98330de..3d6304e 100644
--- a/components/camel-jt400/src/main/docs/jt400-component.adoc
+++ b/components/camel-jt400/src/main/docs/jt400-component.adoc
@@ -72,7 +72,7 @@ with the following path and query parameters:
 | *type* | *Required* Whether to work with data queues or remote program call |  | Jt400Type
 |===
 
-==== Query Parameters (29 parameters):
+==== Query Parameters (30 parameters):
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
@@ -105,6 +105,7 @@ with the following path and query parameters:
 | *startScheduler* (scheduler) | Whether the scheduler should be auto started. | true | boolean
 | *timeUnit* (scheduler) | Time unit for initialDelay and delay options. | MILLISECONDS |
TimeUnit
 | *useFixedDelay* (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService
in JDK for details. | true | boolean
+| *procedureName* (procedureName) | Procedure name from a service program to call |  | String
 | *secured* (security) | Whether connections to AS/400 are secured with SSL. | false | boolean
 |===
 // endpoint options: END
diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Configuration.java
b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Configuration.java
index 8bd2ad1..f48ac1a 100644
--- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Configuration.java
+++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Configuration.java
@@ -19,7 +19,6 @@ package org.apache.camel.component.jt400;
 import java.beans.PropertyVetoException;
 import java.net.URI;
 import java.net.URISyntaxException;
-
 import com.ibm.as400.access.AS400;
 import com.ibm.as400.access.AS400ConnectionPool;
 import com.ibm.as400.access.ConnectionPoolException;
@@ -29,6 +28,7 @@ import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
 import org.apache.camel.spi.UriPath;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -116,6 +116,9 @@ public class Jt400Configuration {
     @UriParam(label = "consumer", defaultValue = "30000")
     private int readTimeout = 30000;
 
+    @UriParam(label = "procedureName")
+    private String procedureName;
+
     public Jt400Configuration(String endpointUri, AS400ConnectionPool connectionPool) throws
URISyntaxException {
         ObjectHelper.notNull(endpointUri, "endpointUri", this);
         ObjectHelper.notNull(connectionPool, "connectionPool", this);
@@ -315,6 +318,17 @@ public class Jt400Configuration {
         this.readTimeout = readTimeout;
     }
 
+    public String getProcedureName() {
+        return procedureName;
+    }
+
+    /**
+     * Procedure name from a service program to call
+     */
+    public void setProcedureName(String procedureName) {
+        this.procedureName = procedureName;
+    }
+
     public void setOutputFieldsIdx(String outputFieldsIdx) {
         if (outputFieldsIdx != null) {
             String[] outputArray = outputFieldsIdx.split(",");
diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java
b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java
index a17eda8..0d1c548 100644
--- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java
+++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java
@@ -19,7 +19,6 @@ package org.apache.camel.component.jt400;
 import java.net.URISyntaxException;
 import java.util.Arrays;
 import javax.naming.OperationNotSupportedException;
-
 import com.ibm.as400.access.AS400;
 import com.ibm.as400.access.AS400ConnectionPool;
 import org.apache.camel.CamelException;
@@ -261,6 +260,14 @@ public class Jt400Endpoint extends ScheduledPollEndpoint implements MultipleCons
         configuration.setReadTimeout(readTimeout);
     }
 
+    public void setProcedureName(String procedureName) {
+        configuration.setProcedureName(procedureName);
+    }
+
+    public String getProcedureName() {
+        return configuration.getProcedureName();
+    }
+
     @Override
     public boolean isMultipleConsumersSupported() {
         return true;
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 620fb46..efcd59a 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
@@ -18,18 +18,22 @@ package org.apache.camel.component.jt400;
 
 import java.beans.PropertyVetoException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
-
 import com.ibm.as400.access.AS400;
 import com.ibm.as400.access.AS400ByteArray;
 import com.ibm.as400.access.AS400DataType;
 import com.ibm.as400.access.AS400Message;
 import com.ibm.as400.access.AS400Text;
+import com.ibm.as400.access.CommandCall;
 import com.ibm.as400.access.ProgramCall;
 import com.ibm.as400.access.ProgramParameter;
+import com.ibm.as400.access.ServiceProgramCall;
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.impl.DefaultProducer;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,7 +56,14 @@ public class Jt400PgmProducer extends DefaultProducer {
         String commandStr = getISeriesEndpoint().getObjectPath();
         ProgramParameter[] parameterList = getParameterList(exchange);
 
-        ProgramCall pgmCall = new ProgramCall(iSeries);
+        ProgramCall pgmCall;
+        if (getISeriesEndpoint().getType() == Jt400Type.PGM) {
+            pgmCall = new ProgramCall(iSeries);
+        } else {
+            pgmCall = new ServiceProgramCall(iSeries);
+            ((ServiceProgramCall)pgmCall).setProcedureName(getISeriesEndpoint().getProcedureName());
+            ((ServiceProgramCall)pgmCall).setReturnValueFormat(ServiceProgramCall.NO_RETURN_VALUE);
+        }
         pgmCall.setProgram(commandStr);
         pgmCall.setParameterList(parameterList);
 
@@ -114,7 +125,11 @@ public class Jt400PgmProducer extends DefaultProducer {
 
             if (input && output) {
                 LOG.trace("Parameter {} is both input and output.", i);
-                parameterList[i] = new ProgramParameter(inputData, length);
+                if (getISeriesEndpoint().getType() == Jt400Type.PGM) {
+                    parameterList[i] = new ProgramParameter(inputData, length);
+                } else {
+                    parameterList[i] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENCE,
inputData, length);
+                }
             } else if (input) {
                 LOG.trace("Parameter {} is input.", i);
                 if (inputData != null) {
diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Type.java
b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Type.java
index b5a3b77..c45e31f 100644
--- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Type.java
+++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Type.java
@@ -18,5 +18,5 @@ package org.apache.camel.component.jt400;
 
 public enum Jt400Type {
 
-    DTAQ, PGM
+    DTAQ, PGM, SRVPGM
 }
diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400SrvPgmEndpointTest.java
b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400SrvPgmEndpointTest.java
new file mode 100644
index 0000000..536c343
--- /dev/null
+++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400SrvPgmEndpointTest.java
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jt400;
+
+import org.apache.camel.CamelException;
+import org.apache.camel.Endpoint;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test case for {@link Jt400Endpoint}
+ */
+public class Jt400SrvPgmEndpointTest extends Jt400TestSupport {
+
+    private static final String USER = "USER";
+    private static final String HOST = "host";
+    private static final String PROCEDURE = "someProcedure";
+    private static final String PGM = "/qsys.lib/library.lib/prog.srvpgm";
+    private static final String PASSWORD = "password";
+
+    private Jt400Endpoint endpoint;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        endpoint = (Jt400Endpoint) resolveMandatoryEndpoint("jt400://" + USER + ":" + PASSWORD
+                + "@" + HOST + PGM
+                + "?connectionPool=#mockPool&guiAvailable=true&format=binary&outputFieldsIdx=1,2&fieldsLength=10,512,255"
+                + "&procedureName=" + PROCEDURE);
+    }
+
+    /**
+     * Check that the AS/400 connection is correctly configured for the URL
+     */
+    @Test
+    public void testSystemConfiguration() {
+        assertEquals(USER, endpoint.getUserID());
+        assertEquals(HOST, endpoint.getSystemName());
+        assertEquals(PGM, endpoint.getObjectPath());
+        assertEquals(PROCEDURE, endpoint.getProcedureName());
+        assertTrue(endpoint.isGuiAvailable());
+        assertEquals(Jt400Configuration.Format.binary, endpoint.getFormat());
+        assertEquals(10, endpoint.getOutputFieldLength(0));
+        assertEquals(512, endpoint.getOutputFieldLength(1));
+        assertEquals(255, endpoint.getOutputFieldLength(2));
+        assertEquals(false, endpoint.isFieldIdxForOuput(0));
+        assertEquals(true, endpoint.isFieldIdxForOuput(1));
+        assertEquals(true, endpoint.isFieldIdxForOuput(2));
+    }
+
+    @Test
+    public void testToString() {
+        assertEquals(
+                "jt400://USER:xxxxxx@host/qsys.lib/library.lib/prog.srvpgm?connectionPool=%23mockPool&"
+                        + "fieldsLength=10%2C512%2C255&format=binary&guiAvailable=true"
+                        + "&outputFieldsIdx=1%2C2&procedureName=someProcedure",
+                endpoint.toString());
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <commits@camel.apache.org>'].

Mime
View raw message