[英]javax.ws.rs.client.WebTarget POST and get Response in the same time
I have a rest API which provide a POST method which transform the input data and stream it as output (the input is streamed also so we can transfer huge data). 我有一个rest API,它提供了POST方法,该方法可以转换输入数据并将其作为输出流化(也对输入流进行流化处理,以便我们可以传输大量数据)。
Using curl, I'm able to get the response processed on the same time than that I post the data like this: 使用curl,与发布这样的数据相比,我能够在同一时间处理响应:
curl -uadmin -X POST "http://XXXX:8080/process" -H "Content-Type: application/octet-stream" --data-binary @myFile.csv > output.csv
Enter host password for user 'admin':
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 5868M 0 14826 0 106k 3627 26777 63:50:21 0:00:04 63:50:17 31293
As you can see, curl is able to receive while sending the data. 如您所见,curl能够在发送数据时接收。
My problem is that I would like to achieve the same thing using java (doing an Apache Spark job) but cannot make it working. 我的问题是,我想使用Java(执行Apache Spark作业)实现相同的目的,但无法使其正常工作。 When I use the program is blocked and I cannot get the Response object:
使用程序时,程序被阻止,无法获取Response对象:
Response response = (javax.ws.rs.client.WebTarget)target.request().post(Entity.entity(is, MediaType.APPLICATION_OCTET_STREAM))
Could someone please help me to solve it ? 有人可以帮我解决吗? (underneath, java uses jersey-client 2.22.2)
(在下面,Java使用jersey-client 2.22.2)
I finally found the good library: async-http-client
. 我终于找到了很好的库:
async-http-client
。 Simply using the org.asynchttpclient.handler.TransferCompletionHandler
functionality. 只需使用
org.asynchttpclient.handler.TransferCompletionHandler
功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.