David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 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 | |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 20 | // Distributed under the Thrift Software License |
| 21 | // |
| 22 | // See accompanying file LICENSE or visit the Thrift site at: |
| 23 | // http://developers.facebook.com/thrift/ |
| 24 | using System; |
| 25 | using System.Collections.Generic; |
Jens Geyer | c1d7943 | 2014-04-22 22:52:43 +0200 | [diff] [blame] | 26 | using System.Security.Cryptography.X509Certificates; |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 27 | using Thrift.Collections; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 28 | using Thrift.Test; //generated code |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 29 | using Thrift.Transport; |
| 30 | using Thrift.Protocol; |
| 31 | using Thrift.Server; |
| 32 | |
| 33 | namespace Test |
| 34 | { |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 35 | public class TestServer |
| 36 | { |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 37 | public class TradeServerEventHandler : TServerEventHandler |
| 38 | { |
| 39 | public int callCount = 0; |
| 40 | public void preServe() |
| 41 | { |
| 42 | callCount++; |
| 43 | } |
| 44 | public Object createContext(Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output) |
| 45 | { |
| 46 | callCount++; |
| 47 | return null; |
| 48 | } |
| 49 | public void deleteContext(Object serverContext, Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output) |
| 50 | { |
| 51 | callCount++; |
| 52 | } |
| 53 | public void processContext(Object serverContext, Thrift.Transport.TTransport transport) |
| 54 | { |
| 55 | callCount++; |
| 56 | } |
| 57 | }; |
| 58 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 59 | public class TestHandler : ThriftTest.Iface |
| 60 | { |
| 61 | public TServer server; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 62 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 63 | public TestHandler() { } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 64 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 65 | public void testVoid() |
| 66 | { |
| 67 | Console.WriteLine("testVoid()"); |
| 68 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 69 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 70 | public string testString(string thing) |
| 71 | { |
| 72 | Console.WriteLine("teststring(\"" + thing + "\")"); |
| 73 | return thing; |
| 74 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 75 | |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame^] | 76 | public bool testBool(bool thing) |
| 77 | { |
| 78 | Console.WriteLine("testBool(" + thing + ")"); |
| 79 | return thing; |
| 80 | } |
| 81 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 82 | public sbyte testByte(sbyte thing) |
| 83 | { |
| 84 | Console.WriteLine("testByte(" + thing + ")"); |
| 85 | return thing; |
| 86 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 87 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 88 | public int testI32(int thing) |
| 89 | { |
| 90 | Console.WriteLine("testI32(" + thing + ")"); |
| 91 | return thing; |
| 92 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 93 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 94 | public long testI64(long thing) |
| 95 | { |
| 96 | Console.WriteLine("testI64(" + thing + ")"); |
| 97 | return thing; |
| 98 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 99 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 100 | public double testDouble(double thing) |
| 101 | { |
| 102 | Console.WriteLine("testDouble(" + thing + ")"); |
| 103 | return thing; |
| 104 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 105 | |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 106 | public byte[] testBinary(byte[] thing) |
| 107 | { |
| 108 | string hex = BitConverter.ToString(thing).Replace("-", string.Empty); |
| 109 | Console.WriteLine("testBinary(" + hex + ")"); |
| 110 | return thing; |
| 111 | } |
| 112 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 113 | public Xtruct testStruct(Xtruct thing) |
| 114 | { |
| 115 | Console.WriteLine("testStruct({" + |
| 116 | "\"" + thing.String_thing + "\", " + |
| 117 | thing.Byte_thing + ", " + |
| 118 | thing.I32_thing + ", " + |
| 119 | thing.I64_thing + "})"); |
| 120 | return thing; |
| 121 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 122 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 123 | public Xtruct2 testNest(Xtruct2 nest) |
| 124 | { |
| 125 | Xtruct thing = nest.Struct_thing; |
| 126 | Console.WriteLine("testNest({" + |
| 127 | nest.Byte_thing + ", {" + |
| 128 | "\"" + thing.String_thing + "\", " + |
| 129 | thing.Byte_thing + ", " + |
| 130 | thing.I32_thing + ", " + |
| 131 | thing.I64_thing + "}, " + |
| 132 | nest.I32_thing + "})"); |
| 133 | return nest; |
| 134 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 135 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 136 | public Dictionary<int, int> testMap(Dictionary<int, int> thing) |
| 137 | { |
| 138 | Console.WriteLine("testMap({"); |
| 139 | bool first = true; |
| 140 | foreach (int key in thing.Keys) |
| 141 | { |
| 142 | if (first) |
| 143 | { |
| 144 | first = false; |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | Console.WriteLine(", "); |
| 149 | } |
| 150 | Console.WriteLine(key + " => " + thing[key]); |
| 151 | } |
| 152 | Console.WriteLine("})"); |
| 153 | return thing; |
| 154 | } |
Jens Geyer | 1c99e70 | 2014-03-17 22:50:39 +0200 | [diff] [blame] | 155 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 156 | public Dictionary<string, string> testStringMap(Dictionary<string, string> thing) |
| 157 | { |
| 158 | Console.WriteLine("testStringMap({"); |
| 159 | bool first = true; |
| 160 | foreach (string key in thing.Keys) |
| 161 | { |
| 162 | if (first) |
| 163 | { |
| 164 | first = false; |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | Console.WriteLine(", "); |
| 169 | } |
| 170 | Console.WriteLine(key + " => " + thing[key]); |
| 171 | } |
| 172 | Console.WriteLine("})"); |
| 173 | return thing; |
| 174 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 175 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 176 | public THashSet<int> testSet(THashSet<int> thing) |
| 177 | { |
| 178 | Console.WriteLine("testSet({"); |
| 179 | bool first = true; |
| 180 | foreach (int elem in thing) |
| 181 | { |
| 182 | if (first) |
| 183 | { |
| 184 | first = false; |
| 185 | } |
| 186 | else |
| 187 | { |
| 188 | Console.WriteLine(", "); |
| 189 | } |
| 190 | Console.WriteLine(elem); |
| 191 | } |
| 192 | Console.WriteLine("})"); |
| 193 | return thing; |
| 194 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 195 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 196 | public List<int> testList(List<int> thing) |
| 197 | { |
| 198 | Console.WriteLine("testList({"); |
| 199 | bool first = true; |
| 200 | foreach (int elem in thing) |
| 201 | { |
| 202 | if (first) |
| 203 | { |
| 204 | first = false; |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | Console.WriteLine(", "); |
| 209 | } |
| 210 | Console.WriteLine(elem); |
| 211 | } |
| 212 | Console.WriteLine("})"); |
| 213 | return thing; |
| 214 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 215 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 216 | public Numberz testEnum(Numberz thing) |
| 217 | { |
| 218 | Console.WriteLine("testEnum(" + thing + ")"); |
| 219 | return thing; |
| 220 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 221 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 222 | public long testTypedef(long thing) |
| 223 | { |
| 224 | Console.WriteLine("testTypedef(" + thing + ")"); |
| 225 | return thing; |
| 226 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 227 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 228 | public Dictionary<int, Dictionary<int, int>> testMapMap(int hello) |
| 229 | { |
| 230 | Console.WriteLine("testMapMap(" + hello + ")"); |
| 231 | Dictionary<int, Dictionary<int, int>> mapmap = |
| 232 | new Dictionary<int, Dictionary<int, int>>(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 233 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 234 | Dictionary<int, int> pos = new Dictionary<int, int>(); |
| 235 | Dictionary<int, int> neg = new Dictionary<int, int>(); |
| 236 | for (int i = 1; i < 5; i++) |
| 237 | { |
| 238 | pos[i] = i; |
| 239 | neg[-i] = -i; |
| 240 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 241 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 242 | mapmap[4] = pos; |
| 243 | mapmap[-4] = neg; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 244 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 245 | return mapmap; |
| 246 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 247 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 248 | public Dictionary<long, Dictionary<Numberz, Insanity>> testInsanity(Insanity argument) |
| 249 | { |
| 250 | Console.WriteLine("testInsanity()"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 251 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 252 | Xtruct hello = new Xtruct(); |
| 253 | hello.String_thing = "Hello2"; |
| 254 | hello.Byte_thing = 2; |
| 255 | hello.I32_thing = 2; |
| 256 | hello.I64_thing = 2; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 257 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 258 | Xtruct goodbye = new Xtruct(); |
| 259 | goodbye.String_thing = "Goodbye4"; |
| 260 | goodbye.Byte_thing = (sbyte)4; |
| 261 | goodbye.I32_thing = 4; |
| 262 | goodbye.I64_thing = (long)4; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 263 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 264 | Insanity crazy = new Insanity(); |
| 265 | crazy.UserMap = new Dictionary<Numberz, long>(); |
| 266 | crazy.UserMap[Numberz.EIGHT] = (long)8; |
| 267 | crazy.Xtructs = new List<Xtruct>(); |
| 268 | crazy.Xtructs.Add(goodbye); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 269 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 270 | Insanity looney = new Insanity(); |
| 271 | crazy.UserMap[Numberz.FIVE] = (long)5; |
| 272 | crazy.Xtructs.Add(hello); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 273 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 274 | Dictionary<Numberz, Insanity> first_map = new Dictionary<Numberz, Insanity>(); |
| 275 | Dictionary<Numberz, Insanity> second_map = new Dictionary<Numberz, Insanity>(); ; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 276 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 277 | first_map[Numberz.TWO] = crazy; |
| 278 | first_map[Numberz.THREE] = crazy; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 279 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 280 | second_map[Numberz.SIX] = looney; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 281 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 282 | Dictionary<long, Dictionary<Numberz, Insanity>> insane = |
| 283 | new Dictionary<long, Dictionary<Numberz, Insanity>>(); |
| 284 | insane[(long)1] = first_map; |
| 285 | insane[(long)2] = second_map; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 286 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 287 | return insane; |
| 288 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 289 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 290 | public Xtruct testMulti(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5) |
| 291 | { |
| 292 | Console.WriteLine("testMulti()"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 293 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 294 | Xtruct hello = new Xtruct(); ; |
| 295 | hello.String_thing = "Hello2"; |
| 296 | hello.Byte_thing = arg0; |
| 297 | hello.I32_thing = arg1; |
| 298 | hello.I64_thing = arg2; |
| 299 | return hello; |
| 300 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 301 | |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 302 | /** |
| 303 | * Print 'testException(%s)' with arg as '%s' |
| 304 | * @param string arg - a string indication what type of exception to throw |
| 305 | * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg |
| 306 | * elsen if arg == "TException" throw TException |
| 307 | * else do not throw anything |
| 308 | */ |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 309 | public void testException(string arg) |
| 310 | { |
| 311 | Console.WriteLine("testException(" + arg + ")"); |
| 312 | if (arg == "Xception") |
| 313 | { |
| 314 | Xception x = new Xception(); |
| 315 | x.ErrorCode = 1001; |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 316 | x.Message = arg; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 317 | throw x; |
| 318 | } |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 319 | if (arg == "TException") |
| 320 | { |
| 321 | throw new Thrift.TException(); |
| 322 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 323 | return; |
| 324 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 325 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 326 | public Xtruct testMultiException(string arg0, string arg1) |
| 327 | { |
| 328 | Console.WriteLine("testMultiException(" + arg0 + ", " + arg1 + ")"); |
| 329 | if (arg0 == "Xception") |
| 330 | { |
| 331 | Xception x = new Xception(); |
| 332 | x.ErrorCode = 1001; |
| 333 | x.Message = "This is an Xception"; |
| 334 | throw x; |
| 335 | } |
| 336 | else if (arg0 == "Xception2") |
| 337 | { |
| 338 | Xception2 x = new Xception2(); |
| 339 | x.ErrorCode = 2002; |
| 340 | x.Struct_thing = new Xtruct(); |
| 341 | x.Struct_thing.String_thing = "This is an Xception2"; |
| 342 | throw x; |
| 343 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 344 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 345 | Xtruct result = new Xtruct(); |
| 346 | result.String_thing = arg1; |
| 347 | return result; |
| 348 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 349 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 350 | public void testStop() |
| 351 | { |
| 352 | if (server != null) |
| 353 | { |
| 354 | server.Stop(); |
| 355 | } |
| 356 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 357 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 358 | public void testOneway(int arg) |
| 359 | { |
| 360 | Console.WriteLine("testOneway(" + arg + "), sleeping..."); |
| 361 | System.Threading.Thread.Sleep(arg * 1000); |
| 362 | Console.WriteLine("testOneway finished"); |
| 363 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 364 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 365 | } // class TestHandler |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 366 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 367 | public static bool Execute(string[] args) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 368 | { |
| 369 | try |
| 370 | { |
| 371 | bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false; |
| 372 | int port = 9090; |
| 373 | string pipe = null; |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 374 | string certPath = "../../../../../keys/server.pem"; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 375 | for (int i = 0; i < args.Length; i++) |
| 376 | { |
| 377 | if (args[i] == "-pipe") // -pipe name |
| 378 | { |
| 379 | pipe = args[++i]; |
| 380 | } |
| 381 | else if (args[i].Contains("--port=")) |
| 382 | { |
| 383 | port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1)); |
| 384 | } |
| 385 | else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered") |
| 386 | { |
| 387 | useBufferedSockets = true; |
| 388 | } |
| 389 | else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed") |
| 390 | { |
| 391 | useFramed = true; |
| 392 | } |
| 393 | else if (args[i] == "--compact" || args[i] == "--protocol=compact") |
| 394 | { |
| 395 | compact = true; |
| 396 | } |
| 397 | else if (args[i] == "--json" || args[i] == "--protocol=json") |
| 398 | { |
| 399 | json = true; |
| 400 | } |
| 401 | else if (args[i] == "--ssl") |
| 402 | { |
| 403 | useEncryption = true; |
| 404 | } |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 405 | else if (args[i].StartsWith("--cert=")) |
| 406 | { |
| 407 | certPath = args[i].Substring("--cert=".Length); |
| 408 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 409 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 410 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 411 | // Processor |
| 412 | TestHandler testHandler = new TestHandler(); |
| 413 | ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 414 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 415 | // Transport |
| 416 | TServerTransport trans; |
| 417 | if( pipe != null) |
| 418 | { |
| 419 | trans = new TNamedPipeServerTransport(pipe); |
| 420 | } |
| 421 | else |
| 422 | { |
| 423 | if (useEncryption) |
| 424 | { |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 425 | trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2(certPath)); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 426 | } |
| 427 | else |
| 428 | { |
| 429 | trans = new TServerSocket(port, 0, useBufferedSockets); |
| 430 | } |
| 431 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 432 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 433 | TProtocolFactory proto; |
| 434 | if ( compact ) |
| 435 | proto = new TCompactProtocol.Factory(); |
| 436 | else if ( json ) |
| 437 | proto = new TJSONProtocol.Factory(); |
| 438 | else |
| 439 | proto = new TBinaryProtocol.Factory(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 440 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 441 | // Simple Server |
| 442 | TServer serverEngine; |
| 443 | if ( useFramed ) |
| 444 | serverEngine = new TSimpleServer(testProcessor, trans, new TFramedTransport.Factory(), proto); |
| 445 | else |
| 446 | serverEngine = new TSimpleServer(testProcessor, trans, new TTransportFactory(), proto); |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 447 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 448 | // ThreadPool Server |
| 449 | // serverEngine = new TThreadPoolServer(testProcessor, tServerSocket); |
| 450 | |
| 451 | // Threaded Server |
| 452 | // serverEngine = new TThreadedServer(testProcessor, tServerSocket); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 453 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 454 | //Server event handler |
| 455 | TradeServerEventHandler serverEvents = new TradeServerEventHandler(); |
| 456 | serverEngine.setEventHandler(serverEvents); |
| 457 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 458 | testHandler.server = serverEngine; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 459 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 460 | // Run it |
| 461 | string where = ( pipe != null ? "on pipe "+pipe : "on port " + port); |
| 462 | Console.WriteLine("Starting the server " + where + |
| 463 | (useBufferedSockets ? " with buffered socket" : "") + |
| 464 | (useFramed ? " with framed transport" : "") + |
| 465 | (useEncryption ? " with encryption" : "") + |
| 466 | (compact ? " with compact protocol" : "") + |
| 467 | (json ? " with json protocol" : "") + |
| 468 | "..."); |
| 469 | serverEngine.Serve(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 470 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 471 | } |
| 472 | catch (Exception x) |
| 473 | { |
| 474 | Console.Error.Write(x); |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 475 | return false; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 476 | } |
| 477 | Console.WriteLine("done."); |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 478 | return true; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 479 | } |
| 480 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 481 | } |