blob: ca2d967b62355765b49d1eb23d40245ad7f161e6 [file] [log] [blame]
Jens Geyerf4598682014-05-08 23:18:44 +02001/*
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
20package main
21
22import (
23 "common"
24 "flag"
claudemirof8ca0552016-01-10 23:31:30 -020025 "fmt"
Jens Geyerf4598682014-05-08 23:18:44 +020026 "log"
claudemirof8ca0552016-01-10 23:31:30 -020027 "net/http"
28 "thrift"
Jens Geyerf4598682014-05-08 23:18:44 +020029)
30
31var host = flag.String("host", "localhost", "Host to connect")
32var port = flag.Int64("port", 9090, "Port number to connect")
33var domain_socket = flag.String("domain-socket", "", "Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port")
Jens Geyerc6b991f2015-08-07 23:41:09 +020034var transport = flag.String("transport", "buffered", "Transport: buffered, framed, http, zlib")
Jens Geyerf4598682014-05-08 23:18:44 +020035var protocol = flag.String("protocol", "binary", "Protocol: binary, compact, json")
36var ssl = flag.Bool("ssl", false, "Encrypted Transport using SSL")
James E. King IIIb2b767e2018-09-15 20:32:04 +000037var zlib = flag.Bool("zlib", false, "Wrapped Transport using Zlib")
Roger Meier41ad4342015-03-24 22:30:40 +010038var certPath = flag.String("certPath", "keys", "Directory that contains SSL certificates")
Jens Geyerf4598682014-05-08 23:18:44 +020039
40func main() {
41 flag.Parse()
claudemirof8ca0552016-01-10 23:31:30 -020042
43 processor, serverTransport, transportFactory, protocolFactory, err := common.GetServerParams(*host, *port, *domain_socket, *transport, *protocol, *ssl, *certPath, common.PrintingHandler)
44
Jens Geyerf4598682014-05-08 23:18:44 +020045 if err != nil {
claudemirof8ca0552016-01-10 23:31:30 -020046 log.Fatalf("Unable to process server params: ", err)
Jens Geyerf4598682014-05-08 23:18:44 +020047 }
claudemirof8ca0552016-01-10 23:31:30 -020048
49 if *transport == "http" {
50 http.HandleFunc("/", thrift.NewThriftHandlerFunc(processor, protocolFactory, protocolFactory))
51
52 if *ssl {
53 err := http.ListenAndServeTLS(fmt.Sprintf(":%d", *port),
54 *certPath+"/server.pem", *certPath+"/server.key", nil)
55
56 if err != nil {
57 fmt.Println(err)
58 return
59 }
60 } else {
61 http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)
62 }
63 } else {
64 server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
65 if err = server.Listen(); err != nil {
66 return
67 }
68 go server.AcceptLoop()
69 server.Serve()
70 }
Jens Geyerf4598682014-05-08 23:18:44 +020071}