Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 1 | /* |
| 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 Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame^] | 25 | var fs = require('fs'); |
| 26 | var path = require('path'); |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 27 | var thrift = require('thrift'); |
| 28 | var ThriftTransports = require('thrift/transport'); |
| 29 | var ThriftProtocols = require('thrift/protocol'); |
| 30 | var ThriftTest = require('./gen-nodejs/ThriftTest'); |
| 31 | var ThriftTestHandler = require('./test_handler').ThriftTestHandler; |
| 32 | |
| 33 | |
| 34 | var program = require('commander'); |
| 35 | |
| 36 | program |
| 37 | .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]') |
| 38 | .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]') |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame^] | 39 | .option('--ssl', 'use ssl transport') |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 40 | .parse(process.argv); |
| 41 | |
| 42 | var protocol = undefined; |
| 43 | var transport = undefined; |
| 44 | |
| 45 | if (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 | |
| 54 | if (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 Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame^] | 63 | var options = { |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 64 | protocol: protocol, |
| 65 | transport: transport |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame^] | 66 | }; |
| 67 | |
| 68 | if (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 | } |