0

How to setup Apache Thrift communication between a Java client and a PHP server?

I have PHP codes on server side:

$header('Content-Type', 'application/x-thrift');
$handler = new MyApplicationHandler();
$processor = new \tutorial\MyApplicationProcessor($handler);

$transport = new TFramedTransport(
    new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W));
$protocol = new TBinaryProtocol($transport, true, true);

$transport->open();
$processor->process($protocol, $protocol);
$transport->close();

And Java codes on the client side:

THttpClient httpClient  =
    new THttpClient("http://my.application.com/PhpServer.php");

TTransport transport = new TFramedTransport(httpClient);
transport.open();

TProtocol protocol = new TBinaryProtocol(transport);
MyApplication.Client client = new MyApplication.Client(protocol);

Boolean result = client.someApi(someData); // <-- will crash here

transport.close();

The client will crash when executing this line:

client.someApi(someData);

Is there something wrong in my codes?

JensG
  • 13,148
  • 4
  • 45
  • 55
Jack Chen
  • 79
  • 1
  • 7
  • Is "http://my.application.com/PhpServer.php" available when you use a browser? No error details? – Jeroen Heier Feb 02 '17 at 05:13
  • What does "*crash*" mean exactly? It never ceases to amaze me why even programmers(!) can't include all the obviously relevant details in a problem description. I mean, you guys *know* how it is to get incomplete error reports. – JensG Feb 02 '17 at 10:10
  • @JeroenHeier Sorry for confusion, "my.application.com/PhpServer.php" is just an example. Currently my domain name is temporary and very ugly. – Jack Chen Feb 03 '17 at 06:20
  • @JensG I used Android studio to debug. I put break point in the codes and after my break point was hit, I stepped line by line. After I went through that line, Android studio simply freeze, and my application just closed. I couldn't find a way to get more information about what really happened. – Jack Chen Feb 03 '17 at 06:25

0 Answers0