This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @WebFilter(urlPatterns = "/*", dispatcherTypes = {DispatcherType.FORWARD}) | |
| public class CustomerFilter implements Filter { | |
| @Override | |
| public void init(FilterConfig filterConfig) throws ServletException { } | |
| @Override | |
| public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { } | |
| @Override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <filter> | |
| <filter-name>CustomerFilter</filter-name> | |
| <filter-class>com.ea.Customerfilter</filter-class> | |
| </filter> | |
| <filter-mapping> | |
| <filter-name>CustomerFilter</filter-name> | |
| <url-pattern>/*</url-pattern> | |
| <dispatcher>REQUEST</dispatcher> | |
| <servlet-name>dispatcherServlet</servlet-name> | |
| </filter-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Configuration | |
| public class WebFilterConfiguration { | |
| @Bean | |
| public FilterRegistrationBean<CustomerFilter> customerFilter() { | |
| FilterRegistrationBean<CustomerFilter> customerFilter = new FilterRegistrationBean<>(); | |
| customerFilter.setFilter(new CustomerFilter()); | |
| customerFilter.addUrlPatterns("/customers/*"); | |
| customerFilter.setOrder(1); | |
| customerFilter.setDispatcherTypes(DispatcherType.REQUEST); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| public class ProductFilter implements Filter, Ordered { | |
| @Override | |
| public int getOrder() { | |
| return 0; | |
| } | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Order(1) | |
| @Component | |
| public class CustomerFilter implements Filter { | |
| ... | |
| } | |
| @Order(2) | |
| @Component | |
| public class ProductFilter implements Filter { | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| public class CustomerFilter implements Filter { | |
| ... | |
| } | |
| @Component | |
| public class ProductFilter implements Filter { | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CustomerFilter implements Filter { | |
| private static final List<String> EXCLUDE_URI_LIST = Arrays.asList("/product", "/order", "/user"); | |
| private static final Short INVALID_CUSTOMER_STATUS = Short.valueOf("-1"); | |
| @Override | |
| public void init(FilterConfig filterConfig) throws ServletException { } | |
| @Override | |
| public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @ExceptionHandler(Exception.class) | |
| @ResponseBody ResponseEntity<TaskApiError> exceptionHandler(Throwable exception) { | |
| ResponseEntity apiError; | |
| if(exception instanceof InvalidInputException) { | |
| apiError = generateErrorResponse(TaskApiErrorType.INVALID_INPUT_ERROR, HttpStatus.BAD_REQUEST, exception); | |
| } else if (exception instanceof RecordNotFoundException) { | |
| apiError = generateErrorResponse(TaskApiErrorType.RECORD_NOT_FOUND_ERROR, HttpStatus.NOT_FOUND, exception); | |
| } else if (exception instanceof IllegalArgumentException || exception instanceof ValidationException || exception instanceof SessionException) { | |
| apiError = generateErrorResponse(TaskApiErrorType.ILLEGAL_ARGUMENTS_ERROR, HttpStatus.NOT_ACCEPTABLE, exception); | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @PutMapping( "/tasks/{id}") | |
| public ResponseEntity<Task> updateTask(@PathVariable Long id, @RequestBody Task requestTask) { | |
| log.info("updating task with id " + id); | |
| if (StringUtils.isEmpty(requestTask.getDescription())) { | |
| throw new InvalidInputException("Description can not be empty"); | |
| } | |
| Optional<Task> optCurrentTask = taskService.findById(id); | |
| if (!optCurrentTask.isPresent()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @ControllerAdvice | |
| public class TaskApiExceptionHandler { | |
| private static Logger log = Logger.getLogger("TaskApiExceptionHandler"); | |
| @ExceptionHandler(InvalidInputException.class) | |
| @ResponseBody ResponseEntity<TaskApiError> invalidInputException(InvalidInputException exception) { | |
| return generateErrorResponse(TaskApiErrorType.INVALID_INPUT_ERROR, HttpStatus.BAD_REQUEST, exception); | |
| } |
NewerOlder