我正在使用一个servlet,它将String参数传递给另一个远程系统中的另一个Servlet,以从该远程servlet获取xml响应。
当我尝试从本地PC连接到远程Servlet时,这很好用。
但是当我从另一台服务器执行相同操作时,我收到错误java.net.SocketException: Unexpected end of file from server
。
错误:
2011-06-04 11:27:24,305 INFO [STDOUT] strURL in Inventry --> http://1**.1**.**.27:7777/GatewayServlet
/Status?Str=Inventory&PARTNUM=200A104%27%2C%27200A112%27%2C%27200A114%27%2C%27200A113%27%2C%27200A117%27%2C%27200A120%27%2C%27240A503%27%2C%27200A132%27%2C%27200A128%27%2C%27200A124
2011-06-04 11:28:06,243 ERROR [STDERR] java.net.SocketException: Unexpected end of file from server
2011-06-04 11:28:06,243 ERROR [STDERR] at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
2011-06-04 11:28:06,243 ERROR [STDERR] at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
2011-06-04 11:28:06,243 ERROR [STDERR] at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
2011-06-04 11:28:06,243 ERROR [STDERR] at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
2011-06-04 11:28:06,243 ERROR [STDERR] at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
2011-06-04 11:28:06,243 ERROR [STDERR] at com.cim.web.servlet.DBGatewayServiceServlet.processRequest(DBGatewayServiceServlet.java:52)
2011-06-04 11:28:06,243 ERROR [STDERR] at com.cim.web.servlet.DBGatewayServiceServlet.doGet(DBGatewayServiceServlet.java:113)
2011-06-04 11:28:06,243 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
2011-06-04 11:28:06,243 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
2 011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
2011-06-04 11:28:06,243 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
2011-06-04 11:28:06,243 ERROR [STDERR] at java.lang.Thread.run(Unknown Source)
My Servlet中的代码(客户端):
if(queryString.equals("Inventory")) {
String partNum = (String)session.getAttribute("PARTNUM");
String locId = (String)session.getAttribute("locids");
strURL = strURL+"/InventoryStatus?queryStr=Inventory&PARTNUM="+partNum;
URLConnection dbGatewayURL = new URL(strURL).openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(dbGatewayURL.getInputStream()));//--This is line 52 Mentioned in Error above
StringBuffer responseData = new StringBuffer();
String line="";
while((line = in.readLine()) != null) {
responseData.append(line);
}
String result =responseData.toString();
request.setAttribute("inventryStock",result);
RequestDispatcher rd=request.getRequestDispatcher ("inventryStatus.jsp?resp=Yes");
rd.forward(request, response);
}
答案 0 :(得分:2)
尝试从服务器远程登录到远程servlet,看看它是否按预期连接。如果不是,那就是连接问题。
如果是,请尝试使用TCP监视器查看从服务器到具有servlet的远程服务器的HTTP流量。 http://ws.apache.org/commons/tcpmon/
答案 1 :(得分:1)
尝试立即等待() URLConnection dbGatewayURL =新URL(strURL).openConnection();
程序可以移动到下一行之前它能够建立连接
答案 2 :(得分:1)
代码没有任何问题,但事情是远程服务器没有从我的服务器监听连接,因此我尝试了相同的代码,但这次在另一台远程服务器上工作正常....!任何人都知道原因............?