0 Replies Latest reply: Jun 15, 2010 9:14 AM by 807580 RSS

    Is it possible to detect network errors using jersey and REST?

    807580
      Hi,

      I'm working on an application that does some work with transferring files to a client device using jersey.
      I want to know if it's possible to detect if a network error occurs between the client and the web service
      and then log that to some file.

      I've tried using @context HttpServletResponse and HttpServletRequest to catch any errors, but this
      doesn't seem to throw any errors at all while a file transfer in progress is terminated.

      Here's a snippet of the code I used:
          private String GetData(HttpServletRequest request,
                                   String PID, String fileName) throws IOException {
      
              boolean ok = false;
              ServletInputStream servletIn = null;
              StringBuilder sb = new StringBuilder();
              int character = 0;
              String status = "";
      
              try {
                  servletIn = request.getInputStream();
                  while ((character = servletIn.read()) != -1) { 
                      sb.append((char) character);
                  }                        
                  ok = true;
                  status = "Successfully received " + fileName; 
              } catch (IOException ioe) { 
                  ok = false;
                  status = ioe.getMessage();
                  throw ioe;
              } finally {
                  if (servletIn != null) {
                      try {
                          servletIn.close();
                      } catch (Exception e) {}
                  }
                  WriteToLog(PID, DOWNLOAD_SERVER, ok ? SUCCESS : FAILED, status);
              }
      
              return sb.toString();
      Any suggestions?

      Thanks!