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/01/02 17:00:01 UTC
svn commit: r1226449 [4/5] - in /camel/trunk: ./ apache-camel/
apache-camel/src/main/descriptors/ components/ components/camel-mina2/
components/camel-mina2/src/ components/camel-mina2/src/main/
components/camel-mina2/src/main/java/ components/camel-mi...
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineProtocolTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineProtocolTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineProtocolTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineProtocolTest.java Mon Jan 2 15:59:58 2012
@@ -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.mina2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2TcpTextlineProtocolTest extends BaseMina2Test {
+
+ @Test
+ public void testMinaRoute() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ Object body = "Hello there!";
+ endpoint.expectedBodiesReceived(body);
+
+ template.sendBodyAndHeader("mina2:tcp://localhost:{{port}}?textline=true&sync=false", body, "cheese", 123);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:tcp://localhost:{{port}}?textline=true&sync=false").to("log:before?showAll=true").to("mock:result").to("log:after?showAll=true");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineProtocolTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpTextlineProtocolTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,135 @@
+/**
+ * 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.mina2;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2TcpWithInOutTest extends BaseMina2Test {
+
+ private String uri;
+ private Exchange receivedExchange;
+ private CountDownLatch latch;
+
+ @Test
+ public void testMinaRouteWithInOut() throws Exception {
+ latch = new CountDownLatch(1);
+ uri = "mina2:tcp://localhost:{{port}}?textline=true";
+
+ Mina2ReverserServer server = new Mina2ReverserServer(getPort());
+ server.start();
+
+ context.addRoutes(new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:x").to(uri).process(new Processor() {
+
+ public void process(Exchange e) {
+ receivedExchange = e;
+ latch.countDown();
+ }
+ });
+ }
+ });
+ context.start();
+
+ // now lets fire in a message
+ Endpoint endpoint = context.getEndpoint("direct:x");
+ Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
+ Message message = exchange.getIn();
+ message.setBody("Hello!");
+ message.setHeader("cheese", 123);
+
+ Producer producer = endpoint.createProducer();
+ producer.start();
+ producer.process(exchange);
+
+ // now lets sleep for a while
+ boolean received = latch.await(5, TimeUnit.SECONDS);
+ assertTrue("Did not receive the message!", received);
+ assertNotNull(receivedExchange.getIn());
+ assertEquals("!olleH", receivedExchange.getIn().getBody());
+
+ producer.stop();
+ context.stop();
+ server.stop();
+ }
+
+ @Test
+ public void testMinaRouteWithInOutLazy() throws Exception {
+ latch = new CountDownLatch(1);
+ uri = "mina2:tcp://localhost:{{port}}?textline=true&lazySessionCreation=true";
+
+ // The server is activated after Camel to check if the lazyness is working
+ Mina2ReverserServer server = new Mina2ReverserServer(getPort());
+ server.start();
+
+ context.addRoutes(new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:x").to(uri).process(new Processor() {
+
+ public void process(Exchange e) {
+ receivedExchange = e;
+ latch.countDown();
+ }
+ });
+ }
+ });
+ context.start();
+
+ // now lets fire in a message
+ Endpoint endpoint = context.getEndpoint("direct:x");
+ Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
+ Message message = exchange.getIn();
+ message.setBody("Hello!");
+ message.setHeader("cheese", 123);
+
+ Producer producer = endpoint.createProducer();
+ producer.start();
+ producer.process(exchange);
+
+ // now lets sleep for a while
+ boolean received = latch.await(5, TimeUnit.SECONDS);
+ assertTrue("Did not receive the message!", received);
+ assertNotNull(receivedExchange.getIn());
+ assertEquals("!olleH", receivedExchange.getIn().getBody());
+
+ producer.stop();
+ context.stop();
+ server.stop();
+ }
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutUsingPlainSocketTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutUsingPlainSocketTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutUsingPlainSocketTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutUsingPlainSocketTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,146 @@
+/**
+ * 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.mina2;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * To test camel-mina component using a TCP client that communicates using TCP socket communication.
+ *
+ * @version
+ */
+public class Mina2TcpWithInOutUsingPlainSocketTest extends BaseMina2Test {
+
+ @Test
+ public void testSendAndReceiveOnce() throws Exception {
+ String response = sendAndReceive("World");
+
+ assertNotNull("Nothing received from Mina", response);
+ assertEquals("Hello World", response);
+ }
+
+ @Test
+ public void testSendAndReceiveTwice() throws Exception {
+ String london = sendAndReceive("London");
+ String paris = sendAndReceive("Paris");
+
+ assertNotNull("Nothing received from Mina", london);
+ assertNotNull("Nothing received from Mina", paris);
+ assertEquals("Hello London", london);
+ assertEquals("Hello Paris", paris);
+ }
+
+ @Test
+ public void testReceiveNoResponseSinceOutBodyIsNull() throws Exception {
+ String out = sendAndReceive("force-null-out-body");
+ assertNull("no data should be recieved", out);
+ }
+
+ @Test
+ public void testReceiveNoResponseSinceOutBodyIsNullTwice() throws Exception {
+ String out = sendAndReceive("force-null-out-body");
+ assertNull("no data should be recieved", out);
+
+ out = sendAndReceive("force-null-out-body");
+ assertNull("no data should be recieved", out);
+ }
+
+ @Test
+ public void testExchangeFailedOutShouldBeNull() throws Exception {
+ String out = sendAndReceive("force-exception");
+ assertTrue("out should not be the same as in when the exchange has failed", !"force-exception".equals(out));
+ assertEquals("should get the exception here", out, "java.lang.IllegalArgumentException: Forced exception");
+ }
+
+ private String sendAndReceive(String input) throws IOException {
+ byte buf[] = new byte[128];
+
+ Socket soc = new Socket();
+ soc.connect(new InetSocketAddress("localhost", getPort()));
+
+ // Send message using plain Socket to test if this works
+ OutputStream os = null;
+ InputStream is = null;
+ try {
+ os = soc.getOutputStream();
+ // must append newline at the end to flag end of textline to Camel-Mina
+ os.write((input + "\n").getBytes());
+
+ is = soc.getInputStream();
+ int len = is.read(buf);
+ if (len == -1) {
+ // no data received
+ return null;
+ }
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ if (os != null) {
+ os.close();
+ }
+ soc.close();
+ }
+
+ // convert the buffer to chars
+ StringBuilder sb = new StringBuilder();
+ for (byte b : buf) {
+ char ch = (char) b;
+ if (ch == '\n' || ch == 0) {
+ // newline denotes end of text (added in the end in the processor below)
+ break;
+ } else {
+ sb.append(ch);
+ }
+ }
+
+ return sb.toString();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:tcp://localhost:{{port}}?textline=true&sync=true").process(new Processor() {
+
+ public void process(Exchange e) {
+ String in = e.getIn().getBody(String.class);
+ if ("force-null-out-body".equals(in)) {
+ // forcing a null out body
+ e.getOut().setBody(null);
+ } else if ("force-exception".equals(in)) {
+ // clear out before throwing exception
+ e.getOut().setBody(null);
+ throw new IllegalArgumentException("Forced exception");
+ } else {
+ e.getOut().setBody("Hello " + in);
+ }
+ }
+ });
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutUsingPlainSocketTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithInOutUsingPlainSocketTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithIoOutProcessorExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithIoOutProcessorExceptionTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithIoOutProcessorExceptionTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithIoOutProcessorExceptionTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,56 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * To unit test CAMEL-364.
+ */
+public class Mina2TcpWithIoOutProcessorExceptionTest extends BaseMina2Test {
+
+ @Test
+ public void testExceptionThrownInProcessor() {
+ String body = "Hello World";
+ Object result = template.requestBody("mina2:tcp://localhost:{{port}}?textline=true&sync=true", body);
+ // The exception should be passed to the client
+ assertNotNull("the result should not be null", result);
+ assertEquals("result is IllegalArgumentException", result, "java.lang.IllegalArgumentException: Forced exception");
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ // use no delay for fast unit testing
+ errorHandler(defaultErrorHandler().maximumRedeliveries(2));
+
+ from("mina2:tcp://localhost:{{port}}?textline=true&sync=true").process(new Processor() {
+
+ public void process(Exchange e) {
+ assertEquals("Hello World", e.getIn().getBody(String.class));
+ // simulate a problem processing the input to see if we can handle it properly
+ throw new IllegalArgumentException("Forced exception");
+ }
+ });
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithIoOutProcessorExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TcpWithIoOutProcessorExceptionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TransferExchangeOptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TransferExchangeOptionTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TransferExchangeOptionTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TransferExchangeOptionTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,139 @@
+/**
+ * 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.mina2;
+
+import java.nio.charset.Charset;
+
+import junit.framework.Assert;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Unit test for the <tt>transferExchange=true</tt> option.
+ *
+ * @version
+ */
+public class Mina2TransferExchangeOptionTest extends BaseMina2Test {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(Mina2TransferExchangeOptionTest.class);
+
+ @Test
+ public void testMinaTransferExchangeOptionWithoutException() throws Exception {
+ Exchange exchange = sendExchange(false);
+ assertExchange(exchange, false);
+ }
+
+ @Test
+ public void testMinaTransferExchangeOptionWithException() throws Exception {
+ Exchange exchange = sendExchange(true);
+ assertExchange(exchange, true);
+ }
+
+ private Exchange sendExchange(boolean setException) throws Exception {
+ Endpoint endpoint = context.getEndpoint("mina2:tcp://localhost:{{port}}?sync=true&encoding=UTF-8&transferExchange=true");
+ Producer producer = endpoint.createProducer();
+ Exchange exchange = producer.createExchange();
+ //Exchange exchange = endpoint.createExchange();
+
+ Message message = exchange.getIn();
+ message.setBody("Hello!");
+ message.setHeader("cheese", "feta");
+ exchange.setProperty("ham", "old");
+ exchange.setProperty("setException", setException);
+
+ producer.start();
+ producer.process(exchange);
+
+ return exchange;
+ }
+
+ private void assertExchange(Exchange exchange, boolean hasFault) {
+ if (!hasFault) {
+ Message out = exchange.getOut();
+ assertNotNull(out);
+ assertFalse(out.isFault());
+ assertEquals("Goodbye!", out.getBody());
+ assertEquals("cheddar", out.getHeader("cheese"));
+ } else {
+ Message fault = exchange.getOut();
+ assertNotNull(fault);
+ assertTrue(fault.isFault());
+ assertNotNull(fault.getBody());
+ assertTrue("Should get the InterrupteException exception", fault.getBody() instanceof InterruptedException);
+ assertEquals("nihao", fault.getHeader("hello"));
+ }
+
+
+ // in should stay the same
+ Message in = exchange.getIn();
+ assertNotNull(in);
+ assertEquals("Hello!", in.getBody());
+ assertEquals("feta", in.getHeader("cheese"));
+ // however the shared properties have changed
+ assertEquals("fresh", exchange.getProperty("salami"));
+ assertNull(exchange.getProperty("Charset"));
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:tcp://localhost:{{port}}?sync=true&encoding=UTF-8&transferExchange=true").process(new Processor() {
+
+ public void process(Exchange e) throws InterruptedException {
+ LOG.debug("Enter Processor...");
+ Assert.assertNotNull(e.getIn().getBody());
+ LOG.debug("Enter Processor...1");
+ Assert.assertNotNull(e.getIn().getHeaders());
+ LOG.debug("Enter Processor...2");
+ Assert.assertNotNull(e.getProperties());
+ LOG.debug("Enter Processor...3");
+ Assert.assertEquals("Hello!", e.getIn().getBody());
+ LOG.debug("Enter Processor...4");
+ Assert.assertEquals("feta", e.getIn().getHeader("cheese"));
+ LOG.debug("Enter Processor...5");
+ Assert.assertEquals("old", e.getProperty("ham"));
+ LOG.debug("Enter Processor...6");
+ Assert.assertEquals(ExchangePattern.InOut, e.getPattern());
+ LOG.debug("Enter Processor...7");
+ Boolean setException = (Boolean) e.getProperty("setException");
+
+ if (setException) {
+ e.getOut().setFault(true);
+ e.getOut().setBody(new InterruptedException());
+ e.getOut().setHeader("hello", "nihao");
+ } else {
+ e.getOut().setBody("Goodbye!");
+ e.getOut().setHeader("cheese", "cheddar");
+ }
+ e.setProperty("salami", "fresh");
+ e.setProperty("Charset", Charset.defaultCharset());
+ LOG.debug("Exit Processor...");
+ }
+ });
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TransferExchangeOptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2TransferExchangeOptionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpNoCamelTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpNoCamelTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpNoCamelTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpNoCamelTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,191 @@
+/**
+ * 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.mina2;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.nio.charset.Charset;
+import java.util.logging.Level;
+
+import org.apache.mina.core.service.IoHandlerAdapter;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.codec.textline.LineDelimiter;
+import org.apache.mina.filter.logging.LoggingFilter;
+import org.apache.mina.transport.socket.DatagramSessionConfig;
+import org.apache.mina.transport.socket.nio.NioDatagramAcceptor;
+import org.apache.mina.transport.socket.nio.NioDatagramConnector;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author chadbeaulac
+ */
+public class Mina2UdpNoCamelTest {
+
+ private static Logger logger = LoggerFactory.getLogger(Mina2UdpNoCamelTest.class);
+ Charset charset = Charset.defaultCharset();
+ LineDelimiter delimiter = LineDelimiter.DEFAULT;
+ Mina2TextLineCodecFactory codecFactory = new Mina2TextLineCodecFactory(charset, delimiter);
+ UDPServer server;
+
+ // Create the UDPServer before the test is run
+ @Before
+ public void setupUDPAcceptor() throws IOException {
+ server = new UDPServer("127.0.0.1", 1234);
+ server.listen();
+ }
+
+ @After
+ public void closeUDPAcceptor() throws IOException {
+ server.close();
+ }
+
+ @Test
+ public void testMinaUDPWithNoCamel() throws InterruptedException {
+ UDPClient client = new UDPClient();
+ client.connect("127.0.0.1", 1234);
+ for (int i = 0; i < 222; i++) {
+ client.sendNoMina("Hello Mina " + i + "\n");
+ }
+ Thread.sleep(2000);
+ assertEquals(222, server.numMessagesReceived);
+ }
+
+ /*
+ * Mina UDP Server
+ */
+ private final class UDPServer extends IoHandlerAdapter {
+
+ private final String host;
+ private final int port;
+ private final NioDatagramAcceptor acceptor;
+ private int numMessagesReceived;
+
+ private UDPServer(String host, int port) {
+ this.host = host;
+ this.port = port;
+ acceptor = new NioDatagramAcceptor();
+ DatagramSessionConfig sessionConfig = acceptor.getSessionConfig();
+ sessionConfig.setReuseAddress(true);
+ acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
+ acceptor.getFilterChain().addLast("logger", new LoggingFilter());
+ acceptor.setHandler(this);
+
+ }
+
+ public void listen() throws IOException {
+ acceptor.bind(new InetSocketAddress(host, port));
+
+ }
+
+ public void close() {
+ acceptor.unbind();
+ }
+
+ @Override
+ public void messageReceived(IoSession session, Object message) throws Exception {
+ logger.debug("UDPServer Received body: {}", message);
+ numMessagesReceived++;
+ }
+
+ @Override
+ public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
+ logger.error("Ooops! Something went wrong :|", cause);
+ }
+ }
+
+ private final class UDPClient extends IoHandlerAdapter {
+
+ /**
+ * Three optional arguments can be provided (defaults in brackets):
+ * path, host (localhost) and port (1234).
+ *
+ * @param args The command line args.
+ */
+ private final NioDatagramConnector connector;
+ private IoSession session;
+ private DatagramSocket socket;
+ private InetAddress address;
+ private int localPort = 1234;
+ private String localHost = "127.0.0.1";
+
+ private UDPClient() {
+ connector = new NioDatagramConnector();
+ connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(codecFactory));
+ //connector.getFilterChain().addLast("logger", new LoggingFilter());
+ connector.setHandler(this);
+
+ }
+
+ public void connect(String host, int port) {
+ localPort = port;
+ localHost = host;
+ session = connector.connect(new InetSocketAddress(localHost, localPort)).awaitUninterruptibly().
+ getSession();
+ try {
+ socket = new DatagramSocket();
+ address = InetAddress.getByName(localHost);
+
+ } catch (UnknownHostException ex) {
+ java.util.logging.Logger.getLogger(Mina2UdpNoCamelTest.class.getName()).log(
+ Level.SEVERE, null, ex);
+ } catch (SocketException ex) {
+ java.util.logging.Logger.getLogger(Mina2UdpNoCamelTest.class.getName()).log(
+ Level.SEVERE, null, ex);
+ }
+
+ }
+
+ public void send(String msg) {
+ session.write(msg);
+ }
+
+ public void sendNoMina(String msg) {
+ try {
+ DatagramPacket packet = new DatagramPacket(msg.getBytes(), msg.getBytes().length,
+ address, localPort);
+ socket.send(packet);
+ } catch (IOException ex) {
+ java.util.logging.Logger.getLogger(Mina2UdpNoCamelTest.class.getName()).log(
+ Level.SEVERE, null, ex);
+ }
+ }
+
+ @Override
+ public void messageReceived(IoSession session, Object message) throws Exception {
+ logger.debug("Client Received body: {}", message);
+ }
+
+ @Override
+ public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
+ logger.error("Ooops! Something went wrong :|", cause);
+ }
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpNoCamelTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpNoCamelTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,81 @@
+/**
+ * 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.mina2;
+
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2UdpTest extends BaseMina2Test {
+
+ protected int messageCount = 3;
+
+ public Mina2UdpTest() {
+ }
+
+ @Test
+ public void testMinaRoute() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ endpoint.expectedBodiesReceived("Hello Message: 0", "Hello Message: 1", "Hello Message: 2");
+
+ sendUdpMessages();
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected void sendUdpMessages() throws Exception {
+ DatagramSocket socket = new DatagramSocket();
+ try {
+ InetAddress address = InetAddress.getByName("127.0.0.1");
+ for (int i = 0; i < messageCount; i++) {
+ String text = "Hello Message: " + Integer.toString(i);
+ byte[] data = text.getBytes();
+
+ //DatagramPacket packet = new DatagramPacket(data, data.length, address, getPort());
+ DatagramPacket packet = new DatagramPacket(data, data.length, address, 10111);
+ socket.send(packet);
+ }
+ Thread.sleep(2000);
+ } finally {
+ socket.close();
+ }
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ int port2 = getNextPort();
+
+ //from("mina2:udp://127.0.0.1:" + getPort() + "?sync=false").to("mina2:udp://127.0.0.1:" + port2 + "?sync=false");
+ //from("mina2:udp://127.0.0.1:" + port2 + "?sync=false").to("mock:result");
+
+ //from("mina2:udp://127.0.0.1:10111?sync=false").to("mina2:udp://127.0.0.1:10112?sync=false");
+ //from("mina2:udp://127.0.0.1:10112?sync=false").to("mock:result");
+ from("mina2:udp://127.0.0.1:10111?sync=false&minaLogger=true").to("mock:result");
+ //from("mina2:udp://127.0.0.1:10111").to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpUsingTemplateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpUsingTemplateTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpUsingTemplateTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpUsingTemplateTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.mina2;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2UdpUsingTemplateTest extends BaseMina2Test {
+
+ private int messageCount = 3;
+
+ @Test
+ public void testMinaRoute() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ endpoint.expectedMessageCount(3);
+ endpoint.expectedBodiesReceived("Hello Message: 0", "Hello Message: 1", "Hello Message: 2");
+
+ sendUdpMessages();
+ // sleeping for while to let the mock endpoint get all the message
+ Thread.sleep(2000);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected void sendUdpMessages() throws Exception {
+ for (int i = 0; i < messageCount; i++) {
+ template.sendBody("mina2:udp://127.0.0.1:{{port}}?sync=false", "Hello Message: " + i);
+ }
+ }
+
+ @Test
+ public void testSendingByteMessages() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ endpoint.expectedMessageCount(1);
+
+ byte[] in = "Hello from bytes".getBytes();
+ template.sendBody("mina2:udp://127.0.0.1:{{port}}?sync=false", in);
+
+ // sleeping for while to let the mock endpoint get all the message
+ Thread.sleep(2000);
+
+ assertMockEndpointsSatisfied();
+ List<Exchange> list = endpoint.getReceivedExchanges();
+ byte[] out = list.get(0).getIn().getBody(byte[].class);
+
+ for (int i = 0; i < in.length; i++) {
+ assertEquals("Thew bytes should be the same", in[i], out[i]);
+ }
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:udp://127.0.0.1:{{port}}?sync=false&minaLogger=true").to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpUsingTemplateTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpUsingTemplateTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpWithInOutUsingPlainSocketTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpWithInOutUsingPlainSocketTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpWithInOutUsingPlainSocketTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpWithInOutUsingPlainSocketTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.mina2;
+
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * To test InOut exchange for the UDP protocol.
+ */
+public class Mina2UdpWithInOutUsingPlainSocketTest extends BaseMina2Test {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(Mina2UdpWithInOutUsingPlainSocketTest.class);
+
+ @Test
+ public void testSendAndReceiveOnce() throws Exception {
+ String out = sendAndReceiveUdpMessages("World");
+ assertNotNull("should receive data", out);
+ assertEquals("Hello World", out);
+ }
+
+ private String sendAndReceiveUdpMessages(String input) throws Exception {
+ DatagramSocket socket = new DatagramSocket();
+ InetAddress address = InetAddress.getByName("127.0.0.1");
+
+ byte[] data = input.getBytes();
+
+ DatagramPacket packet = new DatagramPacket(data, data.length, address, getPort());
+ LOG.debug("+++ Sending data +++");
+ socket.send(packet);
+
+ Thread.sleep(1000);
+
+ byte[] buf = new byte[128];
+ DatagramPacket receive = new DatagramPacket(buf, buf.length, address, getPort());
+ LOG.debug("+++ Receiveing data +++");
+ socket.receive(receive);
+
+ socket.close();
+
+ return new String(receive.getData(), 0, receive.getLength());
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:udp://127.0.0.1:{{port}}?sync=true").process(new Processor() {
+
+ public void process(Exchange exchange) throws Exception {
+ String s = exchange.getIn().getBody(String.class);
+ exchange.getOut().setBody("Hello " + s);
+ }
+ });
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpWithInOutUsingPlainSocketTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2UdpWithInOutUsingPlainSocketTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMCustomCodecTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMCustomCodecTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMCustomCodecTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMCustomCodecTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,136 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.junit.Test;
+
+/**
+ * Unit test with custom codec using the VM protocol.
+ */
+public class Mina2VMCustomCodecTest extends BaseMina2Test {
+
+ @Test
+ public void testMyCodec() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedBodiesReceived("Bye World");
+
+ Object out = template.requestBody("mina2:vm://localhost:{{port}}?sync=true&codec=#myCodec", "Hello World");
+ assertEquals("Bye World", out);
+
+ mock.assertIsSatisfied();
+ }
+
+ @Test
+ public void testTCPEncodeUTF8InputIsString() throws Exception {
+ final String myUri = "mina2:vm://localhost:" + getNextPort() + "?encoding=UTF-8&sync=false";
+ context.addRoutes(new RouteBuilder() {
+
+ public void configure() {
+ from(myUri).to("mock:result");
+ }
+ });
+
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+
+ // include a UTF-8 char in the text \u0E08 is a Thai elephant
+ String body = "Hello Thai Elephant \u0E08";
+
+ endpoint.expectedMessageCount(1);
+ endpoint.expectedBodiesReceived(body);
+
+ template.sendBody(myUri, body);
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testBadConfiguration() throws Exception {
+ try {
+ template.sendBody("mina2:vm://localhost:{{port}}?sync=true&codec=#XXX", "Hello World");
+ fail("Should have thrown a ResolveEndpointFailedException");
+ } catch (ResolveEndpointFailedException e) {
+ // ok
+ }
+ }
+
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("myCodec", new MyCodec());
+ return jndi;
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ public void configure() throws Exception {
+ from("mina2:vm://localhost:{{port}}?sync=true&codec=#myCodec").transform(constant("Bye World")).to("mock:result");
+ }
+ };
+ }
+
+ private static class MyCodec implements ProtocolCodecFactory {
+
+ @Override
+ public ProtocolEncoder getEncoder(IoSession is) throws Exception {
+ return new ProtocolEncoder() {
+
+ public void encode(IoSession ioSession, Object message, ProtocolEncoderOutput out)
+ throws Exception {
+ IoBuffer bb = IoBuffer.allocate(32).setAutoExpand(true);
+ String s = (String) message;
+ bb.put(s.getBytes("US-ASCII"));
+ bb.flip();
+ out.write(bb);
+ }
+
+ public void dispose(IoSession ioSession) throws Exception {
+ // do nothing
+ }
+ };
+
+ }
+
+ @Override
+ public ProtocolDecoder getDecoder(IoSession is) throws Exception {
+ return new CumulativeProtocolDecoder() {
+
+ protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
+ if (in.remaining() > 0) {
+ byte[] buf = new byte[in.remaining()];
+ in.get(buf);
+ out.write(new String(buf, "US-ASCII"));
+ return true;
+ } else {
+ return false;
+ }
+ }
+ };
+ }
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMCustomCodecTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMCustomCodecTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMFileTcpTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMFileTcpTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMFileTcpTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMFileTcpTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,49 @@
+/**
+ * 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.mina2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2VMFileTcpTest extends BaseMina2Test {
+
+ @Test
+ public void testMinaRoute() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:results");
+ endpoint.expectedMessageCount(1);
+ endpoint.message(0).body().startsWith("Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ // lets setup a server
+ from("mina2:vm://localhost:{{port}}?sync=false&textline=true").to("mock:results");
+
+ from("file:src/test/data?noop=true&fileName=message1.txt").
+ to("mina2:vm://localhost:{{port}}?sync=false&textline=true");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMFileTcpTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMFileTcpTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTextlineProtocolTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTextlineProtocolTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTextlineProtocolTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTextlineProtocolTest.java Mon Jan 2 15:59:58 2012
@@ -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.mina2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2VMTextlineProtocolTest extends BaseMina2Test {
+
+ @Test
+ public void testMinaRoute() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ Object body = "Hello there!";
+ endpoint.expectedBodiesReceived(body);
+
+ template.sendBodyAndHeader("mina2:vm://localhost:{{port}}?textline=true&sync=false", body, "cheese", 123);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:vm://localhost:{{port}}?textline=true&sync=false").to("log:before?showAll=true").to("mock:result").to("log:after?showAll=true");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTextlineProtocolTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTextlineProtocolTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTransferExchangeOptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTransferExchangeOptionTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTransferExchangeOptionTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTransferExchangeOptionTest.java Mon Jan 2 15:59:58 2012
@@ -0,0 +1,125 @@
+/**
+ * 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.mina2;
+
+import java.nio.charset.Charset;
+
+import junit.framework.Assert;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * Unit test for the <tt>transferExchange=true</tt> option.
+ *
+ * @version
+ */
+public class Mina2VMTransferExchangeOptionTest extends BaseMina2Test {
+
+ @Test
+ public void testMinaTransferExchangeOptionWithoutException() throws Exception {
+ Exchange exchange = sendExchange(false);
+ assertExchange(exchange, false);
+ }
+
+ @Test
+ public void testMinaTransferExchangeOptionWithException() throws Exception {
+ Exchange exchange = sendExchange(true);
+ assertExchange(exchange, true);
+ }
+
+ private Exchange sendExchange(boolean setException) throws Exception {
+ Endpoint endpoint = context.getEndpoint("mina2:vm://localhost:{{port}}?sync=true&encoding=UTF-8&transferExchange=true");
+ Exchange exchange = endpoint.createExchange();
+
+ Message message = exchange.getIn();
+ message.setBody("Hello!");
+ message.setHeader("cheese", "feta");
+ exchange.setProperty("ham", "old");
+ exchange.setProperty("setException", setException);
+
+ Producer producer = endpoint.createProducer();
+ producer.start();
+ producer.process(exchange);
+
+ return exchange;
+ }
+
+ private void assertExchange(Exchange exchange, boolean hasFault) {
+ if (!hasFault) {
+ Message out = exchange.getOut();
+ assertNotNull(out);
+ assertFalse(out.isFault());
+ assertEquals("Goodbye!", out.getBody());
+ assertEquals("cheddar", out.getHeader("cheese"));
+ } else {
+ Message fault = exchange.getOut();
+ assertNotNull(fault);
+ assertTrue(fault.isFault());
+ assertNotNull(fault.getBody());
+ assertTrue("Should get the InterrupteException exception", fault.getBody() instanceof InterruptedException);
+ assertEquals("nihao", fault.getHeader("hello"));
+ }
+
+
+ // in should stay the same
+ Message in = exchange.getIn();
+ assertNotNull(in);
+ assertEquals("Hello!", in.getBody());
+ assertEquals("feta", in.getHeader("cheese"));
+ // however the shared properties have changed
+ assertEquals("fresh", exchange.getProperty("salami"));
+ assertNull(exchange.getProperty("Charset"));
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:vm://localhost:{{port}}?sync=true&encoding=UTF-8&transferExchange=true").process(new Processor() {
+
+ public void process(Exchange e) throws InterruptedException {
+ Assert.assertNotNull(e.getIn().getBody());
+ Assert.assertNotNull(e.getIn().getHeaders());
+ Assert.assertNotNull(e.getProperties());
+ Assert.assertEquals("Hello!", e.getIn().getBody());
+ Assert.assertEquals("feta", e.getIn().getHeader("cheese"));
+ Assert.assertEquals("old", e.getProperty("ham"));
+ Assert.assertEquals(ExchangePattern.InOut, e.getPattern());
+ Boolean setException = (Boolean) e.getProperty("setException");
+
+ if (setException) {
+ e.getOut().setFault(true);
+ e.getOut().setBody(new InterruptedException());
+ e.getOut().setHeader("hello", "nihao");
+ } else {
+ e.getOut().setBody("Goodbye!");
+ e.getOut().setHeader("cheese", "cheddar");
+ }
+ e.setProperty("salami", "fresh");
+ e.setProperty("Charset", Charset.defaultCharset());
+ }
+ });
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTransferExchangeOptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VMTransferExchangeOptionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VmTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VmTest.java?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VmTest.java (added)
+++ camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VmTest.java Mon Jan 2 15:59:58 2012
@@ -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.mina2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class Mina2VmTest extends BaseMina2Test {
+
+ @Test
+ public void testMinaRoute() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:result");
+ Object body = "Hello there!";
+ endpoint.expectedBodiesReceived(body);
+
+ template.sendBodyAndHeader("mina2:vm://localhost:{{port}}?sync=false&minaLogger=true", body, "cheese", 123);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ public void configure() {
+ from("mina2:vm://localhost:{{port}}?sync=false&minaLogger=true").to("log:before?showAll=true").to("mock:result").to("log:after?showAll=true");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VmTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/java/org/apache/camel/component/mina2/Mina2VmTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-mina2/src/test/resources/jndi-example.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/resources/jndi-example.properties?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/resources/jndi-example.properties (added)
+++ camel/trunk/components/camel-mina2/src/test/resources/jndi-example.properties Mon Jan 2 15:59:58 2012
@@ -0,0 +1,22 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# START SNIPPET: jndi
+
+java.naming.factory.initial = org.apache.camel.util.jndi.CamelInitialContextFactory
+
+# END SNIPPET: jndi
Propchange: camel/trunk/components/camel-mina2/src/test/resources/jndi-example.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/resources/jndi-example.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-mina2/src/test/resources/jndi-example.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-mina2/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/resources/log4j.properties?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/resources/log4j.properties (added)
+++ camel/trunk/components/camel-mina2/src/test/resources/log4j.properties Mon Jan 2 15:59:58 2012
@@ -0,0 +1,36 @@
+## ---------------------------------------------------------------------------
+## 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 during tests..
+#
+log4j.rootLogger=INFO, file
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.org.apache.camel.component.mina2=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=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-ftp-test.log
\ No newline at end of file
Propchange: camel/trunk/components/camel-mina2/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-mina2/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointTest-context.xml?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointTest-context.xml (added)
+++ camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointTest-context.xml Mon Jan 2 15:59:58 2012
@@ -0,0 +1,61 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <!-- START SNIPPET: e1 -->
+ <!-- Creating mina endpoints is a bit complex so we reuse MinaComponnet
+ as a factory bean to create our endpoint, this is the easiest to do -->
+ <bean id="myMinaFactory" class="org.apache.camel.component.mina2.Mina2Component">
+ <!-- we must provide a camel context so we refer to it by its id -->
+ <constructor-arg index="0" ref="myCamel"/>
+ </bean>
+
+ <!-- This is our mina endpoint configured with spring, we will use the factory above
+ to create it for us. The goal is to invoke the createEndpoint method with the
+ mina configuration parameter we defined using the constructor-arg option -->
+ <bean id="myMinaEndpoint"
+ factory-bean="myMinaFactory"
+ factory-method="createEndpoint">
+ <!-- and here we can pass it our configuration -->
+ <constructor-arg index="0" ref="myMinaConfig"/>
+ </bean>
+
+ <!-- this is our mina configuration with plain properties -->
+ <bean id="myMinaConfig" class="org.apache.camel.component.mina2.Mina2Configuration">
+ <property name="protocol" value="tcp"/>
+ <property name="host" value="localhost"/>
+ <property name="port" value="1234"/>
+ <property name="sync" value="false"/>
+ </bean>
+ <!-- END SNIPPET: e1 -->
+
+ <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
+ <!-- START SNIPPET: e2 -->
+ <route>
+ <!-- here we route from or mina endpoint we have defined above -->
+ <from ref="myMinaEndpoint"/>
+ <to uri="mock:result"/>
+ </route>
+ <!-- END SNIPPET: e2 -->
+ </camelContext>
+
+</beans>
Propchange: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointTest-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointTest-context.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointTest-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointUDPTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointUDPTest-context.xml?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointUDPTest-context.xml (added)
+++ camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointUDPTest-context.xml Mon Jan 2 15:59:58 2012
@@ -0,0 +1,61 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <!-- START SNIPPET: e1 -->
+ <!-- Creating mina endpoints is a bit complex so we reuse MinaComponnet
+ as a factory bean to create our endpoint, this is the easiest to do -->
+ <bean id="myMinaFactory" class="org.apache.camel.component.mina2.Mina2Component">
+ <!-- we must provide a camel context so we refer to it by its id -->
+ <constructor-arg index="0" ref="myCamel"/>
+ </bean>
+
+ <!-- This is our mina endpoint configured with spring, we will use the factory above
+ to create it for us. The goal is to invoke the createEndpoint method with the
+ mina configuration parameter we defined using the constructor-arg option -->
+ <bean id="myMinaEndpoint"
+ factory-bean="myMinaFactory"
+ factory-method="createEndpoint">
+ <!-- and here we can pass it our configuration -->
+ <constructor-arg index="0" ref="myMinaConfig"/>
+ </bean>
+
+ <!-- this is our mina configuration with plain properties -->
+ <bean id="myMinaConfig" class="org.apache.camel.component.mina2.Mina2Configuration">
+ <property name="protocol" value="udp"/>
+ <property name="host" value="localhost"/>
+ <property name="port" value="1234"/>
+ <property name="sync" value="false"/>
+ </bean>
+ <!-- END SNIPPET: e1 -->
+
+ <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
+ <!-- START SNIPPET: e2 -->
+ <route>
+ <!-- here we route from or mina endpoint we have defined above -->
+ <from ref="myMinaEndpoint"/>
+ <to uri="mock:result"/>
+ </route>
+ <!-- END SNIPPET: e2 -->
+ </camelContext>
+
+</beans>
Propchange: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointUDPTest-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointUDPTest-context.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMinaEndpointUDPTest-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMultipleUDPTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMultipleUDPTest-context.xml?rev=1226449&view=auto
==============================================================================
--- camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMultipleUDPTest-context.xml (added)
+++ camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMultipleUDPTest-context.xml Mon Jan 2 15:59:58 2012
@@ -0,0 +1,64 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd" xmlns:ns2="null">
+
+ <!-- START SNIPPET: e1 -->
+ <!-- Creating mina endpoints is a bit complex so we reuse MinaComponnet
+ as a factory bean to create our endpoint, this is the easiest to do -->
+ <bean id="myMinaFactory" class="org.apache.camel.component.mina2.Mina2Component">
+ <!-- we must provide a camel context so we refer to it by its id -->
+ <constructor-arg index="0" ref="myCamel"/>
+ </bean>
+
+ <!-- This is our mina endpoint configured with spring, we will use the factory above
+ to create it for us. The goal is to invoke the createEndpoint method with the
+ mina configuration parameter we defined using the constructor-arg option -->
+ <bean id="myMinaEndpoint"
+ factory-bean="myMinaFactory"
+ factory-method="createEndpoint">
+ <!-- and here we can pass it our configuration -->
+ <constructor-arg index="0" ref="myMinaConfig"/>
+ </bean>
+
+ <!-- this is our mina configuration with plain properties -->
+ <bean id="myMinaConfig" class="org.apache.camel.component.mina2.Mina2Configuration">
+ <property name="protocol" value="udp"/>
+ <property name="host" value="localhost"/>
+ <property name="port" value="1234"/>
+ <property name="sync" value="false"/> <!-- InOut Exchange. Response is allowed -->
+ <property name="minaLogger" value="true"/>
+ <property name="textline" value="true"/>
+ <property name="encoding" value="UTF-8"/>
+ </bean>
+ <!-- END SNIPPET: e1 -->
+
+ <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
+ <!-- START SNIPPET: e2 -->
+ <route>
+ <!-- here we route from or mina endpoint we have defined above -->
+ <from ref="myMinaEndpoint"/>
+ <to uri="mock:result"/>
+ </route>
+ <!-- END SNIPPET: e2 -->
+ </camelContext>
+
+</beans>
Propchange: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMultipleUDPTest-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMultipleUDPTest-context.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-mina2/src/test/resources/org/apache/camel/component/mina2/SpringMultipleUDPTest-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/pom.xml?rev=1226449&r1=1226448&r2=1226449&view=diff
==============================================================================
--- camel/trunk/components/pom.xml (original)
+++ camel/trunk/components/pom.xml Mon Jan 2 15:59:58 2012
@@ -102,6 +102,7 @@
<module>camel-lucene</module>
<module>camel-mail</module>
<module>camel-mina</module>
+ <module>camel-mina2</module>
<module>camel-msv</module>
<module>camel-mvel</module>
<module>camel-mybatis</module>
Modified: camel/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/parent/pom.xml?rev=1226449&r1=1226448&r2=1226449&view=diff
==============================================================================
--- camel/trunk/parent/pom.xml (original)
+++ camel/trunk/parent/pom.xml Mon Jan 2 15:59:58 2012
@@ -118,6 +118,7 @@
<log4j-version>1.2.16</log4j-version>
<lucene-version>3.0.3</lucene-version>
<mina-version>1.1.7</mina-version>
+ <mina2-version>2.0.4</mina2-version>
<mockito-version>1.8.5</mockito-version>
<mvel-version>2.0.18</mvel-version>
<mybatis-version>3.0.6</mybatis-version>
@@ -180,7 +181,7 @@
org.apache.qpid.*;version="[0.12,0.13)",
org.apache.abdera.*;version="[0.4,2)",
org.apache.commons.httpclient.*;version="[3.1,4.0)",
- org.apache.mina.*;version="[1.1.7,2.0)",
+ org.apache.mina.*;version="[1.1.7,3.0)",
org.apache.velocity.*;version="[1.6.2,2)",
org.apache.xmlbeans.*;version="[2.4,3)",
org.eclipse.jetty.*;version="[7.0,8)",
@@ -546,6 +547,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-mina2</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-msv</artifactId>
<version>${project.version}</version>
</dependency>
Modified: camel/trunk/platforms/karaf/features/src/main/resources/features.xml
URL: http://svn.apache.org/viewvc/camel/trunk/platforms/karaf/features/src/main/resources/features.xml?rev=1226449&r1=1226448&r2=1226449&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/features/src/main/resources/features.xml (original)
+++ camel/trunk/platforms/karaf/features/src/main/resources/features.xml Mon Jan 2 15:59:58 2012
@@ -108,7 +108,12 @@
<bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.mina/${mina-bundle-version}</bundle>
<bundle>mvn:org.apache.camel/camel-mina/${project.version}</bundle>
</feature>
- <feature name='camel-jetty' version='${project.version}' resolver='(obr)' start-level='50'>
+ <feature name='camel-mina2' version='${pom.version}' resolver='(obr)' start-level='50'>
+ <feature version='${pom.version}'>camel-core</feature>
+ <bundle dependency="true">mvn:org.apache.mina/mina-core/${mina2-version}</bundle>
+ <bundle>mvn:org.apache.camel/camel-mina2/${pom.version}</bundle>
+ </feature>
+ <feature name='camel-jetty' version='${pom.version}' resolver='(obr)' start-level='50'>
<feature>jetty</feature>
<feature version='${project.version}'>camel-core</feature>
<feature version='${project.version}'>camel-http</feature>