2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 import org
.apache
.thrift
.server
.TServer
;
21 import org
.apache
.thrift
.server
.TServer
.Args
;
22 import org
.apache
.thrift
.server
.TSimpleServer
;
23 import org
.apache
.thrift
.server
.TThreadPoolServer
;
24 import org
.apache
.thrift
.transport
.TSSLTransportFactory
;
25 import org
.apache
.thrift
.transport
.TServerSocket
;
26 import org
.apache
.thrift
.transport
.TServerTransport
;
27 import org
.apache
.thrift
.transport
.TSSLTransportFactory
.TSSLTransportParameters
;
33 import java
.util
.HashMap
;
35 public class JavaServer
{
37 public static CalculatorHandler handler
;
39 public static Calculator
.Processor processor
;
41 public static void main(String
[] args
) {
43 handler
= new CalculatorHandler();
44 processor
= new Calculator
.Processor(handler
);
46 Runnable simple
= new Runnable() {
51 Runnable secure
= new Runnable() {
57 new Thread(simple
).start();
58 new Thread(secure
).start();
59 } catch (Exception x
) {
64 public static void simple(Calculator
.Processor processor
) {
66 TServerTransport serverTransport
= new TServerSocket(9090);
67 TServer server
= new TSimpleServer(new Args(serverTransport
).processor(processor
));
69 // Use this for a multithreaded server
70 // TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
72 System
.out
.println("Starting the simple server...");
74 } catch (Exception e
) {
79 public static void secure(Calculator
.Processor processor
) {
82 * Use TSSLTransportParameters to setup the required SSL parameters. In this example
83 * we are setting the keystore and the keystore password. Other things like algorithms,
84 * cipher suites, client auth etc can be set.
86 TSSLTransportParameters params
= new TSSLTransportParameters();
87 // The Keystore contains the private key
88 params
.setKeyStore("../../lib/java/test/.keystore", "thrift", null, null);
91 * Use any of the TSSLTransportFactory to get a server transport with the appropriate
92 * SSL configuration. You can use the default settings if properties are set in the command line.
93 * Ex: -Djavax.net.ssl.keyStore=.keystore and -Djavax.net.ssl.keyStorePassword=thrift
95 * Note: You need not explicitly call open(). The underlying server socket is bound on return
96 * from the factory class.
98 TServerTransport serverTransport
= TSSLTransportFactory
.getServerSocket(9091, 0, null, params
);
99 TServer server
= new TSimpleServer(new Args(serverTransport
).processor(processor
));
101 // Use this for a multi threaded server
102 // TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
104 System
.out
.println("Starting the secure server...");
106 } catch (Exception e
) {