blob: 69519ab1d9741e8e9e0d0de0f53cf74b8d4b2f08 [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 */
19
20//Server test for the following I/O stack:
21// TBinaryProtocol
22// TFramedTransport
23// TSocket
24
Roger Meier57b354b2014-02-22 01:01:58 +010025var fs = require('fs');
26var path = require('path');
Roger Meier8909cbd2014-01-26 11:44:27 +010027var thrift = require('thrift');
28var ThriftTransports = require('thrift/transport');
29var ThriftProtocols = require('thrift/protocol');
30var ThriftTest = require('./gen-nodejs/ThriftTest');
31var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
32
33
34var program = require('commander');
35
36program
37 .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
38 .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
Roger Meier57b354b2014-02-22 01:01:58 +010039 .option('--ssl', 'use ssl transport')
Roger Meier8909cbd2014-01-26 11:44:27 +010040 .parse(process.argv);
41
42var protocol = undefined;
43var transport = undefined;
44
45if (program.protocol === "binary") {
46 protocol = ThriftProtocols.TBinaryProtocol;
47} else if (program.protocol === "json") {
48 protocol = ThriftProtocols.TJSONProtocol;
49} else {
50 //default
51 protocol = ThriftProtocols.TBinaryProtocol;
52}
53
54if (program.transport === "framed") {
55 transport = ThriftTransports.TFramedTransport;
56} else if (program.transport === "buffered") {
57 transport = ThriftTransports.TBufferedTransport;
58} else {
59 //default
60 transport = ThriftTransports.TBufferedTransport;
61}
62
Roger Meier57b354b2014-02-22 01:01:58 +010063var options = {
Roger Meier8909cbd2014-01-26 11:44:27 +010064 protocol: protocol,
65 transport: transport
Roger Meier57b354b2014-02-22 01:01:58 +010066};
67
68if (program.ssl) {
69 //ssl options
70 options.key = fs.readFileSync(path.resolve(__dirname, 'server.key'));
71 options.cert = fs.readFileSync(path.resolve(__dirname, 'server.crt'));
72 thrift.createSSLServer(ThriftTest, ThriftTestHandler, options).listen(9090);
73
74} else {
75 //default
76 thrift.createServer(ThriftTest, ThriftTestHandler, options).listen(9090);
77}