1/* 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{ 33 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"); 45 #if !phpwebserver 46 throw "HTTP server not implemented yet"; 47 //transport = new THttpServer( targetHost); 48 #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 57 default: 58 throw "Unhandled transport"; 59 } 60 61 // 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"); 69 transfactory = new TBufferedTransportFactory(); 70 } 71 72 // 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(); 82 case compact: 83 trace("- compact protocol"); 84 protfactory = new TCompactProtocolFactory(); 85 } 86 87 88 // Processor 89 var handler = new TestServerHandler(); 90 var processor = new ThriftTestProcessor(handler); 91 92 // Simple Server 93 var server : TServer = null; 94 switch( args.servertype) 95 { 96 case simple: 97 var simpleServer = new TSimpleServer( processor, transport, transfactory, protfactory); 98 #if phpwebserver 99 simpleServer.runOnce = true; 100 #end 101 server = simpleServer; 102 103 default: 104 throw "Unhandled server type"; 105 } 106 107 108 /* 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 { 124 trace('$x ${x.errorID} ${x.errorMsg}'); 125 } 126 catch (x : Dynamic) 127 { 128 trace('$x'); 129 } 130 } 131} 132