私はかなり単純な Thrift IDL を持っています (図のように 2 つのファイルに分割されています)。
コア。スリフト
namespace cpp MyProduct.Core
namespace java com.mycompany.myproduct.core
namespace py myproduct.core
/**
* Struct used to indicate a location referenced by geodetic coordinates.
*/
struct GeoPoint{
/**
* Latitude for this point
*/
1: required double latitude;
/**
* Longitude for this point
*/
2: required double longitude;
/**
* Elevation for this point
*/
3: required double elevation;
}
加工・倹約
include "core.thrift"
namespace cpp MyProduct.Processing
namespace java com.mycompany.myproduct.processing
namespace py myproduct.processing
/**
* MyProduct processing services
*/
service PointsQuery{
/**
* Returns elevation of a list of input (geodetic) points
* The elevation attribute in input GeoPoints are ignored
*/
list<double> getElevations(1: required list<core.GeoPoint> inputPoints = [], 2: required string layername = "undefined");
}
Python Tornado サーバーと Java クライアントを使用しています。コードは次のようになります。
Python サーバー:
class PointQueryHandler(object):
def __init__(self):
self.log = {}
def getElevations(self, inputPoints, layerName, callback=None):
elevation_list = []
// ...implementation here to fill elevation list with doubles...
if callback:
callback(elevation_list)
else:
return elevation_list
def main():
handler = PointQueryHandler()
processor = PointsQuery.Processor(handler)
factory = TBinaryProtocol.TBinaryProtocolFactory()
server = TTornado.TTornadoServer(processor, factory)
print "Starting the server..."
server.bind(9090)
server.start(1)
ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()
Java クライアント:
public class QueryPointsTest {
public static void main(String [] args) {
try {
TTransport transport;
transport = new TSocket("localhost", 9090);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
PointsQuery.Client client = new PointsQuery.Client(protocol);
perform(client);
transport.close();
} catch (TTransportException x) {
System.out.println("Unable to connect to service provider: " + "localhost" + 9090);
} catch (TException err){
System.out.println("Error when accessing remote service: ");
err.printStackTrace();
}
}
private static void perform(PointsQuery.Client client) throws TException
{
List<GeoPoint> pointList = new ArrayList<GeoPoint>();
GeoPoint pt1 = new GeoPoint(74.53951, 34.36709, 0.0);
GeoPoint pt2 = new GeoPoint(74.52242,34.35413, 0.0);
GeoPoint pt3 = new GeoPoint(74.51398,34.41069, 0.0);
GeoPoint pt4 = new GeoPoint(83, 39.36709, 0.0);
pointList.add(pt1);
pointList.add(pt2);
pointList.add(pt3);
pointList.add(pt4);
List<Double> result = client.getElevations(pointList, "dummylayername");
System.out.println("Done");
}
}
クライアントがサーバーに正常に接続し、Python PointQueryHandler.getElevations 関数が呼び出されます。ただし、問題は、PointQueryHandler.getElevations への引数が常に空のリストと「未定義」文字列のデフォルト引数であることです。Java クライアントから渡したデータが、何らかの理由でサーバーに到着しません。
何がうまくいかないのですか?
(Thrift バージョン: 0.9.2、Python 2.7.5、JDK 1.7.0_45、プラットフォーム: Windows 7 64 ビット)