You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/06/05 11:43:38 UTC

svn commit: r1346315 - in /camel/trunk/components/camel-jt400/src: main/java/org/apache/camel/component/jt400/ test/java/org/apache/camel/component/jt400/

Author: davsclaus
Date: Tue Jun  5 09:43:38 2012
New Revision: 1346315

URL: http://svn.apache.org/viewvc?rev=1346315&view=rev
Log:
CAMEL-5198: Added connection pool support to camel-jt400. Thanks to Joao Loureiro for the patch.

Added:
    camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueService.java
    camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentDefaultConnectionPoolTest.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueProducerTest.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointConnectionTest.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointTest.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400TestSupport.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/MockAS400ConnectionPool.java
Modified:
    camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java
    camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java
    camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
    camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java
    camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmEndpoint.java
    camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueConsumerTest.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmEndpointTest.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmRouteTest.java
    camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400RouteTest.java

Modified: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java (original)
+++ camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java Tue Jun  5 09:43:38 2012
@@ -18,32 +18,95 @@ package org.apache.camel.component.jt400
 
 import java.util.Map;
 
+import com.ibm.as400.access.AS400ConnectionPool;
 import org.apache.camel.CamelException;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.EndpointHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * {@link Component} to provide integration with AS/400 objects. 
+ * {@link org.apache.camel.Component} to provide integration with AS/400 objects.
  * 
  * Current implementation supports working with data queues (*DTAQ) and Program calls (*PGM)
  */
 public class Jt400Component extends DefaultComponent {
+    
+    /**
+     * Name of the connection pool URI option.
+     */
+    static final String CONNECTION_POOL = "connectionPool";
+
+    /**
+     * Logging tool used by this class.
+     */
+    private static final Logger LOG = LoggerFactory.getLogger(Jt400Component.class);
 
     private static final String DATA_QUEUE = "DTAQ";
     private static final String PGM = "PGM";
 
+    /**
+     * Default connection pool used by the component. Note that this pool is
+     * lazily initialized. This is because in a scenario where the user always
+     * provides a pool, it would be wasteful for Camel to initialize and keep an
+     * idle pool.
+     */
+    private AS400ConnectionPool connectionPool;
+
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> properties) throws Exception {
         String type = remaining.substring(remaining.lastIndexOf(".") + 1).toUpperCase();
+        AS400ConnectionPool connectionPool;
+        if (properties.containsKey(CONNECTION_POOL)) {
+            LOG.trace("AS400ConnectionPool instance specified in the URI - will look it up.");
+            
+            // We have chosen to handle the connectionPool option ourselves, so
+            // we must remove it from the given parameter list (see
+            // http://camel.apache.org/writing-components.html)
+            String poolId = properties.remove(CONNECTION_POOL).toString();
+            connectionPool = EndpointHelper.resolveReferenceParameter(getCamelContext(), poolId, AS400ConnectionPool.class, true);
+        } else {
+            LOG.trace("No AS400ConnectionPool instance specified in the URI - one will be provided.");
+            connectionPool = getConnectionPool();
+        }
 
         if (DATA_QUEUE.equals(type)) {
-            return new Jt400DataQueueEndpoint(uri, this);
+            return new Jt400DataQueueEndpoint(uri, this, connectionPool);
         }
         
         if (PGM.equals(type)) {
-            return new Jt400PgmEndpoint(uri, this);
+            return new Jt400PgmEndpoint(uri, this, connectionPool);
         }
         
         throw new CamelException(String.format("AS/400 Object type %s is not supported", type));
     }
+
+    /**
+     * Returns the default connection pool used by this component.
+     * 
+     * @return the default connection pool used by this component
+     */
+    public synchronized AS400ConnectionPool getConnectionPool() {
+        if (connectionPool == null) {
+            LOG.info("Instantiating the default connection pool ...");
+            connectionPool = new AS400ConnectionPool();
+        }
+        return connectionPool;
+    }
+
+    public void setConnectionPool(AS400ConnectionPool connectionPool) {
+        this.connectionPool = connectionPool;
+    }
+
+    @Override
+    protected void doShutdown() throws Exception {
+        super.doShutdown();
+        if (connectionPool != null) {
+            LOG.info("Shutting down the default connection pool " + connectionPool + " ...");
+            connectionPool.close();
+            connectionPool = null;
+        }
+    }
+    
 }

Modified: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java (original)
+++ camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java Tue Jun  5 09:43:38 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.component.jt400;
 
-import com.ibm.as400.access.AS400;
 import com.ibm.as400.access.BaseDataQueue;
 import com.ibm.as400.access.DataQueue;
 import com.ibm.as400.access.DataQueueEntry;
