camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CAMEL-12055) Allow Jt400PgmProducer to call IBM i service programs
Date Tue, 05 Dec 2017 09:43:00 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-12055?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16278296#comment-16278296
] 

ASF GitHub Bot commented on CAMEL-12055:
----------------------------------------

oscerd closed pull request #2131: CAMEL-12055: Allow Jt400PgmProducer to call IBM i service
programs
URL: https://github.com/apache/camel/pull/2131
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/components/camel-jt400/pom.xml b/components/camel-jt400/pom.xml
index 88527eadfb8..41ccf97d8a9 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 98330de185e..3d6304e6c8d 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 8bd2ad188d3..f48ac1a0d24 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 @@
 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.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 @@
     @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 void setReadTimeout(int readTimeout) {
         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 a17eda8da80..0d1c548ac7f 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 @@
 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 void setReadTimeout(int readTimeout) {
         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 620fb46fc9a..efcd59adb18 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 @@
 
 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 void process(Exchange exchange) throws Exception {
         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 void process(Exchange exchange) throws Exception {
 
             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 b5a3b77b90b..c45e31f314d 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 @@
 
 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 00000000000..536c3434dba
--- /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());
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Allow Jt400PgmProducer to call IBM i service programs
> -----------------------------------------------------
>
>                 Key: CAMEL-12055
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12055
>             Project: Camel
>          Issue Type: New Feature
>          Components: camel-jt400
>            Reporter: Rafał Gała
>            Priority: Minor
>
> It would be good to add possibility to call IBM i service programs in Jt400PgmProducer.
> I have already made necessary changes to the code. I will test them and make a pull request
when ready.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message