You can use Swift .
Shortly speaking; annotate your classes and interfaces (structures and services in Trrift). You can then either run the Swift client / server code, or use the swift2thrift generator to create the equivalent IDL and use the Thrift compiler to generate the clients (the latter is what I recommend for what you are describing).
Once this is done to create a TProcessor that you can use in TServlet with regular TProtocol / TTransport objects, do something similar in your init () servlet:
protected void addProcessor(String name, Object svc) {
ThriftCodecManager codecManager = new ThriftCodecManager(
new CompilerThriftCodecFactory(false)
);
List<ThriftEventHandler> eventList = Collections.emptyList();
ThriftServiceProcessor proc = new ThriftServiceProcessor(codecManager, eventList, svc);
this.processors.put(name, proc);
this.multiplex.registerProcessor(name, NiftyProcessorAdapters.processorToTProcessor(proc));
}
The multiplex instance variable in this example is an instance TMultiplexedProcessorof libthrift.jar.
Then just do it in your doPost ():
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
getServletContext().log("entering doPost()");
TTransport inTransport = null;
TTransport outTransport = null;
try {
InputStream in = request.getInputStream();
OutputStream out = response.getOutputStream();
TTransport transport = new TIOStreamTransport(in, out);
inTransport = transport;
outTransport = transport;
TProtocol inProtocol = getInProtocolFactory().getProtocol(inTransport);
TProtocol outProtocol = getOutProtocolFactory().getProtocol(outTransport);
if (multiplex.process(inProtocol, outProtocol)) {
out.flush();
} else {
throw new ServletException("multiplex.process() returned false");
}
} catch (TException te) {
throw new ServletException(te);
} finally {
if (inTransport != null) {
inTransport.close();
}
if (outTransport != null) {
outTransport.close();
}
}
}
FYI - TJSONProtocol Swift 0.14, , .
... Swift final... JPA , final... , Eclipselink, YMMV