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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
32 debugServerProtocol bool
37 flag.BoolVar(&debugServerProtocol, "debug_server_protocol", false, "turn server protocol trace on")
48 handler thrifttest.ThriftTest) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, error) {
51 hostPort := fmt.Sprintf("%s:%d", host, port)
53 var protocolFactory thrift.TProtocolFactory
56 protocolFactory = thrift.NewTCompactProtocolFactory()
58 protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
60 protocolFactory = thrift.NewTJSONProtocolFactory()
62 protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
64 protocolFactory = thrift.NewTHeaderProtocolFactory()
66 return nil, nil, nil, nil, fmt.Errorf("Invalid protocol specified %s", protocol)
68 if debugServerProtocol {
69 protocolFactory = thrift.NewTDebugProtocolFactory(protocolFactory, "server:")
72 var serverTransport thrift.TServerTransport
74 cfg := new(tls.Config)
75 if cert, err := tls.LoadX509KeyPair(certPath+"/server.crt", certPath+"/server.key"); err != nil {
76 return nil, nil, nil, nil, err
78 cfg.Certificates = append(cfg.Certificates, cert)
80 serverTransport, err = thrift.NewTSSLServerSocket(hostPort, cfg)
82 if domain_socket != "" {
83 serverTransport, err = thrift.NewTServerSocket(domain_socket)
85 serverTransport, err = thrift.NewTServerSocket(hostPort)
89 return nil, nil, nil, nil, err
92 var transportFactory thrift.TTransportFactory
96 // there is no such factory, and we don't need any
97 transportFactory = nil
99 transportFactory = thrift.NewTTransportFactory()
100 transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
102 transportFactory = thrift.NewTBufferedTransportFactory(8192)
104 transportFactory = thrift.NewTZlibTransportFactory(zlib.BestCompression)
106 transportFactory = thrift.NewTTransportFactory()
108 return nil, nil, nil, nil, fmt.Errorf("Invalid transport specified %s", transport)
110 processor := thrifttest.NewThriftTestProcessor(handler)
112 return processor, serverTransport, transportFactory, protocolFactory, nil