blob: d44c68cfa2f62f5098291e4b17d10f08aab95cff [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);
Jens Geyer2dcefad2021-02-25 09:42:52 +010042 #if (flash || html5 || js)
43 throw "Transport not supported on this platform";
44 #else
Jens Geyerb5028322014-11-09 02:38:11 +010045 transport = new TServerSocket( args.port);
Jens Geyer2dcefad2021-02-25 09:42:52 +010046 #end
Jens Geyerb5028322014-11-09 02:38:11 +010047 case http:
48 trace("- http");
Jens Geyer2dcefad2021-02-25 09:42:52 +010049 #if phpwebserver
50 transport = new TWrappingServerTransport(
51 new TStreamTransport(
52 new TFileStream("php://input", Read),
53 new TFileStream("php://output", Append),
54 null
55 )
56 );
Oleksii Prudkyi39a09ac2016-05-19 16:55:11 +030057 #else
Jens Geyer2dcefad2021-02-25 09:42:52 +010058 throw "Transport not supported on this platform";
59 //transport = new THttpServer( targetHost);
Oleksii Prudkyi39a09ac2016-05-19 16:55:11 +030060 #end
Jens Geyerb5028322014-11-09 02:38:11 +010061 default:
62 throw "Unhandled transport";
63 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020064
Jens Geyerb5028322014-11-09 02:38:11 +010065 // optional: layered transport
66 var transfactory : TTransportFactory = null;
67 if ( args.framed) {
68 trace("- framed transport");
69 transfactory = new TFramedTransportFactory();
70 }
71 if ( args.buffered) {
72 trace("- buffered transport");
Jens Geyerd35f6162014-11-29 19:23:03 +010073 transfactory = new TBufferedTransportFactory();
Jens Geyerb5028322014-11-09 02:38:11 +010074 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020075
Jens Geyerb5028322014-11-09 02:38:11 +010076 // protocol
77 var protfactory : TProtocolFactory = null;
78 switch( args.protocol)
79 {
80 case binary:
81 trace("- binary protocol");
82 protfactory = new TBinaryProtocolFactory();
83 case json:
84 trace("- json protocol");
85 protfactory = new TJSONProtocolFactory();
Jens Geyer426ab862015-03-02 23:37:15 +010086 case compact:
87 trace("- compact protocol");
88 protfactory = new TCompactProtocolFactory();
Jens Geyerb5028322014-11-09 02:38:11 +010089 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020090
Jens Geyerbd52f1a2014-07-28 01:25:30 +020091
Jens Geyerb5028322014-11-09 02:38:11 +010092 // Processor
Jens Geyer2dcefad2021-02-25 09:42:52 +010093 var handler : ThriftTest_service = new TestServerHandler();
Jens Geyerb5028322014-11-09 02:38:11 +010094 var processor = new ThriftTestProcessor(handler);
Jens Geyerbd52f1a2014-07-28 01:25:30 +020095
Jens Geyerb5028322014-11-09 02:38:11 +010096 // Simple Server
97 var server : TServer = null;
98 switch( args.servertype)
99 {
100 case simple:
Oleksii Prudkyi39a09ac2016-05-19 16:55:11 +0300101 var simpleServer = new TSimpleServer( processor, transport, transfactory, protfactory);
102 #if phpwebserver
103 simpleServer.runOnce = true;
104 #end
105 server = simpleServer;
106
Jens Geyerb5028322014-11-09 02:38:11 +0100107 default:
108 throw "Unhandled server type";
109 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200110
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200111
Jens Geyerb5028322014-11-09 02:38:11 +0100112 /*
113 // Server event handler
114 if( args.serverEvents) {
115 var events = new TestServerEventHandler();
116 server.setEventHandler(serverEvents);
117 handler.server = serverEngine;
118 }
119 */
120
121 // Run it
122 server.Serve();
123 trace("done.");
124
125 }
126 catch (x : TException)
127 {
Jens Geyer1d20a372016-03-15 23:04:27 +0200128 trace('$x ${x.errorID} ${x.errorMsg}');
Jens Geyerb5028322014-11-09 02:38:11 +0100129 }
130 catch (x : Dynamic)
131 {
132 trace('$x');
133 }
134 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200135}