LineBotServerInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (!(handler instanceof HandlerMethod)) { return true; } final HandlerMethod hm = (HandlerMethod) handler; final MethodParameter[] methodParameters = hm.getMethodParameters(); for (MethodParameter methodParameter : methodParameters) { if (methodParameter.getParameterAnnotation(LineBotMessages.class) == null) { continue; } try { final String signatureHeader = request.getHeader(WebhookParser.SIGNATURE_HEADER_NAME); final byte[] payload = StreamUtils.copyToByteArray(request.getInputStream()); final CallbackRequest callbackRequest = webhookParser.handle(signatureHeader, payload); LineBotServerArgumentProcessor.setValue(request, callbackRequest); return true; } catch (WebhookParseException e) { log.info("LINE Bot callback exception: {}", e.getMessage()); response.sendError(HttpStatus.BAD_REQUEST.value()); try (PrintWriter writer = response.getWriter()) { writer.println(e.getMessage()); } return false; } } return true; }  @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler); @Override void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView); @Override void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
                                Exception ex);  }
@Test public void preHandleStaticResourceTest() throws Exception { ResourceHttpRequestHandler handler = mock(ResourceHttpRequestHandler.class); boolean result = target.preHandle(request, response, handler); assertThat(result).isTrue(); }
@Test public void preHandleForNotBotMessageHandler() throws Exception { HandlerMethod handler = mock(HandlerMethod.class); when(handler.getMethodParameters()).thenReturn(new MethodParameter[] {}); boolean result = target.preHandle(request, response, handler); assertThat(result).isTrue(); }