Anthony F. Molinaro | 71a58a8 | 2010-09-27 19:27:40 +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 _ 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 | |
| 20 | module ThriftTest_TestServer where |
| 21 | |
| 22 | import ThriftTest |
| 23 | import ThriftTest_Iface |
| 24 | import Data.Map as Map |
| 25 | import Control.Exception |
| 26 | import ThriftTest_Types |
| 27 | |
| 28 | import Thrift |
| 29 | import Thrift.Server |
| 30 | |
| 31 | |
| 32 | data TestHandler = TestHandler |
| 33 | instance ThriftTest_Iface TestHandler where |
| 34 | testVoid _ = return () |
| 35 | |
| 36 | testString _ (Just s) = do |
| 37 | print s |
| 38 | return s |
| 39 | |
| 40 | testString _ Nothing = do |
| 41 | error $ "Unsupported testString form" |
| 42 | |
| 43 | testByte _ (Just x) = do |
| 44 | print x |
| 45 | return x |
| 46 | |
| 47 | testByte _ Nothing = do |
| 48 | error $ "Unsupported testByte form" |
| 49 | |
| 50 | testI32 _ (Just x) = do |
| 51 | print x |
| 52 | return x |
| 53 | |
| 54 | testI32 _ Nothing = do |
| 55 | error $ "Unsupported testI32 form" |
| 56 | |
| 57 | testI64 _ (Just x) = do |
| 58 | print x |
| 59 | return x |
| 60 | |
| 61 | testI64 _ Nothing = do |
| 62 | error $ "Unsupported testI64 form" |
| 63 | |
| 64 | testDouble _ (Just x) = do |
| 65 | print x |
| 66 | return x |
| 67 | |
| 68 | testDouble _ Nothing = do |
| 69 | error $ "Unsupported testDouble form" |
| 70 | |
| 71 | testStruct _ (Just x) = do |
| 72 | print x |
| 73 | return x |
| 74 | |
| 75 | testStruct _ Nothing = do |
| 76 | error $ "Unsupported testStruct form" |
| 77 | |
| 78 | testNest _ (Just x) = do |
| 79 | print x |
| 80 | return x |
| 81 | |
| 82 | testNest _ Nothing = do |
| 83 | error $ "Unsupported testNest form" |
| 84 | |
| 85 | testMap _ (Just x) = do |
| 86 | print x |
| 87 | return x |
| 88 | |
| 89 | testMap _ Nothing = do |
| 90 | error $ "Unsupported testMap form" |
| 91 | |
| 92 | testSet _ (Just x) = do |
| 93 | print x |
| 94 | return x |
| 95 | |
| 96 | testSet _ Nothing = do |
| 97 | error $ "Unsupported testSet form" |
| 98 | |
| 99 | testList _ (Just x) = do |
| 100 | print x |
| 101 | return x |
| 102 | |
| 103 | testList _ Nothing = do |
| 104 | error $ "Unsupported testList form" |
| 105 | |
| 106 | testEnum _ (Just x) = do |
| 107 | print x |
| 108 | return x |
| 109 | |
| 110 | testEnum _ Nothing = do |
| 111 | error $ "Unsupported testEnum form" |
| 112 | |
| 113 | testTypedef _ (Just x) = do |
| 114 | print x |
| 115 | return x |
| 116 | |
| 117 | testTypedef _ Nothing = do |
| 118 | error $ "Unsupported testTypedef form" |
| 119 | |
| 120 | testMapMap _ (Just _) = do |
| 121 | return (Map.fromList [(1, Map.fromList [(2, 2)])]) |
| 122 | |
| 123 | testMapMap _ Nothing = do |
| 124 | error $ "Unsupported testMapMap form" |
| 125 | |
| 126 | testInsanity _ (Just x) = do |
| 127 | return (Map.fromList [(1, Map.fromList [(ONE, x)])]) |
| 128 | |
| 129 | testInsanity _ Nothing = do |
| 130 | error $ "Unsupported testInsanity form" |
| 131 | |
| 132 | testMulti _ _ _ _ _ _ _ = do |
| 133 | return (Xtruct Nothing Nothing Nothing Nothing) |
| 134 | |
| 135 | testException _ _ = do |
| 136 | throw (Xception (Just 1) (Just "bya")) |
| 137 | |
| 138 | testMultiException _ _ _ = do |
| 139 | throw (Xception (Just 1) (Just "xyz")) |
| 140 | |
| 141 | testOneway _ (Just i) = do |
| 142 | print i |
| 143 | |
| 144 | testOneway _ Nothing = do |
| 145 | error $ "Unsupported testOneway form" |
| 146 | |
| 147 | |
| 148 | main :: IO () |
| 149 | main = do putStrLn "Server ready..." |
| 150 | (runBasicServer TestHandler process 9090) |
| 151 | `Control.Exception.catch` |
| 152 | (\(TransportExn s _) -> print s) |