| 183 | } |
| 184 | |
| 185 | private String thriftRequest(byte[] input){ |
| 186 | try{ |
| 187 | |
| 188 | //Input |
| 189 | TMemoryBuffer inbuffer = new TMemoryBuffer(input.length); |
| 190 | inbuffer.write(input); |
| 191 | TProtocol inprotocol = new TJSONProtocol(inbuffer); |
| 192 | |
| 193 | //Output |
| 194 | TMemoryBuffer outbuffer = new TMemoryBuffer(100); |
| 195 | TProtocol outprotocol = new TJSONProtocol(outbuffer); |
| 196 | |
| 197 | TProcessor processor = new Calculator.Processor(new CalculatorHandler()); |
| 198 | processor.process(inprotocol, outprotocol); |
| 199 | |
| 200 | byte[] output = new byte[outbuffer.length()]; |
| 201 | outbuffer.readAll(output, 0, output.length); |
| 202 | |
| 203 | return new String(output,"UTF-8"); |
| 204 | }catch(Throwable t){ |
| 205 | return "Error:"+t.getMessage(); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | } |
| 210 | |
| 211 | } |
| 212 | |