@Test public void testDoGetShouldSendErrorResponseWhenRequestParsingFailedByTheServletFileUpload() throws ServletException, IOException, FileUploadException { given(request.getMethod()).willReturn("POST"); given(servletFileUpload.parseRequest(request)).willThrow(new FileUploadException()); underTest.doGet(request, response); verify(response).setContentType("text/html"); verify(response).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); verify(printWriter).write(Matchers.anyString()); }
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); boolean isMultipartContent = ServletFileUpload.isMultipartContent(request); if (!isMultipartContent) { out.println("You are not trying to upload"); } else { try { List<FileItem> fields = servletFileUpload.parseRequest(request); String msg = multiPartFileParser.parseMultiPartFiles(fields); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, msg)); out.write(msg); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write("File uploading failed! cause: " + e.getMessage()); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, e.getMessage()), e); } } }
MultiPartFormUploadServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); boolean isMultipartContent = ServletFileUpload.isMultipartContent(request); if (!isMultipartContent) { out.println("You are not trying to upload"); } else { try { List<FileItem> fields = servletFileUpload.parseRequest(request); String msg = multiPartFileParser.parseMultiPartFiles(fields); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, msg)); out.write(msg); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write("File uploading failed! cause: " + e.getMessage()); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, e.getMessage()), e); } } } }
MultiPartFormUploadServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); boolean isMultipartContent = ServletFileUpload.isMultipartContent(request); if (!isMultipartContent) { out.println("You are not trying to upload"); } else { try { List<FileItem> fields = servletFileUpload.parseRequest(request); String msg = multiPartFileParser.parseMultiPartFiles(fields); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, msg)); out.write(msg); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write("File uploading failed! cause: " + e.getMessage()); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, e.getMessage()), e); } } } @Autowired  MultiPartFormUploadServlet(final ServletFileUploadFactory servletFileUploadFactory, final MultiPartFileParser multiPartFileParser,
                                      final UrlAccessLogMessageAssembler urlAccessLogMessageAssembler); }
MultiPartFormUploadServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); boolean isMultipartContent = ServletFileUpload.isMultipartContent(request); if (!isMultipartContent) { out.println("You are not trying to upload"); } else { try { List<FileItem> fields = servletFileUpload.parseRequest(request); String msg = multiPartFileParser.parseMultiPartFiles(fields); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, msg)); out.write(msg); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write("File uploading failed! cause: " + e.getMessage()); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, e.getMessage()), e); } } } @Autowired  MultiPartFormUploadServlet(final ServletFileUploadFactory servletFileUploadFactory, final MultiPartFileParser multiPartFileParser,
                                      final UrlAccessLogMessageAssembler urlAccessLogMessageAssembler);  }
MultiPartFormUploadServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); boolean isMultipartContent = ServletFileUpload.isMultipartContent(request); if (!isMultipartContent) { out.println("You are not trying to upload"); } else { try { List<FileItem> fields = servletFileUpload.parseRequest(request); String msg = multiPartFileParser.parseMultiPartFiles(fields); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, msg)); out.write(msg); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write("File uploading failed! cause: " + e.getMessage()); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, e.getMessage()), e); } } } @Autowired  MultiPartFormUploadServlet(final ServletFileUploadFactory servletFileUploadFactory, final MultiPartFileParser multiPartFileParser,
                                      final UrlAccessLogMessageAssembler urlAccessLogMessageAssembler);   }