@@ -0,0 +1,3122 @@
+package com.rhcloud.analytics4github.config;%0A%0A%0Aimport com.rhcloud.analytics4github.util.GithubApiIterator;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.boot.web.servlet.FilterRegistrationBean;%0Aimport org.springframework.context.annotation.Bean;%0Aimport org.springframework.context.annotation.Configuration;%0A%0Aimport javax.servlet.*;%0Aimport javax.servlet.http.Cookie;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport java.io.IOException;%0A%0A%0A/**%0A * Created by ivan on 17.03.17.%0A */%0A@Configuration%0Apublic class SaveCoockiesFilter %7B%0A    private static Logger LOG = LoggerFactory.getLogger(SaveCoockiesFilter.class);%0A%0A    @Bean%0A    public FilterRegistrationBean registrationBean() %7B%0A        FilterRegistrationBean registrationBean = new FilterRegistrationBean();%0A        registrationBean.setFilter(this.requestsSaveCoockiesFilter());%0A        registrationBean.addUrlPatterns(%22/commits%22);%0A        registrationBean.addUrlPatterns(%22/stargazers%22);%0A        registrationBean.addUrlPatterns(%22/uniqueContributors%22);%0A        registrationBean.setOrder(1);%0A        return registrationBean;%0A    %7D%0A%0A    @Bean(name = %22requestsSaveCoockiesFilter%22)%0A    public Filter requestsSaveCoockiesFilter()%7B%0A        return new Filter() %7B%0A            @Override%0A            public void init(FilterConfig filterConfig) throws ServletException %7B%0A%0A            %7D%0A%0A            @Override%0A            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException %7B%0A                if (request instanceof HttpServletRequest)%7B%0A                    Cookie%5B%5D cookies = ((HttpServletRequest)request).getCookies();%0A                    if (cookies != null) %7B%0A                        boolean isCookiesExist = false;%0A                        for (Cookie cookie : cookies) %7B%0A                            if (%22freeTokens%22.equals(cookie.getName())) %7B%0A                                int c = Integer.parseInt(cookie.getValue());%0A                                cookie.setValue(String.valueOf(c-20));%0A                                System.out.println(c);%0A                                cookie.setMaxAge(24*60*60);%0A                                cookie.setPath(%22/%22);%0A                                ((HttpServletResponse)response).addCookie(cookie);%0A                                isCookiesExist = true;%0A                                System.out.println(%22This cookies exists%22);%0A                                break;%0A                            %7D%0A                        %7D%0A                        if (!isCookiesExist)%7B%0A                            Cookie newCookie = new Cookie(%22freeTokens%22, %22400%22);%0A                            newCookie.setMaxAge(24 * 60 * 60);%0A                            newCookie.setPath(%22/%22);%0A                            ((HttpServletResponse)response).addCookie(newCookie);%0A                        %7D%0A                    %7D%0A%0A                %7D%0A                chain.doFilter(request, response);%0A%0A            %7D%0A%0A            @Override%0A            public void destroy() %7B%0A%0A            %7D%0A        %7D;%0A    %7D%0A%0A%0A%0A%7D%0A

save cookies using filter