@@ -34,6 +33,11 @@ import org.apache.camel.impl.PollingCons
 public class Jt400DataQueueConsumer extends PollingConsumerSupport {
 
     private final Jt400DataQueueEndpoint endpoint;
+    
+    /**
+     * Performs the lifecycle logic of this consumer.
+     */
+    private final Jt400DataQueueService queueService;
 
     /**
      * Creates a new consumer instance
@@ -41,22 +45,17 @@ public class Jt400DataQueueConsumer exte
     protected Jt400DataQueueConsumer(Jt400DataQueueEndpoint endpoint) {
         super(endpoint);
         this.endpoint = endpoint;
+        this.queueService = new Jt400DataQueueService(endpoint);
     }
 
     @Override
     protected void doStart() throws Exception {
-        if (!endpoint.getSystem().isConnected()) {
-            log.info("Connecting to " + endpoint);
-            endpoint.getSystem().connectService(AS400.DATAQUEUE);
-        }
+        queueService.start();
     }
 
     @Override
     protected void doStop() throws Exception {
-        if (endpoint.getSystem().isConnected()) {
-            log.info("Disconnecting from " + endpoint);
-            endpoint.getSystem().disconnectAllServices();
-        }
+        queueService.stop();
     }
 
     public Exchange receive() {
@@ -86,7 +85,7 @@ public class Jt400DataQueueConsumer exte
      *                indicates a blocking read.
      */
     public Exchange receive(long timeout) {
-        BaseDataQueue queue = endpoint.getDataQueue();
+        BaseDataQueue queue = queueService.getDataQueue();
         try {
             if (endpoint.isKeyed()) {
                 return receive((KeyedDataQueue) queue, timeout);

Modified: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java (original)
+++ camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java Tue Jun  5 09:43:38 2012
@@ -17,10 +17,10 @@
 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.BaseDataQueue;
 import com.ibm.as400.access.DataQueue;
 import com.ibm.as400.access.KeyedDataQueue;
@@ -28,8 +28,7 @@ import org.apache.camel.CamelException;
 import org.apache.camel.PollingConsumer;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultPollingEndpoint;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * AS/400 Data queue endpoint
@@ -61,47 +60,55 @@ public class Jt400DataQueueEndpoint exte
         binary;
     }
 
-    private static final transient Logger LOG = LoggerFactory.getLogger(Jt400DataQueueEndpoint.class);
+    /**
+     * Encapsulates the base endpoint options and functionality.
+     */
+    private final Jt400Endpoint baseEndpoint;
 
-    private final AS400 system;
-    private final String objectPath;
+    /**
+     * @deprecated Used by {@link #getDataQueue()}, which is deprecated.
+     */
+    @Deprecated
     private BaseDataQueue dataQueue;
-    private Format format = Format.text;
+
     private boolean keyed;
     private String searchKey;
     private SearchType searchType = SearchType.EQ;
 
     /**
-     * Creates a new AS/400 data queue endpoint
+     * Creates a new AS/400 data queue endpoint using a default connection pool
+     * provided by the component.
+     * 
+     * @throws NullPointerException if {@code component} is null
      */
     protected Jt400DataQueueEndpoint(String endpointUri, Jt400Component component) throws CamelException {
+        this(endpointUri, component, component.getConnectionPool());
+    }
+
+    /**
+     * Creates a new AS/400 data queue endpoint using the specified connection
+     * pool.
+     */
+    protected Jt400DataQueueEndpoint(String endpointUri, Jt400Component component, AS400ConnectionPool connectionPool) throws CamelException {
         super(endpointUri, component);
+        ObjectHelper.notNull(connectionPool, "connectionPool");
         try {
-            URI uri = new URI(endpointUri);
-            String[] credentials = uri.getUserInfo().split(":");
-            system = new AS400(uri.getHost(), credentials[0], credentials[1]);
-            objectPath = uri.getPath();
+            baseEndpoint = new Jt400Endpoint(endpointUri, connectionPool);
         } catch (URISyntaxException e) {
             throw new CamelException("Unable to parse URI for " + endpointUri, e);
         }
-
-        try {
-            system.setGuiAvailable(false);
-        } catch (PropertyVetoException e) {
-            LOG.warn("Failed to disable AS/400 prompting in the environment running Camel. This exception will be ignored.", e);
-        }
     }
 
     public void setCcsid(int ccsid) throws PropertyVetoException {
-        this.system.setCcsid(ccsid);
+        baseEndpoint.setCcsid(ccsid);
     }
 
     public void setFormat(Format format) {
-        this.format = format;
+        baseEndpoint.setFormat(format);
     }
 
     public Format getFormat() {
-        return format;
+        return baseEndpoint.getFormat();
     }
 
     public void setKeyed(boolean keyed) {
@@ -129,7 +136,7 @@ public class Jt400DataQueueEndpoint exte
     }
 
     public void setGuiAvailable(boolean guiAvailable) throws PropertyVetoException {
-        this.system.setGuiAvailable(guiAvailable);
+        baseEndpoint.setGuiAvailable(guiAvailable);
     }
 
     @Override
@@ -142,16 +149,51 @@ public class Jt400DataQueueEndpoint exte
         return new Jt400DataQueueProducer(this);
     }
 
+    /**
+     * Obtains an {@code AS400} object that connects to this endpoint. Since
+     * these objects represent limited resources, clients have the
+     * responsibility of {@link #releaseSystem(AS400) releasing them} when done.
+     * 
+     * @return an {@code AS400} object that connects to this endpoint
+     */
     protected AS400 getSystem() {
-        return system;
+        return baseEndpoint.getConnection();
+    }
+    
+    /**
+     * Releases a previously obtained {@code AS400} object from use.
+     * 
+     * @param system a previously obtained {@code AS400} object
+     */
+    protected void releaseSystem(AS400 system) {
+        baseEndpoint.releaseConnection(system);
     }
 
+    /**
+     * @deprecated This method does not benefit from connection pooling; data
+     *             queue instances should be constructed with a connection
+     *             obtained by {@link #getSystem()}.
+     */
+    @Deprecated
     protected BaseDataQueue getDataQueue() {
         if (dataQueue == null) {
+            AS400 system = new AS400(baseEndpoint.getSystemName(), baseEndpoint.getUserID(), baseEndpoint.getPassword());
+            String objectPath = baseEndpoint.getObjectPath();
             dataQueue = keyed ? new KeyedDataQueue(system, objectPath) : new DataQueue(system, objectPath);
         }
         return dataQueue;
     }
+    
+    /**
+     * Returns the fully qualified integrated file system path name of the data
+     * queue of this endpoint.
+     * 
+     * @return the fully qualified integrated file system path name of the data
+     *         queue of this endpoint
+     */
+    protected String getObjectPath() {
+        return baseEndpoint.getObjectPath();
+    }
 
     public boolean isSingleton() {
         return false;

Modified: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java (original)
+++ camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java Tue Jun  5 09:43:38 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.component.jt400;
 
-import com.ibm.as400.access.AS400;
 import com.ibm.as400.access.BaseDataQueue;
 import com.ibm.as400.access.DataQueue;
 import com.ibm.as400.access.KeyedDataQueue;
@@ -31,10 +30,16 @@ import org.apache.camel.impl.DefaultProd
 public class Jt400DataQueueProducer extends DefaultProducer {
 
     private final Jt400DataQueueEndpoint endpoint;
+    
+    /**
+     * Performs the lifecycle logic of this producer.
+     */
+    private final Jt400DataQueueService queueService;
 
     protected Jt400DataQueueProducer(Jt400DataQueueEndpoint endpoint) {
         super(endpoint);
         this.endpoint = endpoint;
+        this.queueService = new Jt400DataQueueService(endpoint);
     }
 
     /**
@@ -48,7 +53,7 @@ public class Jt400DataQueueProducer exte
      * then the {@link org.apache.camel.Message} header <code>KEY</code> must be set.
      */
     public void process(Exchange exchange) throws Exception {
-        BaseDataQueue queue = endpoint.getDataQueue();
+        BaseDataQueue queue = queueService.getDataQueue();
         if (endpoint.isKeyed()) {
             process((KeyedDataQueue) queue, exchange);
         } else {
@@ -74,18 +79,12 @@ public class Jt400DataQueueProducer exte
 
     @Override
     protected void doStart() throws Exception {
-        if (!endpoint.getSystem().isConnected()) {
-            log.info("Connecting to " + endpoint);
-            endpoint.getSystem().connectService(AS400.DATAQUEUE);
-        }
+        queueService.start();
     }
 
     @Override
     protected void doStop() throws Exception {
-        if (endpoint.getSystem().isConnected()) {
-            log.info("Disconnecting from " + endpoint);
-            endpoint.getSystem().disconnectAllServices();
-        }
+        queueService.stop();
     }
 
 }

Added: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueService.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueService.java?rev=1346315&view=auto
==============================================================================
--- camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueService.java (added)
+++ camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueService.java Tue Jun  5 09:43:38 2012
@@ -0,0 +1,97 @@
+/**
+ * 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 com.ibm.as400.access.AS400;
+import com.ibm.as400.access.BaseDataQueue;
+import com.ibm.as400.access.DataQueue;
+import com.ibm.as400.access.KeyedDataQueue;
+import org.apache.camel.Service;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Pseudo-abstract class that encapsulates Service logic common to
+ * {@link Jt400DataQueueConsumer} and {@link Jt400DataQueueProducer}.
+ */
+class Jt400DataQueueService implements Service {
+    
+    /**
+     * Logging tool.
+     */
+    private static final Logger LOG = LoggerFactory.getLogger(Jt400DataQueueService.class);
+    
+    /**
+     * Endpoint which this service connects to.
+     */
+    private final Jt400DataQueueEndpoint endpoint;
+    
+    /**
+     * Data queue object that corresponds to the endpoint of this service (null if stopped).
+     */
+    private BaseDataQueue queue;
+    
+    /**
+     * Creates a {@code Jt400DataQueueService} that connects to the specified
+     * endpoint.
+     * 
+     * @param endpoint endpoint which this service connects to
+     */
+    Jt400DataQueueService(Jt400DataQueueEndpoint endpoint) {
+        ObjectHelper.notNull(endpoint, "endpoint", this);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    public void start() throws Exception {
+        if (queue == null) {
+            AS400 system = endpoint.getSystem();
+            if (endpoint.isKeyed()) {
+                queue = new KeyedDataQueue(system, endpoint.getObjectPath());
+            } else {
+                queue = new DataQueue(system, endpoint.getObjectPath());
+            }
+        }
+        if (!queue.getSystem().isConnected(AS400.DATAQUEUE)) {
+            LOG.info("Connecting to {}", endpoint);
+            queue.getSystem().connectService(AS400.DATAQUEUE);
+        }
+    }
+
+    @Override
+    public void stop() throws Exception {
+        if (queue != null) {
+            LOG.info("Releasing connection to {}", endpoint);
+            AS400 system = queue.getSystem();
+            queue = null;
+            endpoint.releaseSystem(system);
+        }
+    }
+    
+    /**
+     * Returns the data queue object that this service connects to. Returns
+     * {@code null} if the service is stopped.
+     * 
+     * @return the data queue object that this service connects to, or
+     *         {@code null} if stopped
+     */
+    public BaseDataQueue getDataQueue() {
+        return queue;
+    }
+
+}

Added: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java?rev=1346315&view=auto
==============================================================================
--- camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java (added)
+++ camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java Tue Jun  5 09:43:38 2012
@@ -0,0 +1,264 @@
+/**
+ * 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 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;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Pseudo-abstract base JT400 endpoint. This class provides the options that
+ * supported by both the {@link Jt400DataQueueEndpoint} and
+ * {@link Jt400PgmEndpoint}, and also serves as a factory of connections to the
+ * system.
+ */
+class Jt400Endpoint {
+    
+    /**
+     * Logging tool.
+     */
+    private static final Logger LOG = LoggerFactory.getLogger(Jt400Endpoint.class);
+
+    /**
+     * Constant used to specify that the default system CCSID be used (a
+     * negative CCSID is otherwise invalid).
+     */
+    private static final int DEFAULT_SYSTEM_CCSID = -1;
+    
+    /**
+     * Name of the AS/400 system.
+     */
+    private final String systemName;
+    
+    /**
+     * ID of the AS/400 user.
+     */
+    private final String userID;
+    
+    /**
+     * Password of the AS/400 user.
+     */
+    private final String password;
+    
+    /**
+     * Fully qualified integrated file system path name of the target object of
+     * this endpoint (either data queue or program).
+     */
+    private final String objectPath;
+    
+    /**
+     * Pool from which physical connections to the system are obtained.
+     */
+    private final AS400ConnectionPool connectionPool;
+    
+    /**
+     * CCSID to use for the connection with the AS/400 system.
+     */
+    private int ccsid = DEFAULT_SYSTEM_CCSID;
+    
+    /**
+     * Data format for sending messages.
+     */
+    private Format format = Format.text;
+    
+    /**
+     * Whether AS/400 prompting is enabled in the environment running Camel.
+     */
+    private boolean guiAvailable;
+    
+    /**
+     * Creates a new endpoint instance for the specified URI, which will use the
+     * specified pool for obtaining physical connections to the system.
+     * 
+     * @param endpointUri URI of the endpoint
+     * @param connectionPool pool for obtaining physical connections to the
+     *            system
+     * @throws URISyntaxException if unable to parse {@code endpointUri}
+     * @throws IllegalArgumentException if either {@code endpointUri} or
+     *             {@code connectionPool} are null
+     */
+    Jt400Endpoint(String endpointUri, AS400ConnectionPool connectionPool) throws URISyntaxException {
+        ObjectHelper.notNull(endpointUri, "endpointUri", this);
+        ObjectHelper.notNull(connectionPool, "connectionPool", this);
+        
+        URI uri = new URI(endpointUri);
+        String[] credentials = uri.getUserInfo().split(":");
+        systemName = uri.getHost();
+        userID = credentials[0];
+        password = credentials[1];
+        objectPath = uri.getPath();
+        
+        this.connectionPool = connectionPool;
+    }
+    
+    /**
+     * Returns the name of the AS/400 system.
+     * 
+     * @return the name of the AS/400 system
+     */
+    public String getSystemName() {
+        return systemName;
+    }
+    
+    /**
+     * Returns the ID of the AS/400 user.
+     * 
+     * @return the ID of the AS/400 user
+     */
+    public String getUserID() {
+        return userID;
+    }
+    
+    /**
+     * Returns the password of the AS/400 user.
+     * 
+     * @return the password of the AS/400 user
+     */
+    public String getPassword() {
+        return password;
+    }
+    
+    /**
+     * Returns the fully qualified integrated file system path name of the
+     * target object of this endpoint.
+     * 
+     * @return the fully qualified integrated file system path name of the
+     *         target object of this endpoint
+     */
+    public String getObjectPath() {
+        return objectPath;
+    }
+    
+    
+    // Options
+    
+    /**
+     * Returns the CCSID to use for the connection with the AS/400 system.
+     * Returns -1 if the CCSID to use is the default system CCSID.
+     * 
+     * @return the CCSID to use for the connection with the AS/400 system, or -1
+     *         if that is the default system CCSID
+     */
+    public int getCssid() {
+        return ccsid;
+    }
+    
+    /**
+     * Sets the CCSID to use for the connection with the AS/400 system.
+     * 
+     * @param ccsid the CCSID to use for the connection with the AS/400 system
+     */
+    public void setCcsid(int ccsid) {
+        this.ccsid = (ccsid < 0) ? DEFAULT_SYSTEM_CCSID : ccsid;
+    }
+    
+    /**
+     * Returns the data format for sending messages.
+     * 
+     * @return the data format for sending messages
+     */
+    public Format getFormat() {
+        return format;
+    }
+    
+    /**
+     * Sets the data format for sending messages.
+     * 
+     * @param format the data format for sending messages
+     * @throws IllegalArgumentException if {@code format} is null
+     */
+    public void setFormat(Format format) {
+        ObjectHelper.notNull(format, "format", this);
+        this.format = format;
+    }
+    
+    /**
+     * Returns whether AS/400 prompting is enabled in the environment running
+     * Camel.
+     * 
+     * @return whether AS/400 prompting is enabled in the environment running
+     *         Camel
+     */
+    public boolean isGuiAvailable() {
+        return guiAvailable;
+    }
+    
+    /**
+     * Sets whether AS/400 prompting is enabled in the environment running
+     * Camel.
+     * 
+     * @param guiAvailable whether AS/400 prompting is enabled in the
+     *            environment running Camel
+     */
+    public void setGuiAvailable(boolean guiAvailable) {
+        this.guiAvailable = guiAvailable;
+    }
+    
+    
+    // AS400 connections
+    
+    /**
+     * Obtains an {@code AS400} object that connects to this endpoint. Since
+     * these objects represent limited resources, clients have the
+     * responsibility of {@link #releaseConnection(AS400) releasing them} when
+     * done.
+     * 
+     * @return an {@code AS400} object that connects to this endpoint
+     */
+    public AS400 getConnection() {
+        AS400 system = null;
+        try {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Getting an AS400 object for '{}' from {}.", systemName + '/' + userID, connectionPool);
+            }
+            system = connectionPool.getConnection(systemName, userID, password);
+            if (ccsid != DEFAULT_SYSTEM_CCSID) {
+                system.setCcsid(ccsid);
+            }
+            try {
+                system.setGuiAvailable(guiAvailable);
+            } catch (PropertyVetoException e) {
+                LOG.warn("Failed to disable AS/400 prompting in the environment running Camel. This exception will be ignored.", e);
+            }
+            return system; // Not null here.
+        } catch (ConnectionPoolException e) {
+            throw new RuntimeCamelException(String.format("Unable to obtain an AS/400 connection for system name '%s' and user ID '%s'", systemName, userID), e);
+        } catch (PropertyVetoException e) {
+            throw new RuntimeCamelException("Unable to set the CSSID to use with " + system, e);
+        }
+    }
+    
+    /**
+     * Releases a previously obtained {@code AS400} object from use.
+     * 
+     * @param connection a previously obtained {@code AS400} object to release
+     */
+    public void releaseConnection(AS400 connection) {
+        ObjectHelper.notNull(connection, "connection", this);
+        connectionPool.returnConnectionToPool(connection);
+    }
+
+}

Modified: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmEndpoint.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmEndpoint.java (original)
+++ camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmEndpoint.java Tue Jun  5 09:43:38 2012
@@ -17,60 +17,72 @@
 package org.apache.camel.component.jt400;
 
 import java.beans.PropertyVetoException;
-import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Arrays;
 import java.util.Map;
 import javax.naming.OperationNotSupportedException;
 
 import com.ibm.as400.access.AS400;
+import com.ibm.as400.access.AS400ConnectionPool;
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelException;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format;
 import org.apache.camel.impl.DefaultEndpoint;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.camel.util.EndpointHelper;
+import org.apache.camel.util.ObjectHelper;
 
 public class Jt400PgmEndpoint extends DefaultEndpoint {
-    private static final transient Logger LOG = LoggerFactory.getLogger(Jt400PgmEndpoint.class);
-
-    private String programToExecute;
+    /**
+     * Encapsulates the base endpoint options and functionality.
+     */
+    private final Jt400Endpoint baseEndpoint;
 
     private Integer[] outputFieldsIdxArray;
     private Integer[] outputFieldsLengthArray;
 
-    private AS400 iSeries;
-    private Format format = Format.text;
-
     /**
-     * Creates a new AS/400 PGM CALL endpoint
+     * Creates a new AS/400 PGM CALL endpoint using a default connection pool
+     * provided by the component.
+     * 
+     * @throws NullPointerException if {@code component} is null
      */
     protected Jt400PgmEndpoint(String endpointUri, Jt400Component component) throws CamelException {
+        this(endpointUri, component, component.getConnectionPool());
+    }
+
+    /**
+     * Creates a new AS/400 PGM CALL endpoint using the specified connection
+     * pool.
+     */
+    protected Jt400PgmEndpoint(String endpointUri, Jt400Component component, AS400ConnectionPool connectionPool) throws CamelException {
         super(endpointUri, component);
+        ObjectHelper.notNull(connectionPool, "connectionPool");
         try {
-            URI uri = new URI(endpointUri);
-            String[] credentials = uri.getUserInfo().split(":");
-            iSeries = new AS400(uri.getHost(), credentials[0], credentials[1]);
-            programToExecute = uri.getPath();
+            baseEndpoint = new Jt400Endpoint(endpointUri, connectionPool);
         } catch (URISyntaxException e) {
             throw new CamelException("Unable to parse URI for " + endpointUri, e);
         }
-
-        try {
-            iSeries.setGuiAvailable(false);
-        } catch (PropertyVetoException e) {
-            LOG.warn("Failed do disable AS/400 prompting in the environment running Camel.", e);
-        }
     }
 
     @SuppressWarnings("deprecation")
     public Jt400PgmEndpoint(String endpointUri, String programToExecute, Map<String, Object> parameters,
                             CamelContext camelContext) {
         super(endpointUri, camelContext);
-        this.programToExecute = programToExecute;
+        ObjectHelper.notNull(parameters, "parameters", this);
+        if (!parameters.containsKey(Jt400Component.CONNECTION_POOL)) {
+            throw new RuntimeCamelException(String.format("parameters must specify '%s'", Jt400Component.CONNECTION_POOL));
+        }
+        String poolId = parameters.get(Jt400Component.CONNECTION_POOL).toString();
+        AS400ConnectionPool connectionPool = EndpointHelper.resolveReferenceParameter(camelContext, poolId, AS400ConnectionPool.class, true);
+        try {
+            this.baseEndpoint = new Jt400Endpoint(endpointUri, connectionPool);
+        } catch (URISyntaxException e) {
+            throw new RuntimeCamelException("Unable to parse URI for " + endpointUri, e);
+        }
     }
 
     public Producer createProducer() throws Exception {
@@ -86,14 +98,6 @@ public class Jt400PgmEndpoint extends De
         return false;
     }
 
-    @Override
-    public void stop() throws Exception {
-        super.stop();
-        if (iSeries != null) {
-            iSeries.disconnectAllServices();
-        }
-    }
-
     public boolean isFieldIdxForOuput(int idx) {
         return Arrays.binarySearch(outputFieldsIdxArray, idx) >= 0;
     }
@@ -104,11 +108,28 @@ public class Jt400PgmEndpoint extends De
 
     // getters and setters
     public String getProgramToExecute() {
-        return programToExecute;
+        return baseEndpoint.getObjectPath();
     }
 
+    /**
+     * Obtains an {@code AS400} object that connects to this endpoint. Since
+     * these objects represent limited resources, clients have the
+     * responsibility of {@link #releaseiSeries(AS400) releasing them} when
+     * done.
+     * 
+     * @return an {@code AS400} object that connects to this endpoint
+     */
     public AS400 getiSeries() {
-        return iSeries;
+        return baseEndpoint.getConnection();
+    }
+    
+    /**
+     * Releases a previously obtained {@code AS400} object from use.
+     * 
+     * @param iSeries a previously obtained {@code AS400} object
+     */
+    public void releaseiSeries(AS400 iSeries) {
+        baseEndpoint.releaseConnection(iSeries);
     }
 
     public void setOutputFieldsIdx(String outputFieldsIdx) {
@@ -134,19 +155,19 @@ public class Jt400PgmEndpoint extends De
     }
 
     public void setFormat(Format format) {
-        this.format = format;
+        baseEndpoint.setFormat(format);
     }
 
     public Format getFormat() {
-        return format;
+        return baseEndpoint.getFormat();
     }
 
     public void setGuiAvailable(boolean guiAvailable) throws PropertyVetoException {
-        this.iSeries.setGuiAvailable(guiAvailable);
+        baseEndpoint.setGuiAvailable(guiAvailable);
     }
 
     public boolean isGuiAvailable() {
-        return iSeries != null && iSeries.isGuiAvailable();
+        return baseEndpoint.isGuiAvailable();
     }
 
 }

Modified: camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java (original)
+++ camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java Tue Jun  5 09:43:38 2012
@@ -37,6 +37,8 @@ import org.slf4j.LoggerFactory;
 public class Jt400PgmProducer extends DefaultProducer {
 
     private static final Logger LOG = LoggerFactory.getLogger(Jt400PgmProducer.class);
+    
+    private AS400 iSeries;
 
     public Jt400PgmProducer(Jt400PgmEndpoint endpoint) {
         super(endpoint);
@@ -48,8 +50,6 @@ public class Jt400PgmProducer extends De
 
     public void process(Exchange exchange) throws Exception {
 
-        AS400 iSeries = getISeriesEndpoint().getiSeries();
-
         String commandStr = getISeriesEndpoint().getProgramToExecute();
         ProgramParameter[] parameterList = getParameterList(exchange);
 
@@ -106,7 +106,7 @@ public class Jt400PgmProducer extends De
                     if (getISeriesEndpoint().getFormat() == Format.binary) {
                         typeConverter = new AS400ByteArray(length);
                     } else {
-                        typeConverter = new AS400Text(length, getISeriesEndpoint().getiSeries());
+                        typeConverter = new AS400Text(length, iSeries);
                     }
                     inputData = typeConverter.toBytes(param);
                 }
@@ -153,7 +153,7 @@ public class Jt400PgmProducer extends De
                 if (getISeriesEndpoint().getFormat() == Format.binary) {
                     typeConverter = new AS400ByteArray(length);
                 } else {
-                    typeConverter = new AS400Text(length, getISeriesEndpoint().getiSeries());
+                    typeConverter = new AS400Text(length, iSeries);
                 }
                 javaValue = typeConverter.toObject(output);
             }
@@ -186,17 +186,21 @@ public class Jt400PgmProducer extends De
 
     @Override
     protected void doStart() throws Exception {
-        if (!getISeriesEndpoint().getiSeries().isConnected()) {
+        if (iSeries == null) {
+            iSeries = getISeriesEndpoint().getiSeries();
+        }
+        if (!iSeries.isConnected(AS400.COMMAND)) {
             LOG.info("Connecting to {}", getISeriesEndpoint());
-            getISeriesEndpoint().getiSeries().connectService(AS400.COMMAND);
+            iSeries.connectService(AS400.COMMAND);
         }
     }
 
     @Override
     protected void doStop() throws Exception {
-        if (getISeriesEndpoint().getiSeries().isConnected()) {
-            LOG.info("Disconnecting from {}", getISeriesEndpoint());
-            getISeriesEndpoint().getiSeries().disconnectAllServices();
+        if (iSeries != null) {
+            LOG.info("Releasing connection to {}", getISeriesEndpoint());
+            getISeriesEndpoint().releaseiSeries(iSeries);
+            iSeries = null;
         }
     }
 

Added: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentDefaultConnectionPoolTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentDefaultConnectionPoolTest.java?rev=1346315&view=auto
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentDefaultConnectionPoolTest.java (added)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentDefaultConnectionPoolTest.java Tue Jun  5 09:43:38 2012
@@ -0,0 +1,66 @@
+/**
+ * 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 java.util.HashMap;
+
+import com.ibm.as400.access.AS400ConnectionPool;
+import org.apache.camel.CamelException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class Jt400ComponentDefaultConnectionPoolTest {
+    private Jt400Component component;
+
+    @Before
+    public void setUp() throws Exception {
+        component = new Jt400Component();
+        try {
+            // Use an invalid object type so that endpoints are never created
+            // and actual connections are never requested
+            component.createEndpoint("jt400://user:password@host/qsys.lib/library.lib/program.xxx",
+                    "/user:password@host/qsys.lib/library.lib/program.xxx",
+                    new HashMap<String, Object>(0));
+        } catch (CamelException e) {
+            /* Expected */
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (component != null) {
+            component.stop();
+        }
+    }
+
+    @Test
+    public void testDefaultConnectionPoolIsCreated() {
+        assertNotNull(component.getConnectionPool());
+    }
+
+    /**
+     * Note: white-box testing.
+     */
+    @Test
+    public void testDefaultConnectionPoolIsOfExpectedType() {
+        assertEquals(AS400ConnectionPool.class, component.getConnectionPool().getClass());
+    }
+}

Modified: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java (original)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java Tue Jun  5 09:43:38 2012
@@ -17,23 +17,31 @@
 package org.apache.camel.component.jt400;
 
 import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.camel.CamelException;
 import org.apache.camel.Endpoint;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
 /**
  * Test case for {@link Jt400Component}
  */
-public class Jt400ComponentTest extends Assert {
+public class Jt400ComponentTest extends Jt400TestSupport {
 
     private Jt400Component component;
+    private Map<String, Object> properties;
 
+    @Override
     @Before
-    public void setUp() throws Exception {        
+    public void setUp() throws Exception {
+        super.setUp();
+
         component = new Jt400Component();
+        component.setCamelContext(context());
+
+        properties = new HashMap<String, Object>();
+        properties.put("connectionPool", "#mockPool");
     }
 
     /**
@@ -42,8 +50,8 @@ public class Jt400ComponentTest extends 
     @Test
     public void testCreateDatqEndpoint() throws Exception {
         Endpoint endpoint = component
-            .createEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.dtaq",
-                            "/user:password@host/qsys.lib/library.lib/queue.dtaq", new HashMap<String, Object>());
+                .createEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.dtaq",
+                        "/user:password@host/qsys.lib/library.lib/queue.dtaq", properties);
         assertNotNull(endpoint);
         assertTrue(endpoint instanceof Jt400DataQueueEndpoint);
     }
@@ -54,8 +62,8 @@ public class Jt400ComponentTest extends 
     @Test
     public void testCreatePgmEndpoint() throws Exception {
         Endpoint endpoint = component
-            .createEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.pgm",
-                            "/user:password@host/qsys.lib/library.lib/queue.pgm", new HashMap<String, Object>());
+                .createEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.pgm",
+                        "/user:password@host/qsys.lib/library.lib/queue.pgm", properties);
         assertNotNull(endpoint);
         assertTrue(endpoint instanceof Jt400PgmEndpoint);
     }
@@ -67,7 +75,7 @@ public class Jt400ComponentTest extends 
     public void testCreateEndpointForOtherObjectType() throws Exception {
         try {
             component.createEndpoint("jt400://user:password@host/qsys.lib/library.lib/program.xxx",
-                                     "/user:password@host/qsys.lib/library.lib/program.xxx", new HashMap<String, Object>());
+                    "/user:password@host/qsys.lib/library.lib/program.xxx", new HashMap<String, Object>());
             fail("Exception should been thrown when trying to create an endpoint for an unsupported object type");
         } catch (CamelException e) {
             // this is just what we expected

Modified: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueConsumerTest.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueConsumerTest.java (original)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueConsumerTest.java Tue Jun  5 09:43:38 2012
@@ -34,8 +34,6 @@ import org.junit.Test;
  * <code>"jt400test.properties"</code>, in a property with key
  * <code>"org.apache.camel.component.jt400.emptydtaq.uri"</code>).
  * </p>
- *
- * @version 
  */
 @Ignore("Test manual")
 public class Jt400DataQueueConsumerTest extends TestCase {

Modified: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java (original)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java Tue Jun  5 09:43:38 2012
@@ -17,14 +17,13 @@
 package org.apache.camel.component.jt400;
 
 import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Before;
 import org.junit.Test;
 
 /**
  * Test case for {@link Jt400DataQueueEndpoint}
  */
-public class Jt400DataQueueEndpointTest extends CamelTestSupport {
+public class Jt400DataQueueEndpointTest extends Jt400TestSupport {
 
     private Jt400DataQueueEndpoint endpoint;
 
@@ -32,7 +31,7 @@ public class Jt400DataQueueEndpointTest 
     @Before
     public void setUp() throws Exception {
         super.setUp();
-        endpoint = (Jt400DataQueueEndpoint)resolveMandatoryEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.dtaq?ccsid=500&format=binary&guiAvailable=true");
+        endpoint = (Jt400DataQueueEndpoint) resolveMandatoryEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.dtaq?ccsid=500&format=binary&guiAvailable=true&connectionPool=#mockPool");
     }
 
     /**
@@ -46,4 +45,9 @@ public class Jt400DataQueueEndpointTest 
         assertEquals(Format.binary, endpoint.getFormat());
         assertTrue(endpoint.getSystem().isGuiAvailable());
     }
+
+    @Test
+    public void testToString() {
+        assertEquals("Endpoint[jt400://user:******@host/qsys.lib/library.lib/queue.dtaq?ccsid=500&connectionPool=%23mockPool&format=binary&guiAvailable=true]", endpoint.toString());
+    }
 }

Added: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueProducerTest.java?rev=1346315&view=auto
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueProducerTest.java (added)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueProducerTest.java Tue Jun  5 09:43:38 2012
@@ -0,0 +1,43 @@
+/**
+ * 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.junit.Before;
+import org.junit.Test;
+
+public class Jt400DataQueueProducerTest extends Jt400TestSupport {
+
+    private static final String PASSWORD = "p4ssw0rd";
+
+    private Jt400DataQueueProducer producer;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        Jt400DataQueueEndpoint endpoint = resolveMandatoryEndpoint(
+                "jt400://user:" + PASSWORD + "@host/qsys.lib/library.lib/queue.dtaq?connectionPool=#mockPool",
+                Jt400DataQueueEndpoint.class);
+        producer = new Jt400DataQueueProducer(endpoint);
+    }
+
+    @Test
+    public void testToStringHidesPassword() {
+        assertFalse(producer.toString().contains(PASSWORD));
+    }
+
+}

Added: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointConnectionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointConnectionTest.java?rev=1346315&view=auto
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointConnectionTest.java (added)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointConnectionTest.java Tue Jun  5 09:43:38 2012
@@ -0,0 +1,66 @@
+/**
+ * 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 com.ibm.as400.access.AS400;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class Jt400EndpointConnectionTest extends Jt400TestSupport {
+
+    private Jt400Endpoint jt400Endpoint;
+    private AS400 connection;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+
+        jt400Endpoint = new Jt400Endpoint("jt400://USER:password@host/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ", getConnectionPool());
+        jt400Endpoint.setCcsid(37);
+        connection = jt400Endpoint.getConnection();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (connection != null) {
+            jt400Endpoint.releaseConnection(connection);
+        }
+        super.tearDown();
+    }
+
+    @Test
+    public void testSystemName() {
+        assertEquals("host", connection.getSystemName());
+    }
+
+    @Test
+    public void testUserId() {
+        assertEquals("USER", connection.getUserId());
+    }
+
+    @Test
+    public void testCssid() {
+        assertEquals(37, connection.getCcsid());
+    }
+
+    @Test
+    public void testGuiAvailable() {
+        assertFalse(connection.isGuiAvailable());
+    }
+
+}

Added: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointTest.java?rev=1346315&view=auto
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointTest.java (added)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointTest.java Tue Jun  5 09:43:38 2012
@@ -0,0 +1,68 @@
+/**
+ * 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.component.jt400.Jt400DataQueueEndpoint.Format;
+import org.junit.Before;
+import org.junit.Test;
+
+public class Jt400EndpointTest extends Jt400TestSupport {
+
+    private Jt400Endpoint jt400Endpoint;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        jt400Endpoint = new Jt400Endpoint("jt400://USER:password@host/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ", getConnectionPool());
+    }
+
+    @Test
+    public void testSystemName() {
+        assertEquals("host", jt400Endpoint.getSystemName());
+    }
+
+    @Test
+    public void testUserID() {
+        assertEquals("USER", jt400Endpoint.getUserID());
+    }
+
+    @Test
+    public void testPassword() {
+        assertEquals("password", jt400Endpoint.getPassword());
+    }
+
+    @Test
+    public void testObjectPath() {
+        assertEquals("/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ", jt400Endpoint.getObjectPath());
+    }
+
+    @Test
+    public void testDefaultCcsid() {
+        assertEquals(-1, jt400Endpoint.getCssid());
+    }
+
+    @Test
+    public void testDefaultFormat() {
+        assertEquals(Format.text, jt400Endpoint.getFormat());
+    }
+
+    @Test
+    public void testDefaultGuiAvailable() {
+        assertEquals(false, jt400Endpoint.isGuiAvailable());
+    }
+
+}

Modified: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmEndpointTest.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmEndpointTest.java (original)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmEndpointTest.java Tue Jun  5 09:43:38 2012
@@ -17,14 +17,13 @@
 package org.apache.camel.component.jt400;
 
 import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Before;
 import org.junit.Test;
 
 /**
  * Test case for {@link Jt400DataQueueEndpoint}
  */
-public class Jt400PgmEndpointTest extends CamelTestSupport {
+public class Jt400PgmEndpointTest extends Jt400TestSupport {
 
     private static final String USER = "USER";
     private static final String HOST = "host";
@@ -37,8 +36,9 @@ public class Jt400PgmEndpointTest extend
     @Before
     public void setUp() throws Exception {
         super.setUp();
-        endpoint = (Jt400PgmEndpoint)resolveMandatoryEndpoint("jt400://" + USER + ":" + PASSWORD
-                                                              + "@" + HOST + PGM + "?guiAvailable=true&format=binary&outputFieldsIdx=1,2&fieldsLength=10,512,255");
+        endpoint = (Jt400PgmEndpoint) resolveMandatoryEndpoint("jt400://" + USER + ":" + PASSWORD
+                + "@" + HOST + PGM
+                + "?connectionPool=#mockPool&guiAvailable=true&format=binary&outputFieldsIdx=1,2&fieldsLength=10,512,255");
     }
 
     /**

Modified: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmRouteTest.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmRouteTest.java (original)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmRouteTest.java Tue Jun  5 09:43:38 2012
@@ -54,20 +54,20 @@ public class Jt400PgmRouteTest extends C
                     Exchange exchange = endpoint.getReceivedExchanges().get(0);
                     char[] secondParameter = new char[512];
                     Arrays.fill(secondParameter, ' ');
-                    String[] expectedBody = new String[] {"1234", new String(secondParameter), "01"};
+                    String[] expectedBody = new String[]{"1234", new String(secondParameter), "01"};
                     Object actualBody = exchange.getIn().getBody();
 
                     assertNotNull(actualBody);
                     assertTrue(actualBody.getClass().isArray());
 
-                    String[] actualBodyTyped = (String[])actualBody;
+                    String[] actualBodyTyped = (String[]) actualBody;
                     for (int i = 0; i < expectedBody.length; i++) {
                         assertEquals(expectedBody[i], actualBodyTyped[i]);
                     }
                 }
             };
             endpoint.expects(runnable);
-            sendBody("direct:a", new String[] {"1234", "", ""});
+            sendBody("direct:a", new String[]{"1234", "", ""});
             endpoint.assertIsSatisfied();
         }
     }
@@ -80,8 +80,8 @@ public class Jt400PgmRouteTest extends C
             public void configure() throws Exception {
                 if (SYSTEM != null) {
                     String uri = String
-                        .format("jt400://%s:%s@%s/QSYS.LIB/%s.LIB/%s.pgm?outputFieldsIdx=%s&fieldsLength=%s",
-                                USER, PASSWORD, SYSTEM, LIBRARY, PGM, OUTPUT_FIELDS, FIELDS_LENGTH);
+                            .format("jt400://%s:%s@%s/QSYS.LIB/%s.LIB/%s.pgm?outputFieldsIdx=%s&fieldsLength=%s",
+                                    USER, PASSWORD, SYSTEM, LIBRARY, PGM, OUTPUT_FIELDS, FIELDS_LENGTH);
                     from("direct:a").to(uri).to("mock:a");
                 }
             }

Modified: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400RouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400RouteTest.java?rev=1346315&r1=1346314&r2=1346315&view=diff
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400RouteTest.java (original)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400RouteTest.java Tue Jun  5 09:43:38 2012
@@ -56,7 +56,7 @@ public class Jt400RouteTest extends Came
             public void configure() throws Exception {
                 if (SYSTEM != null) {
                     String uri = String.format("jt400://%s:%s@%s/QSYS.LIB/%s.LIB/%s.DTAQ", USER, PASSWORD,
-                                               SYSTEM, LIBRARY, QUEUE);
+                            SYSTEM, LIBRARY, QUEUE);
                     from("direct:a").to(uri);
                     from(uri).to("mock:a");
                 }

Added: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400TestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400TestSupport.java?rev=1346315&view=auto
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400TestSupport.java (added)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400TestSupport.java Tue Jun  5 09:43:38 2012
@@ -0,0 +1,69 @@
+/**
+ * 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 com.ibm.as400.access.AS400ConnectionPool;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * Useful base class for JT400 component unit tests. It creates a mock
+ * connection pool, registers it under the ID {@code "mockPool"} and releases it
+ * after the test runs.
+ */
+public abstract class Jt400TestSupport extends CamelTestSupport {
+
+    private AS400ConnectionPool connectionPool;
+
+    protected Jt400TestSupport() {
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        connectionPool = new MockAS400ConnectionPool();
+        super.setUp();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+        if (connectionPool != null) {
+            connectionPool.close();
+        }
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        ObjectHelper.notNull(connectionPool, "connectionPool");
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("mockPool", connectionPool);
+        return registry;
+    }
+
+    /**
+     * Returns the mock connection pool.
+     *
+     * @return the mock connection pool
+     */
+    public AS400ConnectionPool getConnectionPool() {
+        return connectionPool;
+    }
+
+}

Added: camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/MockAS400ConnectionPool.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/MockAS400ConnectionPool.java?rev=1346315&view=auto
==============================================================================
--- camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/MockAS400ConnectionPool.java (added)
+++ camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/MockAS400ConnectionPool.java Tue Jun  5 09:43:38 2012
@@ -0,0 +1,72 @@
+/**
+ * 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 java.util.Locale;
+
+import com.ibm.as400.access.AS400;
+import com.ibm.as400.access.AS400ConnectionPool;
+import com.ibm.as400.access.ConnectionPoolException;
+
+/**
+ * Mock {@code AS400ConnectionPool} implementation, useful in unit testing JT400 endpoints.
+ */
+public class MockAS400ConnectionPool extends AS400ConnectionPool {
+
+    private static final long serialVersionUID = -7473444280370756827L;
+
+    public MockAS400ConnectionPool() {
+        super();
+        setRunMaintenance(false);
+        setThreadUsed(false);
+    }
+
+    @Deprecated
+    @Override
+    public AS400 getConnection(String systemName, String userID) throws ConnectionPoolException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Deprecated
+    @Override
+    public AS400 getConnection(String systemName, String userID, int service) throws ConnectionPoolException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public AS400 getConnection(String systemName, String userID, String password) throws ConnectionPoolException {
+        return new AS400(systemName, userID, password);
+    }
+
+    @Override
+    public AS400 getConnection(String systemName, String userID, String password, int service) throws ConnectionPoolException {
+        return getConnection(systemName, userID, password);
+    }
+
+    @Override
+    public AS400 getConnection(String systemName, String userID, String password, int service, Locale locale) throws ConnectionPoolException {
+        return getConnection(systemName, userID, password, locale);
+    }
+
+    @Override
+    public AS400 getConnection(String systemName, String userID, String password, Locale locale) throws ConnectionPoolException {
+        AS400 connection = getConnection(systemName, userID, password);
+        connection.setLocale(locale);
+        return connection;
+    }
+
+}