blob: 450c8f28c264d8d4a4c30b95fcff10ef262e998e [file] [log] [blame]
Jens Geyerbd52f1a2014-07-28 01:25:30 +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;
21
22import org.apache.thrift.*;
23import org.apache.thrift.protocol.*;
24import org.apache.thrift.transport.*;
25import org.apache.thrift.server.*;
26import org.apache.thrift.meta_data.*;
27
28import thrift.test.*; // generated code
29
30
31class TestServer
32{
Jens Geyerb5028322014-11-09 02:38:11 +010033 public static function Execute(args : Arguments) : Void
34 {
35 try
36 {
37 // Transport
38 var transport : TServerTransport = null;
39 switch( args.transport) {
40 case socket:
41 trace("- socket port "+args.port);
42 transport = new TServerSocket( args.port);
43 case http:
44 trace("- http");
Oleksii Prudkyi39a09ac2016-05-19 16:55:11 +030045 #if !phpwebserver
46 throw "HTTP server not implemented yet";
Jens Geyerb5028322014-11-09 02:38:11 +010047 //transport = new THttpServer( targetHost);
Oleksii Prudkyi39a09ac2016-05-19 16:55:11 +030048 #else
49 transport = new TWrappingServerTransport(
50 new TStreamTransport(
51 new TFileStream("php://input", Read),
52 new TFileStream("php://output", Append)
53 )
54 );
55
56 #end
Jens Geyerb5028322014-11-09 02:38:11 +010057 default:
58 throw "Unhandled transport";
59 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020060
Jens Geyerb5028322014-11-09 02:38:11 +010061 // optional: layered transport
62 var transfactory : TTransportFactory = null;
63 if ( args.framed) {
64 trace("- framed transport");
65 transfactory = new TFramedTransportFactory();
66 }
67 if ( args.buffered) {
68 trace("- buffered transport");
Jens Geyerd35f6162014-11-29 19:23:03 +010069 transfactory = new TBufferedTransportFactory();
Jens Geyerb5028322014-11-09 02:38:11 +010070 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020071
Jens Geyerb5028322014-11-09 02:38:11 +010072 // protocol
73 var protfactory : TProtocolFactory = null;
74 switch( args.protocol)
75 {
76 case binary:
77 trace("- binary protocol");
78 protfactory = new TBinaryProtocolFactory();
79 case json:
80 trace("- json protocol");
81 protfactory = new TJSONProtocolFactory();
Jens Geyer426ab862015-03-02 23:37:15 +010082 case compact:
83 trace("- compact protocol");
84 protfactory = new TCompactProtocolFactory();
Jens Geyerb5028322014-11-09 02:38:11 +010085 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020086
Jens Geyerbd52f1a2014-07-28 01:25:30 +020087
Jens Geyerb5028322014-11-09 02:38:11 +010088 // Processor
89 var handler = new TestServerHandler();
90 var processor = new ThriftTestProcessor(handler);
Jens Geyerbd52f1a2014-07-28 01:25:30 +020091
Jens Geyerb5028322014-11-09 02:38:11 +010092 // Simple Server
93 var server : TServer = null;
94 switch( args.servertype)
95 {
96 case simple:
Oleksii Prudkyi39a09ac2016-05-19 16:55:11 +030097 var simpleServer = new TSimpleServer( processor, transport, transfactory, protfactory);
98 #if phpwebserver
99 simpleServer.runOnce = true;
100 #end
101 server = simpleServer;
102
Jens Geyerb5028322014-11-09 02:38:11 +0100103 default:
104 throw "Unhandled server type";
105 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200106
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200107
Jens Geyerb5028322014-11-09 02:38:11 +0100108 /*
109 // Server event handler
110 if( args.serverEvents) {
111 var events = new TestServerEventHandler();
112 server.setEventHandler(serverEvents);
113 handler.server = serverEngine;
114 }
115 */
116
117 // Run it
118 server.Serve();
119 trace("done.");
120
121 }
122 catch (x : TException)
123 {
Jens Geyer1d20a372016-03-15 23:04:27 +0200124 trace('$x ${x.errorID} ${x.errorMsg}');
Jens Geyerb5028322014-11-09 02:38:11 +0100125 }
126 catch (x : Dynamic)
127 {
128 trace('$x');
129 }
130 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200131}