blob: 18f9b0d7226a1da27623910535c5a9469d6922a1 [file] [log] [blame]
Roger Meier8909cbd2014-01-26 11:44:27 +01001/*
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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
17 * under the License.
18 */
19var thrift = require('thrift');
Roger Meier8909cbd2014-01-26 11:44:27 +010020
21var ThriftTest = require('./gen-nodejs/ThriftTest'),
22 SecondService = require('./gen-nodejs/SecondService'),
23 ttypes = require('./gen-nodejs/ThriftTest_types');
24
Roger Meier57b354b2014-02-22 01:01:58 +010025var fs = require("fs");
26var path = require("path");
27
Roger Meier8909cbd2014-01-26 11:44:27 +010028var program = require('commander');
29
30program
31 .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
32 .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
Roger Meier57b354b2014-02-22 01:01:58 +010033 .option('--ssl', 'use ssl transport')
Roger Meier8909cbd2014-01-26 11:44:27 +010034 .parse(process.argv);
35
Randy Abernethyd60f9782014-03-28 10:36:38 -070036var protocol = thrift.TBinaryProtocol;
37if (program.protocol === "json") {
38 protocol = thrift.TJSONProtocol;
Roger Meier8909cbd2014-01-26 11:44:27 +010039}
40
Randy Abernethyd60f9782014-03-28 10:36:38 -070041var transport = thrift.TBufferedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010042if (program.transport === "framed") {
Randy Abernethyd60f9782014-03-28 10:36:38 -070043 transport = thrift.TFramedTransport;
Roger Meier8909cbd2014-01-26 11:44:27 +010044}
45
46var ThriftTestHandler = require("./test_handler").ThriftTestHandler;
47
48var SecondServiceHandler = {
49 secondtestString: function(thing, result) {
50 console.log('testString(\'' + thing + '\')');
51 result(null, thing);
52 }
53};
54
55var processor = new thrift.MultiplexedProcessor();
56
57processor.registerProcessor(
58 "ThriftTest",
59 new ThriftTest.Processor(ThriftTestHandler));
60
61processor.registerProcessor(
62 "SecondService",
63 new SecondService.Processor(SecondServiceHandler));
64
Roger Meier57b354b2014-02-22 01:01:58 +010065var options = {
66 transport: transport,
67 protocol: protocol
68};
69
Roger Meier57b354b2014-02-22 01:01:58 +010070if (program.ssl) {
71 //ssl options
Randy Abernethyd60f9782014-03-28 10:36:38 -070072 options.tls = {
73 key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
74 cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
ra779b9ac2014-04-23 20:04:23 -070075 };
Roger Meier57b354b2014-02-22 01:01:58 +010076}
Roger Meier8909cbd2014-01-26 11:44:27 +010077
Randy Abernethyd60f9782014-03-28 10:36:38 -070078thrift.createMultiplexServer(processor, options).listen(9090);