From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/jaegertracing/thrift/lib/nodejs/test/server.js | 137 +++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 src/jaegertracing/thrift/lib/nodejs/test/server.js (limited to 'src/jaegertracing/thrift/lib/nodejs/test/server.js') diff --git a/src/jaegertracing/thrift/lib/nodejs/test/server.js b/src/jaegertracing/thrift/lib/nodejs/test/server.js new file mode 100644 index 000000000..7402094bc --- /dev/null +++ b/src/jaegertracing/thrift/lib/nodejs/test/server.js @@ -0,0 +1,137 @@ +#!/usr/bin/env node + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * 'License'); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +const fs = require("fs"); +const path = require("path"); +const thrift = require("../lib/thrift"); +const program = require("commander"); +const helpers = require("./helpers"); + +program + .option( + "-p, --protocol ", + "Set thrift protocol (binary|compact|json)", + "binary" + ) + .option( + "-t, --transport ", + "Set thrift transport (buffered|framed|http)", + "buffered" + ) + .option("--ssl", "use ssl transport") + .option("--port ", "Set thrift server port", 9090) + .option("--domain-socket ", "Set thift server unix domain socket") + .option( + "-t, --type ", + "Select server type (http|multiplex|tcp|websocket)", + "tcp" + ) + .option("--callback", "test with callback style functions") + .option("--es6", "Use es6 code") + .option("--es5", "Use es5 code") + .parse(process.argv); + +const ThriftTest = require(`./${helpers.genPath}/ThriftTest`); +const SecondService = require(`./${helpers.genPath}/SecondService`); +const { ThriftTestHandler } = require("./test_handler"); + +const port = program.port; +const domainSocket = program.domainSocket; +const ssl = program.ssl; + +let type = program.type; +if (program.transport === "http") { + program.transport = "buffered"; + type = "http"; +} + +let options = { + transport: helpers.transports[program.transport], + protocol: helpers.protocols[program.protocol] +}; + +if (type === "http" || type === "websocket") { + options.handler = ThriftTestHandler; + options.processor = ThriftTest; + + options = { + services: { "/test": options }, + cors: { + "*": true + } + }; +} + +let processor; +if (type === "multiplex") { + const SecondServiceHandler = { + secondtestString: function(thing, result) { + console.log('testString("' + thing + '")'); + result(null, 'testString("' + thing + '")'); + } + }; + + processor = new thrift.MultiplexedProcessor(); + + processor.registerProcessor( + "ThriftTest", + new ThriftTest.Processor(ThriftTestHandler) + ); + + processor.registerProcessor( + "SecondService", + new SecondService.Processor(SecondServiceHandler) + ); +} + +if (ssl) { + if ( + type === "tcp" || + type === "multiplex" || + type === "http" || + type === "websocket" + ) { + options.tls = { + key: fs.readFileSync(path.resolve(__dirname, "server.key")), + cert: fs.readFileSync(path.resolve(__dirname, "server.crt")) + }; + } +} + +let server; +if (type === "tcp") { + server = thrift.createServer(ThriftTest, ThriftTestHandler, options); +} else if (type === "multiplex") { + server = thrift.createMultiplexServer(processor, options); +} else if (type === "http" || type === "websocket") { + server = thrift.createWebServer(options); +} + +if (domainSocket) { + server.listen(domainSocket); +} else if ( + type === "tcp" || + type === "multiplex" || + type === "http" || + type === "websocket" +) { + server.listen(port); +} -- cgit v1.2.3