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; |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 32 | var ThriftTestHandlerPromise = require('./test_handler_promise').ThriftTestHandler; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 33 | |
| 34 | |
| 35 | var program = require('commander'); |
| 36 | |
| 37 | program |
| 38 | .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]') |
| 39 | .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]') |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 40 | .option('--ssl', 'use ssl transport') |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 41 | .option('--promise', 'test with promise style functions') |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 42 | .parse(process.argv); |
| 43 | |
| 44 | var protocol = undefined; |
| 45 | var transport = undefined; |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 46 | var handler = undefined; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 47 | |
| 48 | if (program.protocol === "binary") { |
| 49 | protocol = ThriftProtocols.TBinaryProtocol; |
| 50 | } else if (program.protocol === "json") { |
| 51 | protocol = ThriftProtocols.TJSONProtocol; |
| 52 | } else { |
| 53 | //default |
| 54 | protocol = ThriftProtocols.TBinaryProtocol; |
| 55 | } |
| 56 | |
| 57 | if (program.transport === "framed") { |
| 58 | transport = ThriftTransports.TFramedTransport; |
| 59 | } else if (program.transport === "buffered") { |
| 60 | transport = ThriftTransports.TBufferedTransport; |
| 61 | } else { |
| 62 | //default |
| 63 | transport = ThriftTransports.TBufferedTransport; |
| 64 | } |
| 65 | |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 66 | if (program.promise) { |
| 67 | handler = ThriftTestHandlerPromise; |
| 68 | } else { |
| 69 | handler = ThriftTestHandler; |
| 70 | } |
| 71 | |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 72 | var options = { |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 73 | protocol: protocol, |
| 74 | transport: transport |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | if (program.ssl) { |
| 78 | //ssl options |
| 79 | options.key = fs.readFileSync(path.resolve(__dirname, 'server.key')); |
| 80 | options.cert = fs.readFileSync(path.resolve(__dirname, 'server.crt')); |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 81 | thrift.createSSLServer(ThriftTest, handler, options).listen(9090); |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 82 | |
| 83 | } else { |
| 84 | //default |
henrique | 3123623 | 2014-02-23 20:16:44 +0100 | [diff] [blame] | 85 | thrift.createServer(ThriftTest, handler, options).listen(9090); |
Roger Meier | 57b354b | 2014-02-22 01:01:58 +0100 | [diff] [blame] | 86 | } |