@Test public void return400BadRequestOnBadRequestException() throws Exception { String message = "message"; when(httpServletRequest.getPathInfo()).thenThrow(new BadRequestException(message)); underTest.service(httpServletRequest, servletResponse); verify(servletResponse).sendError(SC_BAD_REQUEST, message); }
@Override protected void service(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws ServletException, IOException { String uri = httpRequest.getRequestURI(); if (httpRequest.getQueryString() != null) { uri = uri + "?" + httpRequest.getQueryString(); } if (log.isDebugEnabled()) { log.debug("Servicing: {} {} ({})", httpRequest.getMethod(), uri, httpRequest.getRequestURL()); } MDC.put(getClass().getName(), uri); try { doService(httpRequest, httpResponse); log.debug("Service completed"); } catch (BadRequestException e) { log.warn("Bad request. Reason: {}", e.getMessage()); send(null, HttpResponses.badRequest(e.getMessage()), httpResponse); } catch (Exception e) { if (!(e instanceof AuthorizationException)) { log.warn("Failure servicing: {} {}", httpRequest.getMethod(), uri, e); } Throwables.propagateIfPossible(e, ServletException.class, IOException.class); throw new ServletException(e); } finally { MDC.remove(getClass().getName()); } }
ViewServlet extends HttpServlet { @Override protected void service(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws ServletException, IOException { String uri = httpRequest.getRequestURI(); if (httpRequest.getQueryString() != null) { uri = uri + "?" + httpRequest.getQueryString(); } if (log.isDebugEnabled()) { log.debug("Servicing: {} {} ({})", httpRequest.getMethod(), uri, httpRequest.getRequestURL()); } MDC.put(getClass().getName(), uri); try { doService(httpRequest, httpResponse); log.debug("Service completed"); } catch (BadRequestException e) { log.warn("Bad request. Reason: {}", e.getMessage()); send(null, HttpResponses.badRequest(e.getMessage()), httpResponse); } catch (Exception e) { if (!(e instanceof AuthorizationException)) { log.warn("Failure servicing: {} {}", httpRequest.getMethod(), uri, e); } Throwables.propagateIfPossible(e, ServletException.class, IOException.class); throw new ServletException(e); } finally { MDC.remove(getClass().getName()); } } }
ViewServlet extends HttpServlet { @Override protected void service(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws ServletException, IOException { String uri = httpRequest.getRequestURI(); if (httpRequest.getQueryString() != null) { uri = uri + "?" + httpRequest.getQueryString(); } if (log.isDebugEnabled()) { log.debug("Servicing: {} {} ({})", httpRequest.getMethod(), uri, httpRequest.getRequestURL()); } MDC.put(getClass().getName(), uri); try { doService(httpRequest, httpResponse); log.debug("Service completed"); } catch (BadRequestException e) { log.warn("Bad request. Reason: {}", e.getMessage()); send(null, HttpResponses.badRequest(e.getMessage()), httpResponse); } catch (Exception e) { if (!(e instanceof AuthorizationException)) { log.warn("Failure servicing: {} {}", httpRequest.getMethod(), uri, e); } Throwables.propagateIfPossible(e, ServletException.class, IOException.class); throw new ServletException(e); } finally { MDC.remove(getClass().getName()); } } @Inject  ViewServlet(final RepositoryManager repositoryManager,
                     final HttpResponseSenderSelector httpResponseSenderSelector,
                     final DescriptionHelper descriptionHelper,
                     final DescriptionRenderer descriptionRenderer,
                     @Named("${nexus.repository.sandbox.enable:-true}") final boolean sandboxEnabled); }
ViewServlet extends HttpServlet { @Override protected void service(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws ServletException, IOException { String uri = httpRequest.getRequestURI(); if (httpRequest.getQueryString() != null) { uri = uri + "?" + httpRequest.getQueryString(); } if (log.isDebugEnabled()) { log.debug("Servicing: {} {} ({})", httpRequest.getMethod(), uri, httpRequest.getRequestURL()); } MDC.put(getClass().getName(), uri); try { doService(httpRequest, httpResponse); log.debug("Service completed"); } catch (BadRequestException e) { log.warn("Bad request. Reason: {}", e.getMessage()); send(null, HttpResponses.badRequest(e.getMessage()), httpResponse); } catch (Exception e) { if (!(e instanceof AuthorizationException)) { log.warn("Failure servicing: {} {}", httpRequest.getMethod(), uri, e); } Throwables.propagateIfPossible(e, ServletException.class, IOException.class); throw new ServletException(e); } finally { MDC.remove(getClass().getName()); } } @Inject  ViewServlet(final RepositoryManager repositoryManager,
                     final HttpResponseSenderSelector httpResponseSenderSelector,
                     final DescriptionHelper descriptionHelper,
                     final DescriptionRenderer descriptionRenderer,
                     @Named("${nexus.repository.sandbox.enable:-true}") final boolean sandboxEnabled); @Override void init(final ServletConfig config); @Override void destroy(); }
ViewServlet extends HttpServlet { @Override protected void service(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws ServletException, IOException { String uri = httpRequest.getRequestURI(); if (httpRequest.getQueryString() != null) { uri = uri + "?" + httpRequest.getQueryString(); } if (log.isDebugEnabled()) { log.debug("Servicing: {} {} ({})", httpRequest.getMethod(), uri, httpRequest.getRequestURL()); } MDC.put(getClass().getName(), uri); try { doService(httpRequest, httpResponse); log.debug("Service completed"); } catch (BadRequestException e) { log.warn("Bad request. Reason: {}", e.getMessage()); send(null, HttpResponses.badRequest(e.getMessage()), httpResponse); } catch (Exception e) { if (!(e instanceof AuthorizationException)) { log.warn("Failure servicing: {} {}", httpRequest.getMethod(), uri, e); } Throwables.propagateIfPossible(e, ServletException.class, IOException.class); throw new ServletException(e); } finally { MDC.remove(getClass().getName()); } } @Inject  ViewServlet(final RepositoryManager repositoryManager,
                     final HttpResponseSenderSelector httpResponseSenderSelector,
                     final DescriptionHelper descriptionHelper,
                     final DescriptionRenderer descriptionRenderer,
                     @Named("${nexus.repository.sandbox.enable:-true}") final boolean sandboxEnabled); @Override void init(final ServletConfig config); @Override void destroy();  }