Spring-Boot running jar file for 2nd time causing timeout issue

Viewed 371

Yes, you read it correct. I've done dozens of spring-boot micro service but never faced this issue.

I have configured spring security for secured resources. I do have normal non secured pages. I'm building jar using spring-boot-maven-plugin

  1. Created jar file using mvn package
  2. Pushed that file using scp to my remote server
  3. Started application using java -jar app.jar
  4. Everything works well. Just stopped the process
  5. Did some changes on external properties, started again using very same command
  6. Non secured pages are getting rendered.
  7. Secured page redirecting to /login and it never render the login page. Causing timeout for the page

Debug Logs

2019-01-02 20:41:02.698 DEBUG 27713 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/admin/login]
2019-01-02 20:41:02.706 DEBUG 27713 --- [nio-8081-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /login
2019-01-02 20:41:02.711 DEBUG 27713 --- [nio-8081-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView com.admin.SecuredPage.login(javax.servlet.http.HttpServletRequest,org.springframework.security.web.csrf.CsrfToken)]
2019-01-02 20:41:02.712 DEBUG 27713 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/admin/login] is: -1
2019-01-02 20:41:02.789 DEBUG 27713 --- [nio-8081-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, */*;q=0.8] based on Accept header types and producible media types [*/*])
2019-01-02 20:41:02.805 DEBUG 27713 --- [nio-8081-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.boot.web.servlet.view.MustacheView: name 'login'; URL [classpath:/templates/login.html]] based on requested media type 'text/html'
2019-01-02 20:41:02.807 DEBUG 27713 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.boot.web.servlet.view.MustacheView: name 'login'; URL [classpath:/templates/login.html]] in DispatcherServlet with name 'dispatcherServlet'

Spring security configuration

protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().antMatchers("/stylesheets/**").permitAll().and()
            .authorizeRequests().antMatchers("/register").permitAll().and()
            .authorizeRequests().antMatchers("/js/**").permitAll().and()
            .authorizeRequests().antMatchers("/images/**").permitAll().and()
            .authorizeRequests().antMatchers("/login").permitAll().anyRequest().authenticated().and()
            .formLogin().loginPage("/login").successHandler(successAuthHandler)
            .failureUrl("/login?error=401").permitAll().and()
            .logout().permitAll().and().csrf();
            http.sessionManagement().maximumSessions(1).expiredUrl("/login?error=ms").sessionRegistry(sessionRegistry());
        }

LOGIN method

 @RequestMapping(value = "/login")
    public ModelAndView login(HttpServletRequest req, CsrfToken csrfToken) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (!(auth instanceof AnonymousAuthenticationToken)) {
            return utilityComponent.getRedirectModelAndView("cats");
        }
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("login");

        CsrfToken csrf = (CsrfToken) req.getAttribute(CsrfToken.class.getName());
        modelAndView.addObject("_csrf", csrf);
        String errorParm = req.getParameter("error");
        System.out.println("I am tired");  
        return modelAndView;
    }

And it is printing I am tired without any issues.

VERSIONS

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
</parent>



<properties>
    <maven.compiler.source>9</maven.compiler.source>
    <maven.compiler.target>9</maven.compiler.target>
    <maven.test.skip>true</maven.test.skip>
</properties>

BUILD LOGS

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.admin:admin-app:jar:0.0.2
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] ----------< com.admin:admin-app >-----------
[INFO] Building admin-app 0.0.2
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ admin-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 102 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ admin-app ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ admin-app ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ admin-app ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ admin-app ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ admin-app ---
[INFO] Building jar: /home/pasu/eclipse-workspace/admin-app/target/admin-app-0.0.2.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.0.3.RELEASE:repackage (default) @ admin-app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.326 s
[INFO] Finished at: 2019-01-02T19:35:15-06:00
[INFO] ------------------------------------------------------------------------

Few application.yml

spring:
  profiles:
    active: dna
  http:
    multipart:
      max-file-size: 900KB
      max-request-size: 1000KB
  resources:
    cache:
      cachecontrol:
        max-age: 86400
        must-revalidate: true
        cache-private: true
server:
  port: 8080
  compression:
    enabled: true
    compression.mime-types: "text/html,image/png,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json"
    compression.min-response-size: 1024
    http2:
      enabled: true
  servlet:
    contextPath: /admin

Environment

Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-38-generic x86_64)
openjdk 10.0.2 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)

What am I missing.

0 Answers
Related