Jetty HttpClent错误“java.util.concurrent.ExecutionException:org.eclipse.Jetty.io.EOFEException”
我目前正在开发一个模块,其中我使用Jetty HttpClient将JSON格式的数据发送到服务器端运行的REST服务
简而言之,用例:
- 我有一个包含10000个条目的CSV文件李>
- 需要将CSV条目转换为Java POJO对象,然后转换为JSON格式李>
- 将转换后的JSON格式发送到服务器端运行的RESTWeb服务李>
- 它还应该执行身份验证过程,同时使用RESTWeb服务调用将JSON格式的数据发送到服务器李>
问题: 如果我尝试发送所有10000个条目以及身份验证过程,我会得到以下异常:
java.util.concurrent.ExecutionException: org.eclipse.jetty.io.EofException at org.eclipse.jetty.client.util.FutureResponseListener.getResult(FutureResponseListener.java:118) at org.eclipse.jetty.client.util.FutureResponseListener.get(FutureResponseListener.java:101) at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:653)
Caused by: org.eclipse.jetty.io.EofException
at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:192) at org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:408) at org.eclipse.jetty.io.WriteFlusher.completeWrite(WriteFlusher.java:364) at org.eclipse.jetty.io.SelectChannelEndPoint.onSelected(SelectChannelEndPoint.java:111) at org.eclipse.jetty.io.SelectorManager$ManagedSelector.processKey(SelectorManager.java:636) at org.eclipse.jetty.io.SelectorManager$ManagedSelector.select(SelectorManager.java:607) at org.eclipse.jetty.io.SelectorManager$ManagedSelector.run(SelectorManager.java:545) at org.eclipse.jetty.util.thread.NonBlockingThread.run(NonBlockingThread.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.write0(Native Method) at sun.nio.ch.SocketDispatcher.write(Unknown Source) at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source) at sun.nio.ch.IOUtil.write(Unknown Source) at sun.nio.ch.SocketChannelImpl.write(Unknown Source) at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:170)
... 10 more
批量转换10000个条目 如果我成批转换所有10000个条目(例如,10个条目的成批转换)。我能够成功地用相同的URL和身份验证过程发送数据
参考所需的代码如下所示:
String user = "myuser";
String passwd = "mypassword";
String relm = "Realm";
String URL = "http://localhost:9123/path/to/rest/service/";
HttpClient httpClient = new HttpClient();
httpClient.start();
httpClient.setConnectTimeout(10000);
Gson gson = new Gson();
String content = gson.toJson();
AuthenticationStore authentication = httpClient.getAuthenticationStore();
BasicAuthentication basicAuth = new BasicAuthentication(new URI(URL), relm, user, passwd);
authentication.addAuthentication(basicAuth);
StringContentProvider contentProvider = new StringContentProvider("application/json", content, StandardCharsets.UTF_8);
Request request = httpClient.newRequest(tURL);
request.method(HttpMethod.POST);
request.content(contentProvider);
ContentResponse response = request.send();
//ContentResponse response = httpClient.newRequest(URL).method(HttpMethod.POST).content(contentProvider).send();
int status = response.getStatus();
String reason = response.getReason();
logger.info("REASON IS :: " + reason);
logger.info("RESPONSE STATUS :: " + status);
请帮我解决这个问题
共 (0) 个答案