Jetty HttpClent错误" java.util.concurrent.ExecutionException:org.eclipse.jetty.io.EofException"

时间:2016-02-01 09:16:23

标签: java jetty httpclient

我目前正在开发一个模块,我使用Jetty HttpClient将数据以JSON格式发送到服务器端运行的REST服务。

简称用例:

  1. 我有一个包含10000个条目的CSV文件。
  2. 需要将CSV条目转换为Java POJO对象,然后转换为JSON格式。
  3. 将转换后的JSON格式发送到服务器端运行的REST Web服务。
  4. 它还应该在使用REST Web服务调用将JSON格式的数据发送到服务器时执行身份验证过程。
  5. 问题: 如果我尝试发送所有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)       在org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:653)
      引起:org.eclipse.jetty.io.EofException
          在org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:192)       在org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:408)       at org.eclipse.jetty.io.WriteFlusher.completeWrite(WriteFlusher.java:364)       在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)       在org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)       在org.eclipse.jetty.util.thread.QueuedThreadPool $ 3.run(QueuedThreadPool.java:555)       在java.lang.Thread.run(未知来源)
      引起:java.io.IOException:已建立的连接被主机中的软件中止       at sun.nio.ch.SocketDispatcher.write0(Native Method)       at sun.nio.ch.SocketDispatcher.write(Unknown Source)       at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source)       在sun.nio.ch.IOUtil.write(未知来源)       at sun.nio.ch.SocketChannelImpl.write(Unknown Source)       在org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:170)
          ......还有10个

    批量转换10000个条目 如果我批量转换所有10000个条目(批量为ex: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 个答案:

没有答案