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
10 -- http://www.apache.org/licenses/LICENSE-2.0
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
20 import qualified Calculator
21 import qualified Calculator_Client as Client
22 import qualified SharedService_Client as SClient
24 import SharedService_Iface
28 import Thrift.Protocol.Binary
29 import Thrift.Transport
30 import Thrift.Transport.Handle
33 import Control.Exception
40 transport <- hOpen ("localhost", PortNumber 9090)
41 let binProto = BinaryProtocol transport
42 let client = (binProto, binProto)
47 sum <- Client.add client 1 1
51 let work = Work { work_op = DIVIDE,
54 work_comment = Nothing
57 Control.Exception.catch (printf "1/0=%d\n" =<< Client.calculate client 1 work)
58 (\e -> printf "InvalidOperation %s\n" (show (e :: InvalidOperation)))
61 let work = Work { work_op = SUBTRACT,
64 work_comment = Nothing
67 diff <- Client.calculate client 1 work
68 printf "15-10=%d\n" diff
70 log <- SClient.getStruct client 1
71 printf "Check log: %s\n" $ unpack $ sharedStruct_value log