具有io异常的http 500 servlet - 处于不确定状态

时间:2014-02-13 02:36:47

标签: java http tomcat ioexception http-error

我通过servlet将文件上传到我的服务器上。 它一直很好,直到今天下午,突然间我开始得到

java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8282

我一直在使用tomcat 7进行应用程序,并且工作正常。 我不确定服务器内发生了什么事情,或者问题究竟发生在哪里。

我试过了:

  1. 更改不同的端口
  2. 清理,删除和使用不同的服务器(Vfabric)
  3. JAVA_TOOL_OPTIONS添加到系统变量。
  4. 卸载并重新安装tomcat。
  5. 尝试重新启动系统以查看是否有任何打开/守护程序线程挂起。
  6. 增加了tomcat文件夹中server.xml的最大线程大小。
  7. 我无法找到解决问题的其他可行方案。如果可能,请建议并提供见解。

    以下是我的应用程序中的代码:(客户端代码):

    private URLConnection getServletConnection() throws MalformedURLException,
                IOException {
    
            // Config
            servletConnection.setDoInput(true);
            servletConnection.setDoOutput(true);
            servletConnection.setUseCaches(false);
            servletConnection.setDefaultUseCaches(false);
            servletConnection.setRequestMethod("POST");
            servletConnection.setRequestProperty("Content-Type",
                    "multipart/form-data;boundary=" + this.boundary);
            servletConnection.setRequestProperty("Connection", "Keep-Alive");
            servletConnection.connect();
            return servletConnection;
        }
    
        private boolean onSendData(String fileEntry) {
            try {
                // Send data to the servlet
                HttpURLConnection servletConnection = (HttpURLConnection) getServletConnection();
                DataOutputStream dataOutputStream = new DataOutputStream(
                        servletConnection.getOutputStream());
                final FileInputStream fileInputStream = new FileInputStream(
                ...
                // send multipart form data necesssary after file data
                dataOutputStream.writeBytes(lineEnd);
                dataOutputStream.writeBytes(twoHyphens + boundary + twoHyphens
                        + lineEnd);
    
    
                // Receive result from servlet
                InputStream inputStream = servletConnection.getInputStream();
                ObjectInputStream objectInputStream = new ObjectInputStream(
                        inputStream);
                String result = (String) objectInputStream.readObject();
    
                objectInputStream.close();
                inputStream.close();
                dataOutputStream.flush();
                dataOutputStream.close();
                fileInputStream.close();
    
            } catch (java.net.MalformedURLException mue) {
                mue.printStackTrace();
                System.out
                        .println("Invalid serlvetUrl, error: " + mue.getMessage());
                errorLabel.setText(mue.getMessage());
            } catch (java.io.IOException ioe) {
                ioe.printStackTrace();
                System.out.println("Couldn't open a URLConnection, error: "
                        + ioe.getMessage());
                errorLabel.setText(ioe.getMessage());
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("Exception caught, error: " + e.getMessage());
                errorLabel.setText(e.getMessage());
            }
            return fileUploaded;
        } 
    

    这就是我所看到的错误(当我在我的IDE中运行代码时):

    Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8282/UploadFile/upload
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
        at com.FileUpload.onSendData(FileUpload.java:317)
        ... 4 more
    

    奇怪的是,当我在网络浏览器上运行它(作为一个签名的JAR文件运行)时,我在java控制台中看到以下错误(这是一个小程序)。

    java.net.ConnectException: Connection refused: connect
        at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
        at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
        at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at sun.net.NetworkClient.doConnect(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
        at sun.net.www.http.HttpClient.<init>(Unknown Source)
        at sun.net.www.http.HttpClient.New(Unknown Source)
        at sun.net.www.http.HttpClient.New(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
       Couldn't open a URLConnection, error: Connection refused: connect
    

0 个答案:

没有答案