You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2017/10/03 14:38:24 UTC
[2/3] camel git commit: CAMEL-11696: Add an advanced properties to
the camel-thrift component
http://git-wip-us.apache.org/repos/asf/camel/blob/5a501706/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java
----------------------------------------------------------------------
diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java
new file mode 100644
index 0000000..8fd916c
--- /dev/null
+++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java
@@ -0,0 +1,211 @@
+/**
+ * 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.thrift;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.thrift.generated.Calculator;
+import org.apache.camel.component.thrift.generated.InvalidOperation;
+import org.apache.camel.component.thrift.generated.Operation;
+import org.apache.camel.component.thrift.generated.Work;
+import org.apache.camel.component.thrift.impl.CalculatorSyncServerImpl;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.thrift.TProcessor;
+import org.apache.thrift.server.TServer;
+import org.apache.thrift.server.TThreadPoolServer;
+import org.apache.thrift.transport.TSSLTransportFactory;
+import org.apache.thrift.transport.TServerSocket;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ThriftProducerSecurityTest extends CamelTestSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(ThriftProducerSecurityTest.class);
+
+ private static TServerSocket serverTransport;
+ private static TServer server;
+ @SuppressWarnings({"rawtypes"})
+ private static Calculator.Processor processor;
+
+ private static final int THRIFT_TEST_PORT = AvailablePortFinder.getNextAvailable();
+ private static final int THRIFT_TEST_NUM1 = 12;
+ private static final int THRIFT_TEST_NUM2 = 13;
+
+ private static final String TRUST_STORE_PATH = "src/test/resources/certs/truststore.jks";
+ private static final String KEY_STORE_PATH = "src/test/resources/certs/keystore.jks";
+ private static final String SECURITY_STORE_PASSWORD = "camelinaction";
+ private static final int THRIFT_CLIENT_TIMEOUT = 2000;
+
+ @BeforeClass
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public static void startThriftServer() throws Exception {
+ processor = new Calculator.Processor(new CalculatorSyncServerImpl());
+
+ TSSLTransportFactory.TSSLTransportParameters sslParams = new TSSLTransportFactory.TSSLTransportParameters();
+
+ sslParams.setKeyStore(KEY_STORE_PATH, SECURITY_STORE_PASSWORD);
+ serverTransport = TSSLTransportFactory.getServerSocket(THRIFT_TEST_PORT, THRIFT_CLIENT_TIMEOUT, InetAddress.getByName("localhost"), sslParams);
+ TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport);
+ args.processor((TProcessor)processor);
+ server = new TThreadPoolServer(args);
+
+ Runnable simple = new Runnable() {
+ public void run() {
+ LOG.info("Thrift secured server started on port: {}", THRIFT_TEST_PORT);
+ server.serve();
+ }
+ };
+ new Thread(simple).start();
+ }
+
+ @AfterClass
+ public static void stopThriftServer() throws IOException {
+ if (server != null) {
+ server.stop();
+ serverTransport.close();
+ LOG.info("Thrift secured server stoped");
+ }
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ ThriftSSLConfiguration sslConfig = new ThriftSSLConfiguration();
+
+ sslConfig.setTrustStorePath(TRUST_STORE_PATH);
+ sslConfig.setTrustPassword(SECURITY_STORE_PASSWORD);
+ jndi.bind("sslConfig", sslConfig);
+ return jndi;
+ }
+
+ @Test
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void testCalculateMethodInvocation() throws Exception {
+ LOG.info("Thrift calculate method sync test start");
+
+ List requestBody = new ArrayList();
+
+ requestBody.add((int)1);
+ requestBody.add(new Work(THRIFT_TEST_NUM1, THRIFT_TEST_NUM2, Operation.MULTIPLY));
+
+ Object responseBody = template.requestBody("direct:thrift-secured-calculate", requestBody);
+
+ assertNotNull(responseBody);
+ assertTrue(responseBody instanceof Integer);
+ assertEquals(THRIFT_TEST_NUM1 * THRIFT_TEST_NUM2, responseBody);
+ }
+
+ @Test
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void testCalculateWithException() throws Exception {
+ LOG.info("Thrift calculate method with business exception sync test start");
+
+ List requestBody = new ArrayList();
+
+ requestBody.add((int)1);
+ requestBody.add(new Work(THRIFT_TEST_NUM1, 0, Operation.DIVIDE));
+
+ try {
+ template.requestBody("direct:thrift-secured-calculate", requestBody);
+ fail("Expect the exception here");
+ } catch (Exception ex) {
+ assertTrue("Expect CamelExecutionException", ex instanceof CamelExecutionException);
+ assertTrue("Get an InvalidOperation exception", ex.getCause() instanceof InvalidOperation);
+ }
+ }
+
+ @Test
+ public void testVoidMethodInvocation() throws Exception {
+ LOG.info("Thrift method with empty parameters and void output sync test start");
+
+ Object requestBody = null;
+ Object responseBody = template.requestBody("direct:thrift-secured-ping", requestBody);
+ assertNull(responseBody);
+ }
+
+ @Test
+ public void testOneWayMethodInvocation() throws Exception {
+ LOG.info("Thrift one-way method sync test start");
+
+ Object requestBody = null;
+ Object responseBody = template.requestBody("direct:thrift-secured-zip", requestBody);
+ assertNull(responseBody);
+ }
+
+ @Test
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void testAllTypesMethodInvocation() throws Exception {
+ LOG.info("Thrift method with all possile types sync test start");
+
+ List requestBody = new ArrayList();
+
+ requestBody.add((boolean)true);
+ requestBody.add((byte)THRIFT_TEST_NUM1);
+ requestBody.add((short)THRIFT_TEST_NUM1);
+ requestBody.add((int)THRIFT_TEST_NUM1);
+ requestBody.add((long)THRIFT_TEST_NUM1);
+ requestBody.add((double)THRIFT_TEST_NUM1);
+ requestBody.add("empty");
+ requestBody.add(ByteBuffer.allocate(10));
+ requestBody.add(new Work(THRIFT_TEST_NUM1, THRIFT_TEST_NUM2, Operation.MULTIPLY));
+ requestBody.add(new ArrayList<Integer>());
+ requestBody.add(new HashSet<String>());
+ requestBody.add(new HashMap<String, Long>());
+
+ Object responseBody = template.requestBody("direct:thrift-secured-alltypes", requestBody);
+
+ assertNotNull(responseBody);
+ assertTrue(responseBody instanceof Integer);
+ assertEquals(1, responseBody);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:thrift-secured-calculate")
+ .to("thrift://localhost:" + THRIFT_TEST_PORT + "/org.apache.camel.component.thrift.generated.Calculator?"
+ + "method=calculate&negotiationType=SSL&sslConfiguration=#sslConfig&synchronous=true");
+ from("direct:thrift-secured-add")
+ .to("thrift://localhost:" + THRIFT_TEST_PORT + "/org.apache.camel.component.thrift.generated.Calculator?"
+ + "method=add&negotiationType=SSL&sslConfiguration=#sslConfig&synchronous=true");
+ from("direct:thrift-secured-ping")
+ .to("thrift://localhost:" + THRIFT_TEST_PORT + "/org.apache.camel.component.thrift.generated.Calculator?"
+ + "method=ping&negotiationType=SSL&sslConfiguration=#sslConfig&synchronous=true");
+ from("direct:thrift-secured-zip")
+ .to("thrift://localhost:" + THRIFT_TEST_PORT + "/org.apache.camel.component.thrift.generated.Calculator?"
+ + "method=zip&negotiationType=SSL&sslConfiguration=#sslConfig&synchronous=true");
+ from("direct:thrift-secured-alltypes")
+ .to("thrift://localhost:" + THRIFT_TEST_PORT + "/org.apache.camel.component.thrift.generated.Calculator?"
+ + "method=alltypes&negotiationType=SSL&sslConfiguration=#sslConfig&synchronous=true");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/5a501706/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerZlibCompressionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerZlibCompressionTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerZlibCompressionTest.java
new file mode 100644
index 0000000..e2405b7
--- /dev/null
+++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerZlibCompressionTest.java
@@ -0,0 +1,126 @@
+/**
+ * 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.thrift;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.thrift.generated.Calculator;
+import org.apache.camel.component.thrift.generated.Operation;
+import org.apache.camel.component.thrift.generated.Work;
+import org.apache.camel.component.thrift.impl.CalculatorSyncServerImpl;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.thrift.TProcessor;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.server.TServer;
+import org.apache.thrift.server.TThreadPoolServer;
+import org.apache.thrift.transport.TServerSocket;
+import org.apache.thrift.transport.TTransportFactory;
+import org.apache.thrift.transport.TZlibTransport;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ThriftProducerZlibCompressionTest extends CamelTestSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(ThriftProducerZlibCompressionTest.class);
+
+ private static TServerSocket serverTransport;
+ private static TServer server;
+ @SuppressWarnings({"rawtypes"})
+ private static Calculator.Processor processor;
+
+ private static final int THRIFT_TEST_PORT = AvailablePortFinder.getNextAvailable();
+ private static final int THRIFT_TEST_NUM1 = 12;
+ private static final int THRIFT_TEST_NUM2 = 13;
+ private static final int THRIFT_CLIENT_TIMEOUT = 2000;
+
+ @BeforeClass
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public static void startThriftServer() throws Exception {
+ processor = new Calculator.Processor(new CalculatorSyncServerImpl());
+
+ serverTransport = new TServerSocket(new InetSocketAddress(InetAddress.getByName("localhost"), THRIFT_TEST_PORT), THRIFT_CLIENT_TIMEOUT);
+ TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport);
+ args.processor((TProcessor)processor);
+ args.protocolFactory(new TBinaryProtocol.Factory());
+ args.transportFactory((TTransportFactory)new TZlibTransport.Factory());
+ server = new TThreadPoolServer(args);
+
+ Runnable simple = new Runnable() {
+ public void run() {
+ LOG.info("Thrift server with zlib compression started on port: {}", THRIFT_TEST_PORT);
+ server.serve();
+ }
+ };
+ new Thread(simple).start();
+ }
+
+ @AfterClass
+ public static void stopThriftServer() throws IOException {
+ if (server != null) {
+ server.stop();
+ serverTransport.close();
+ LOG.info("Thrift server with zlib compression stoped");
+ }
+ }
+
+ @Test
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void testCalculateMethodInvocation() throws Exception {
+ LOG.info("Thrift calculate method sync test start");
+
+ List requestBody = new ArrayList();
+
+ requestBody.add((int)1);
+ requestBody.add(new Work(THRIFT_TEST_NUM1, THRIFT_TEST_NUM2, Operation.MULTIPLY));
+
+ Object responseBody = template.requestBody("direct:thrift-zlib-calculate", requestBody);
+
+ assertNotNull(responseBody);
+ assertTrue(responseBody instanceof Integer);
+ assertEquals(THRIFT_TEST_NUM1 * THRIFT_TEST_NUM2, responseBody);
+ }
+
+ @Test
+ public void testVoidMethodInvocation() throws Exception {
+ LOG.info("Thrift method with empty parameters and void output sync test start");
+
+ Object requestBody = null;
+ Object responseBody = template.requestBody("direct:thrift-zlib-ping", requestBody);
+ assertNull(responseBody);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:thrift-zlib-calculate")
+ .to("thrift://localhost:" + THRIFT_TEST_PORT + "/org.apache.camel.component.thrift.generated.Calculator?method=calculate&compressionType=ZLIB&synchronous=true");
+ from("direct:thrift-zlib-ping")
+ .to("thrift://localhost:" + THRIFT_TEST_PORT + "/org.apache.camel.component.thrift.generated.Calculator?method=ping&compressionType=ZLIB&synchronous=true");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/5a501706/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorAsyncServerImpl.java
----------------------------------------------------------------------
diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorAsyncServerImpl.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorAsyncServerImpl.java
new file mode 100644
index 0000000..dc7ba44
--- /dev/null
+++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorAsyncServerImpl.java
@@ -0,0 +1,94 @@
+/**
+ * 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.thrift.impl;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.component.thrift.generated.Calculator;
+import org.apache.camel.component.thrift.generated.InvalidOperation;
+import org.apache.camel.component.thrift.generated.Work;
+import org.apache.thrift.TException;
+import org.apache.thrift.async.AsyncMethodCallback;
+
+/**
+ * Test Thrift Calculator nonblocking server implementation
+ */
+public class CalculatorAsyncServerImpl implements Calculator.AsyncIface {
+
+ @Override
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void ping(AsyncMethodCallback resultHandler) throws TException {
+ resultHandler.onComplete(new Object());
+ }
+
+ @Override
+ public void add(int num1, int num2, AsyncMethodCallback<Integer> resultHandler) throws TException {
+ resultHandler.onComplete(new Integer(num1 + num2));
+ }
+
+ @Override
+ public void calculate(int logid, Work work, AsyncMethodCallback<Integer> resultHandler) throws TException {
+ int val = 0;
+ switch (work.op) {
+ case ADD:
+ val = work.num1 + work.num2;
+ break;
+ case SUBTRACT:
+ val = work.num1 - work.num2;
+ break;
+ case MULTIPLY:
+ val = work.num1 * work.num2;
+ break;
+ case DIVIDE:
+ if (work.num2 == 0) {
+ InvalidOperation io = new InvalidOperation();
+ io.whatOp = work.op.getValue();
+ io.why = "Cannot divide by 0";
+ resultHandler.onError(io);
+ }
+ val = work.num1 / work.num2;
+ break;
+ default:
+ InvalidOperation io = new InvalidOperation();
+ io.whatOp = work.op.getValue();
+ io.why = "Unknown operation";
+ resultHandler.onError(io);
+ }
+ resultHandler.onComplete(val);
+ }
+
+ @Override
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public void zip(AsyncMethodCallback resultHandler) throws TException {
+ resultHandler.onComplete(new Object());
+ }
+
+ @Override
+ public void echo(Work w, AsyncMethodCallback<Work> resultHandler) throws TException {
+ resultHandler.onComplete(w.deepCopy());
+ }
+
+ @Override
+ public void alltypes(boolean v1, byte v2, short v3, int v4, long v5, double v6, String v7, ByteBuffer v8, Work v9, List<Integer> v10, Set<String> v11, Map<String, Long> v12,
+ AsyncMethodCallback<Integer> resultHandler)
+ throws TException {
+ resultHandler.onComplete(new Integer(1));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/5a501706/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorSyncServerImpl.java
----------------------------------------------------------------------
diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorSyncServerImpl.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorSyncServerImpl.java
new file mode 100644
index 0000000..f2d5e19
--- /dev/null
+++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/impl/CalculatorSyncServerImpl.java
@@ -0,0 +1,89 @@
+/**
+ * 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.thrift.impl;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.component.thrift.generated.Calculator;
+import org.apache.camel.component.thrift.generated.InvalidOperation;
+import org.apache.camel.component.thrift.generated.Work;
+import org.apache.thrift.TException;
+
+/**
+ * Test Thrift Calculator blocking server implementation
+ */
+public class CalculatorSyncServerImpl implements Calculator.Iface {
+
+ @Override
+ public void ping() throws TException {
+ }
+
+ @Override
+ public int add(int num1, int num2) throws TException {
+ return num1 + num2;
+ }
+
+ @Override
+ public int calculate(int logId, Work work) throws InvalidOperation, TException {
+ int val = 0;
+ switch (work.op) {
+ case ADD:
+ val = work.num1 + work.num2;
+ break;
+ case SUBTRACT:
+ val = work.num1 - work.num2;
+ break;
+ case MULTIPLY:
+ val = work.num1 * work.num2;
+ break;
+ case DIVIDE:
+ if (work.num2 == 0) {
+ InvalidOperation io = new InvalidOperation();
+ io.whatOp = work.op.getValue();
+ io.why = "Cannot divide by 0";
+ throw io;
+ }
+ val = work.num1 / work.num2;
+ break;
+ default:
+ InvalidOperation io = new InvalidOperation();
+ io.whatOp = work.op.getValue();
+ io.why = "Unknown operation";
+ throw io;
+ }
+
+ return val;
+ }
+
+ @Override
+ public void zip() throws TException {
+ }
+
+ @Override
+ public Work echo(Work w) throws TException {
+ return w.deepCopy();
+ }
+
+ @Override
+ public int alltypes(boolean v1, byte v2, short v3, int v4, long v5, double v6, String v7, ByteBuffer v8, Work v9, List<Integer> v10, Set<String> v11, Map<String, Long> v12)
+ throws TException {
+ return 1;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/5a501706/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/local/ThriftThreadPoolServerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/local/ThriftThreadPoolServerTest.java b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/local/ThriftThreadPoolServerTest.java
new file mode 100644
index 0000000..297729e
--- /dev/null
+++ b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/local/ThriftThreadPoolServerTest.java
@@ -0,0 +1,106 @@
+/**
+ * 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.thrift.local;
+
+import java.io.IOException;
+import java.net.InetAddress;
+
+import org.apache.camel.component.thrift.ThriftProducerSecurityTest;
+import org.apache.camel.component.thrift.generated.Calculator;
+import org.apache.camel.component.thrift.impl.CalculatorSyncServerImpl;
+import org.apache.camel.component.thrift.server.ThriftThreadPoolServer;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.thrift.TException;
+import org.apache.thrift.TProcessor;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.server.TServer;
+import org.apache.thrift.transport.TSSLTransportFactory;
+import org.apache.thrift.transport.TServerSocket;
+import org.apache.thrift.transport.TTransport;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TBD
+ */
+public class ThriftThreadPoolServerTest extends CamelTestSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(ThriftProducerSecurityTest.class);
+
+ private static final int THRIFT_TEST_PORT = AvailablePortFinder.getNextAvailable();
+ private static final int THRIFT_TEST_NUM1 = 12;
+ private static final int THRIFT_TEST_NUM2 = 13;
+
+ private static final String TRUST_STORE_PATH = "src/test/resources/certs/truststore.jks";
+ private static final String KEY_STORE_PATH = "src/test/resources/certs/keystore.jks";
+ private static final String SECURITY_STORE_PASSWORD = "camelinaction";
+ private static final int THRIFT_CLIENT_TIMEOUT = 2000;
+
+ private static TServerSocket serverTransport;
+ private static TTransport clientTransport;
+ private static TServer server;
+ private static TProtocol protocol;
+ @SuppressWarnings({"rawtypes"})
+ private static Calculator.Processor processor;
+
+ @Before
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public void startThriftServer() throws Exception {
+ processor = new Calculator.Processor(new CalculatorSyncServerImpl());
+
+ TSSLTransportFactory.TSSLTransportParameters sslParams = new TSSLTransportFactory.TSSLTransportParameters();
+
+ sslParams.setKeyStore(KEY_STORE_PATH, SECURITY_STORE_PASSWORD);
+ serverTransport = TSSLTransportFactory.getServerSocket(THRIFT_TEST_PORT, THRIFT_CLIENT_TIMEOUT, InetAddress.getByName("localhost"), sslParams);
+ ThriftThreadPoolServer.Args args = new ThriftThreadPoolServer.Args(serverTransport);
+
+ args.processor((TProcessor)processor);
+ args.executorService(this.context().getExecutorServiceManager().newThreadPool(this, "test-server-invoker", 1, 10));
+ args.startThreadPool(this.context().getExecutorServiceManager().newSingleThreadExecutor(this, "test-start-thread"));
+ args.context(this.context());
+
+ server = new ThriftThreadPoolServer(args);
+ server.serve();
+ LOG.info("Thrift secured server started on port: {}", THRIFT_TEST_PORT);
+ }
+
+ @After
+ public void stopThriftServer() throws IOException {
+ if (server != null) {
+ server.stop();
+ serverTransport.close();
+ LOG.info("Thrift secured server stoped");
+ }
+ }
+
+ @Test
+ public void clientConnectionTest() throws TException {
+ TSSLTransportFactory.TSSLTransportParameters sslParams = new TSSLTransportFactory.TSSLTransportParameters();
+ sslParams.setTrustStore(TRUST_STORE_PATH, SECURITY_STORE_PASSWORD);
+ clientTransport = TSSLTransportFactory.getClientSocket("localhost", THRIFT_TEST_PORT, 1000, sslParams);
+
+ protocol = new TBinaryProtocol(clientTransport);
+ Calculator.Client client = new Calculator.Client(protocol);
+ int addResult = client.add(THRIFT_TEST_NUM1, THRIFT_TEST_NUM2);
+
+ assertEquals(addResult, THRIFT_TEST_NUM1 + THRIFT_TEST_NUM2);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/5a501706/components/camel-thrift/src/test/resources/certs/README.md
----------------------------------------------------------------------
diff --git a/components/camel-thrift/src/test/resources/certs/README.md b/components/camel-thrift/src/test/resources/certs/README.md
new file mode 100644
index 0000000..acbd67b
--- /dev/null
+++ b/components/camel-thrift/src/test/resources/certs/README.md
@@ -0,0 +1,13 @@
+The test certificates have been generated with the following commands:
+
+Creating Key Store:
+-----------------------
+
+$ keytool -genkeypair -alias certificatekey -keyalg RSA -validity 3650 -keystore keystore.jks
+
+$ keytool -export -alias certificatekey -keystore keystore.jks -rfc -file cert.cer
+
+Creating Trust Store:
+------------------------
+
+$ keytool -import -alias certificatekey -file cert.cer -keystore truststore.jks
http://git-wip-us.apache.org/repos/asf/camel/blob/5a501706/components/camel-thrift/src/test/resources/certs/keystore.jks
----------------------------------------------------------------------
diff --git a/components/camel-thrift/src/test/resources/certs/keystore.jks b/components/camel-thrift/src/test/resources/certs/keystore.jks
new file mode 100644
index 0000000..057d848
Binary files /dev/null and b/components/camel-thrift/src/test/resources/certs/keystore.jks differ
http://git-wip-us.apache.org/repos/asf/camel/blob/5a501706/components/camel-thrift/src/test/resources/certs/truststore.jks
----------------------------------------------------------------------
diff --git a/components/camel-thrift/src/test/resources/certs/truststore.jks b/components/camel-thrift/src/test/resources/certs/truststore.jks
new file mode 100644
index 0000000..b1b02c8
Binary files /dev/null and b/components/camel-thrift/src/test/resources/certs/truststore.jks differ
http://git-wip-us.apache.org/repos/asf/camel/blob/5a501706/components/camel-thrift/src/test/thrift/README.md
----------------------------------------------------------------------
diff --git a/components/camel-thrift/src/test/thrift/README.md b/components/camel-thrift/src/test/thrift/README.md
new file mode 100644
index 0000000..5fe3aaf
--- /dev/null
+++ b/components/camel-thrift/src/test/thrift/README.md
@@ -0,0 +1,9 @@
+Thrift tutorial java files generation
+-----------------------
+$ cd src/test/thrift
+
+$ thrift -r --gen java -out ../java/ ./tutorial-dataformat.thrift
+
+$ thrift -r --gen java -out ../java/ ./tutorial-component.thrift
+
+*Examples taken from the Apache Thrift java tutorial https://thrift.apache.org/tutorial/java*
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/5a501706/components/camel-thrift/src/test/thrift/readme.txt
----------------------------------------------------------------------
diff --git a/components/camel-thrift/src/test/thrift/readme.txt b/components/camel-thrift/src/test/thrift/readme.txt
deleted file mode 100644
index 13e69ce..0000000
--- a/components/camel-thrift/src/test/thrift/readme.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-Examples taken from the Apache Thrift java tutorial https://thrift.apache.org/tutorial/java
-
-Thrift tutorial java files generation
- cd src/test/thrift
- thrift -r --gen java -out ../java/ ./tutorial-dataformat.thrift
- thrift -r --gen java -out ../java/ ./tutorial-component.thrift
\ No newline at end of file