Author: gertv
Date: Fri Jul 18 02:01:29 2008
New Revision: 677858
URL: http://svn.apache.org/viewvc?rev=677858&view=rev
Log:
CAMEL-617: Add support for integrating with AS/400 DTAQ
Added:
activemq/camel/trunk/components/camel-jt400/ (with props)
activemq/camel/trunk/components/camel-jt400/pom.xml
activemq/camel/trunk/components/camel-jt400/src/
activemq/camel/trunk/components/camel-jt400/src/main/
activemq/camel/trunk/components/camel-jt400/src/main/java/
activemq/camel/trunk/components/camel-jt400/src/main/java/org/
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java
activemq/camel/trunk/components/camel-jt400/src/main/resources/
activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/
activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/services/
activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/services/org/
activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/services/org/apache/
activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/services/org/apache/camel/
activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/services/org/apache/camel/component/
activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/services/org/apache/camel/component/jt400
activemq/camel/trunk/components/camel-jt400/src/test/
activemq/camel/trunk/components/camel-jt400/src/test/java/
activemq/camel/trunk/components/camel-jt400/src/test/java/org/
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400RouteTest.java
activemq/camel/trunk/components/camel-jt400/src/test/resources/
activemq/camel/trunk/components/camel-jt400/src/test/resources/log4j.properties
Propchange: activemq/camel/trunk/components/camel-jt400/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jul 18 02:01:29 2008
@@ -0,0 +1,5 @@
+.classpath
+.project
+.settings
+target
+eclipse-classes
Added: activemq/camel/trunk/components/camel-jt400/pom.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jt400/pom.xml?rev=677858&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jt400/pom.xml (added)
+++ activemq/camel/trunk/components/camel-jt400/pom.xml Fri Jul 18 02:01:29 2008
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </parent>
+ <artifactId>camel-jt400</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Java Toolbox for AS/400 (jt400)</name>
+ <description>Camel AS/400 support</description>
+
+ <properties>
+
<camel.osgi.export.pkg>org.apache.camel.component.jt400.*</camel.osgi.export.pkg>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.jt400</groupId>
+ <artifactId>jt400-full</artifactId>
+ <version>6.0</version>
+ </dependency>
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+ <!-- to allow Spring annotations (jmx) to be tested -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <optional>true</optional>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <optional>true</optional>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added:
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java?rev=677858&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java
(added)
+++
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java
Fri Jul 18 02:01:29 2008
@@ -0,0 +1,47 @@
+/**
+ * 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.Map;
+
+import org.apache.camel.CamelException;
+import org.apache.camel.Component;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * [EMAIL PROTECTED] Component} to provide integration with AS/400 objects.
+ *
+ * Current implementation only supports working with data queues (*DTAQ)
+ */
+public class Jt400Component extends DefaultComponent<Exchange> {
+
+ private static final String DATA_QUEUE = "DTAQ";
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected Endpoint<Exchange> createEndpoint(String uri, String remaining,
Map properties)
+ throws Exception {
+ String type = remaining.substring(remaining.lastIndexOf(".") +
1).toUpperCase();
+
+ if (DATA_QUEUE.equals(type)) {
+ return new Jt400DataQueueEndpoint(uri, this);
+ }
+ throw new CamelException(String.format("AS/400 Object type %s is not
supported", type));
+ }
+}
Added:
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java?rev=677858&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java
(added)
+++
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java
Fri Jul 18 02:01:29 2008
@@ -0,0 +1,124 @@
+/**
+ * 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.io.IOException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.PollingConsumerSupport;
+
+import com.ibm.as400.access.AS400;
+import com.ibm.as400.access.AS400SecurityException;
+import com.ibm.as400.access.DataQueue;
+import com.ibm.as400.access.DataQueueEntry;
+import com.ibm.as400.access.ErrorCompletingRequestException;
+import com.ibm.as400.access.IllegalObjectTypeException;
+import com.ibm.as400.access.ObjectDoesNotExistException;
+
+/**
+ * [EMAIL PROTECTED] PollingConsumer} that polls a data queue for data
+ */
+public class Jt400DataQueueConsumer extends PollingConsumerSupport<Exchange> {
+
+ private final Jt400DataQueueEndpoint endpoint;
+
+ /**
+ * Creates a new consumer instance
+ */
+ protected Jt400DataQueueConsumer(Jt400DataQueueEndpoint endpoint) {
+ super(endpoint);
+ this.endpoint = endpoint;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ if (!endpoint.getSystem().isConnected()) {
+ endpoint.getSystem().connectService(AS400.DATAQUEUE);
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ if (endpoint.getSystem().isConnected()) {
+ endpoint.getSystem().disconnectAllServices();
+ }
+ }
+
+ /**
+ * [EMAIL PROTECTED] Jt400DataQueueConsumer#receive(long)}
+ */
+ public Exchange receive() {
+ // -1 to indicate a blocking read from data queue
+ return receive(-1);
+ }
+
+ /**
+ * [EMAIL PROTECTED] Jt400DataQueueConsumer#receive(long)}
+ */
+ public Exchange receiveNoWait() {
+ return receive(0);
+ }
+
+ /**
+ * Receives an entry from a data queue and returns an [EMAIL PROTECTED]
Exchange} to
+ * send this data If the endpoint's format is set to [EMAIL PROTECTED]
Format#binary},
+ * the data queue entry's data will be received/sent as a
+ * <code>byte[]</code>. If the endpoint's format is set to
+ * [EMAIL PROTECTED] Format#text}, the data queue entry's data will be
received/sent as
+ * a <code>String</code>.
+ *
+ * @param timeout time to wait when reading from data queue. A value of -1
+ * indicates a blocking read.
+ */
+ public Exchange receive(long timeout) {
+ DataQueue queue = endpoint.getDataQueue();
+ try {
+ DataQueueEntry entry;
+ if (timeout >= 0) {
+ entry = queue.read((int)timeout);
+ } else {
+ entry = queue.read();
+ }
+ Exchange exchange = new
DefaultExchange(endpoint.getCamelContext());
+ if (entry != null) {
+ if (endpoint.getFormat() == Format.binary) {
+ exchange.getIn().setBody(entry.getData());
+ } else {
+ exchange.getIn().setBody(entry.getString());
+ }
+ return exchange;
+ }
+ } catch (AS400SecurityException e) {
+ throw new RuntimeCamelException("Unable to read from data queue: "
+ e.getMessage(), e);
+ } catch (ErrorCompletingRequestException e) {
+ throw new RuntimeCamelException("Unable to read from data queue: "
+ e.getMessage(), e);
+ } catch (IOException e) {
+ throw new RuntimeCamelException("Unable to read from data queue: "
+ e.getMessage(), e);
+ } catch (IllegalObjectTypeException e) {
+ throw new RuntimeCamelException("Unable to read from data queue: "
+ e.getMessage(), e);
+ } catch (InterruptedException e) {
+ throw new RuntimeCamelException("Unable to read from data queue: "
+ e.getMessage(), e);
+ } catch (ObjectDoesNotExistException e) {
+ throw new RuntimeCamelException("Unable to read from data queue: "
+ e.getMessage(), e);
+ }
+ return null;
+ }
+}
Added:
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java?rev=677858&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
(added)
+++
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java
Fri Jul 18 02:01:29 2008
@@ -0,0 +1,109 @@
+/**
+ * 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 org.apache.camel.CamelException;
+import org.apache.camel.Exchange;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultPollingEndpoint;
+
+import com.ibm.as400.access.AS400;
+import com.ibm.as400.access.DataQueue;
+
+/**
+ * AS/400 Data queue endpoint
+ */
+public class Jt400DataQueueEndpoint extends DefaultPollingEndpoint<Exchange> {
+
+ /**
+ * Enumeration of supported data formats
+ */
+ public enum Format {
+
+ /**
+ * Using <code>String</code> for transferring data
+ */
+ text,
+
+ /**
+ * Using <code>byte[]</code> for transferring data
+ */
+ binary;
+ }
+
+ private final AS400 system;
+ private final String objectPath;
+ private DataQueue dataqueue;
+ private Format format = Format.text;
+
+ /**
+ * Creates a new AS/400 data queue endpoint
+ */
+ protected Jt400DataQueueEndpoint(String endpointUri, Jt400Component
component) throws CamelException {
+ super(endpointUri, component);
+ try {
+ URI uri = new URI(endpointUri);
+ String[] credentials = uri.getUserInfo().split(":");
+ system = new AS400(uri.getHost(), credentials[0], credentials[1]);
+ objectPath = uri.getPath();
+ } catch (URISyntaxException e) {
+ throw new CamelException("Unable to parse URI for " + endpointUri,
e);
+ }
+ }
+
+ public void setCcsid(int ccsid) throws PropertyVetoException {
+ this.system.setCcsid(ccsid);
+ }
+
+ public void setFormat(Format format) {
+ this.format = format;
+ }
+
+ public Format getFormat() {
+ return format;
+ }
+
+ @Override
+ public PollingConsumer<Exchange> createPollingConsumer() throws Exception {
+ return new Jt400DataQueueConsumer(this);
+ }
+
+ public Producer<Exchange> createProducer() throws Exception {
+ return new Jt400DataQueueProducer(this);
+ }
+
+ protected AS400 getSystem() {
+ return system;
+ }
+
+ protected DataQueue getDataQueue() {
+ if (dataqueue == null) {
+ dataqueue = new DataQueue(system, objectPath);
+ }
+ return dataqueue;
+ }
+
+ public boolean isSingleton() {
+ return false;
+ }
+
+}
Added:
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java?rev=677858&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java
(added)
+++
activemq/camel/trunk/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java
Fri Jul 18 02:01:29 2008
@@ -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 org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format;
+import org.apache.camel.impl.DefaultProducer;
+
+import com.ibm.as400.access.AS400;
+import com.ibm.as400.access.DataQueue;
+
+/**
+ * [EMAIL PROTECTED] Producer} to send data to an AS/400 data queue.
+ */
+public class Jt400DataQueueProducer extends DefaultProducer<Exchange> {
+
+ private final Jt400DataQueueEndpoint endpoint;
+
+ protected Jt400DataQueueProducer(Jt400DataQueueEndpoint endpoint) {
+ super(endpoint);
+ this.endpoint = endpoint;
+ }
+
+ /**
+ * Sends the [EMAIL PROTECTED] Exchange}'s in body to the AS/400 data
queue. If the
+ * endpoint's format is set to [EMAIL PROTECTED] Format#binary}, the data
queue entry's
+ * data will be sent as a <code>byte[]</code>. If the endpoint's format is
+ * set to [EMAIL PROTECTED] Format#text}, the data queue entry's data will
be sent as a
+ * <code>String</code>.
+ */
+ public void process(Exchange exchange) throws Exception {
+ DataQueue queue = endpoint.getDataQueue();
+ if (endpoint.getFormat() == Format.binary) {
+ queue.write(exchange.getIn().getBody(byte[].class));
+ } else {
+ queue.write(exchange.getIn().getBody(String.class));
+ }
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ if (!endpoint.getSystem().isConnected()) {
+ endpoint.getSystem().connectService(AS400.DATAQUEUE);
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ if (endpoint.getSystem().isConnected()) {
+ endpoint.getSystem().disconnectAllServices();
+ }
+ }
+
+}
Added:
activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/services/org/apache/camel/component/jt400
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/services/org/apache/camel/component/jt400?rev=677858&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/services/org/apache/camel/component/jt400
(added)
+++
activemq/camel/trunk/components/camel-jt400/src/main/resources/META-INF/services/org/apache/camel/component/jt400
Fri Jul 18 02:01:29 2008
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.jt400.Jt400Component
\ No newline at end of file
Added:
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java?rev=677858&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java
(added)
+++
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java
Fri Jul 18 02:01:29 2008
@@ -0,0 +1,64 @@
+/**
+ * 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 junit.framework.TestCase;
+
+import org.apache.camel.CamelException;
+import org.apache.camel.Endpoint;
+
+/**
+ * Test case for [EMAIL PROTECTED] Jt400Component}
+ */
[EMAIL PROTECTED]("unchecked")
+public class Jt400ComponentTest extends TestCase {
+
+ private Jt400Component component;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ component = new Jt400Component();
+ }
+
+ /**
+ * Test creation of a [EMAIL PROTECTED] Jt400DataQueueEndpoint}
+ */
+ public void testCreateEndpoint() throws Exception {
+ Endpoint endpoint = component
+ .createEndpoint("jt400://user:[EMAIL
PROTECTED]/qsys.lib/library.lib/queue.dtaq",
+ "/user:[EMAIL
PROTECTED]/qsys.lib/library.lib/queue.dtaq", new HashMap());
+ assertNotNull(endpoint);
+ assertTrue(endpoint instanceof Jt400DataQueueEndpoint);
+ }
+
+ /**
+ * Test exception when trying to access any other object type on AS/400
+ */
+ public void testCreateEndpointForOtherObjectType() throws Exception {
+ try {
+ component.createEndpoint("jt400://user:[EMAIL
PROTECTED]/qsys.lib/library.lib/program.pgm",
+ "/user:[EMAIL
PROTECTED]/qsys.lib/library.lib/program.pgm", new HashMap());
+ 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
+ }
+ }
+
+}
Added:
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java?rev=677858&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java
(added)
+++
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java
Fri Jul 18 02:01:29 2008
@@ -0,0 +1,44 @@
+/**
+ * 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.ContextTestSupport;
+import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format;
+
+/**
+ * Test case for [EMAIL PROTECTED] Jt400DataQueueEndpoint}
+ */
+public class Jt400DataQueueEndpointTest extends ContextTestSupport {
+
+ private Jt400DataQueueEndpoint endpoint;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ endpoint =
(Jt400DataQueueEndpoint)resolveMandatoryEndpoint("jt400://user:[EMAIL
PROTECTED]/qsys.lib/library.lib/queue.dtaq?ccsid=500&format=binary");
+ }
+
+ /**
+ * Check that the AS/400 connection is correctly configured for the URL
+ */
+ public void testSystemConfiguration() {
+ assertEquals("USER", endpoint.getSystem().getUserId());
+ assertEquals("host", endpoint.getSystem().getSystemName());
+ assertEquals(500, endpoint.getSystem().getCcsid());
+ assertEquals(Format.binary, endpoint.getFormat());
+ }
+}
Added:
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400RouteTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400RouteTest.java?rev=677858&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400RouteTest.java
(added)
+++
activemq/camel/trunk/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400RouteTest.java
Fri Jul 18 02:01:29 2008
@@ -0,0 +1,64 @@
+/**
+ * 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.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * Test case for routes that contain <code>jt400:</code> endpoints This test
+ * case does nothing by default -- you can use it to test integration when
there
+ * is a real AS/400 system available by filling in correct values for
+ * [EMAIL PROTECTED] #USER}, [EMAIL PROTECTED] #PASSWORD}, [EMAIL PROTECTED]
#SYSTEM}, [EMAIL PROTECTED] #LIBRARY} and
+ * [EMAIL PROTECTED] #QUEUE}
+ */
+public class Jt400RouteTest extends ContextTestSupport {
+
+ // fill in correct values for all constants to test with a real AS/400
+ // system
+ private static final String USER = "username";
+ private static final String PASSWORD = "password";
+ private static final String SYSTEM = null;
+ private static final String LIBRARY = "library";
+ private static final String QUEUE = "queue";
+
+ public void testBasicTest() throws Exception {
+ if (SYSTEM != null) {
+ MockEndpoint endpoint = getMockEndpoint("mock:a");
+ endpoint.expectedBodiesReceived("Test message");
+ sendBody("direct:a", "Test message");
+ endpoint.assertIsSatisfied();
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ if (SYSTEM != null) {
+ String uri = String.format("jt400://%s:[EMAIL
PROTECTED]/QSYS.LIB/%s.LIB/%s.DTAQ", USER, PASSWORD,
+ SYSTEM, LIBRARY, QUEUE);
+ from("direct:a").to(uri);
+ from(uri).to("mock:a");
+ }
+ }
+ };
+ }
+}
Added:
activemq/camel/trunk/components/camel-jt400/src/test/resources/log4j.properties
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jt400/src/test/resources/log4j.properties?rev=677858&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jt400/src/test/resources/log4j.properties
(added)
+++
activemq/camel/trunk/components/camel-jt400/src/test/resources/log4j.properties
Fri Jul 18 02:01:29 2008
@@ -0,0 +1,30 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# The logging properties used for testing
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following to enable camel debugging
+# log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} -
%m%n