/** * {@inheritDoc} * * Handle errors */ @Override public void onError(Throwable e) { try { FileLfsServlet.sendError(response, HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage()); context.complete(); in.close(); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } } }
/** * {@inheritDoc} * * Handle object downloads */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException { AnyLongObjectId obj = getObjectToTransfer(req, rsp); if (obj != null) { if (repository.getSize(obj) == -1) { sendError(rsp, HttpStatus.SC_NOT_FOUND, MessageFormat .format(LfsServerText.get().objectNotFound, obj.getName())); return; } AsyncContext context = req.startAsync(); context.setTimeout(timeout); rsp.getOutputStream() .setWriteListener(new ObjectDownloadListener(repository, context, rsp, obj)); } }
/** * {@inheritDoc} * * Handle object uploads */ @Override protected void doPut(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException { AnyLongObjectId id = getObjectToTransfer(req, rsp); if (id != null) { AsyncContext context = req.startAsync(); context.setTimeout(timeout); req.getInputStream().setReadListener(new ObjectUploadListener( repository, context, req, rsp, id)); } }
/** * Handles object downloads * * @param req * servlet request * @param rsp * servlet response * @throws ServletException * if a servlet-specific error occurs * @throws IOException * if an I/O error occurs */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException { AnyLongObjectId obj = getObjectToTransfer(req, rsp); if (obj != null) { if (repository.getSize(obj) == -1) { sendError(rsp, HttpStatus.SC_NOT_FOUND, MessageFormat .format(LfsServerText.get().objectNotFound, obj.getName())); return; } AsyncContext context = req.startAsync(); context.setTimeout(timeout); rsp.getOutputStream() .setWriteListener(new ObjectDownloadListener(repository, context, rsp, obj)); } }
/** * Handle object uploads * * @param req * servlet request * @param rsp * servlet response * @throws ServletException * if a servlet-specific error occurs * @throws IOException * if an I/O error occurs */ @Override protected void doPut(HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException { AnyLongObjectId id = getObjectToTransfer(req, rsp); if (id != null) { AsyncContext context = req.startAsync(); context.setTimeout(timeout); req.getInputStream().setReadListener(new ObjectUploadListener( repository, context, req, rsp, id)); } }
/** * Handle errors * * @param e * the cause */ @Override public void onError(Throwable e) { try { FileLfsServlet.sendError(response, HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage()); context.complete(); in.close(); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } } }
private AnyLongObjectId getObjectToTransfer(HttpServletRequest req, HttpServletResponse rsp) throws IOException { String info = req.getPathInfo(); int length = 1 + Constants.LONG_OBJECT_ID_STRING_LENGTH; if (info.length() != length) { sendError(rsp, HttpStatus.SC_UNPROCESSABLE_ENTITY, MessageFormat .format(LfsServerText.get().invalidPathInfo, info)); return null; } try { return LongObjectId.fromString(info.substring(1, length)); } catch (InvalidLongObjectIdException e) { sendError(rsp, HttpStatus.SC_UNPROCESSABLE_ENTITY, e.getMessage()); return null; } }
/** {@inheritDoc} */ @Override public void onError(Throwable e) { try { out.abort(); inChannel.close(); channel.close(); int status; if (e instanceof CorruptLongObjectException) { status = HttpStatus.SC_BAD_REQUEST; LOG.log(Level.WARNING, e.getMessage(), e); } else { status = HttpStatus.SC_INTERNAL_SERVER_ERROR; LOG.log(Level.SEVERE, e.getMessage(), e); } FileLfsServlet.sendError(response, status, e.getMessage()); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } } }
/** * @param e * the exception that caused the problem */ @Override public void onError(Throwable e) { try { out.abort(); inChannel.close(); channel.close(); int status; if (e instanceof CorruptLongObjectException) { status = HttpStatus.SC_BAD_REQUEST; LOG.log(Level.WARNING, e.getMessage(), e); } else { status = HttpStatus.SC_INTERNAL_SERVER_ERROR; LOG.log(Level.SEVERE, e.getMessage(), e); } FileLfsServlet.sendError(response, status, e.getMessage()); } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); } } }
/** * Retrieve object id from request * * @param req * servlet request * @param rsp * servlet response * @return object id, or <code>null</code> if the object id could not be * retrieved * @throws java.io.IOException * if an I/O error occurs * @since 4.6 */ protected AnyLongObjectId getObjectToTransfer(HttpServletRequest req, HttpServletResponse rsp) throws IOException { String info = req.getPathInfo(); int length = 1 + Constants.LONG_OBJECT_ID_STRING_LENGTH; if (info.length() != length) { sendError(rsp, HttpStatus.SC_UNPROCESSABLE_ENTITY, MessageFormat .format(LfsServerText.get().invalidPathInfo, info)); return null; } try { return LongObjectId.fromString(info.substring(1, length)); } catch (InvalidLongObjectIdException e) { sendError(rsp, HttpStatus.SC_UNPROCESSABLE_ENTITY, e.getMessage()); return null; } }