I tried to implement a buggy web application in Kotlin

Overview

Introduced before Bug-filled web application ["EasyBuggy"](https://github.com/k-tamura/easybuggy/blob/master/README Reimplement the Spring Boot-based clone "EasyBuggy Boot" of .jp.md) in Kotlin. I saw it ("EasyBuggy Bootlin").

You can download it from this page and start it with the following command.

java -jar ROOT.war
: writing_hand_tone1: Java 8 or above is required to start. `java -jar ROOT.war --port = 9000` will start on port 9000.

If you add Java option as follows, you can output logs, debug, and monitor with JMX. It also limits maximum memory usage, making it more prone to problems such as OutOfMemoryError.

java -Xmx256m -XX:MaxPermSize=64m -XX:MaxDirectMemorySize=90m -XX:+UseSerialGC -Xloggc:logs/gc.log -XX:+PrintHeapAtGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=10M -XX:GCTimeLimit=15 -XX:GCHeapFreeLimit=50 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=logs/ -XX:ErrorFile=logs/hs_err_pid%p.log -agentlib:jdwp=transport=dt_socket,server=y,address=9009,suspend=n -Dderby.stream.error.file=logs/derby.log -Dderby.infolog.append=true -Dderby.language.logStatementText=true -Dderby.locks.deadlockTrace=true -Dderby.locks.monitor=true -Dderby.storage.rowLocking=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=7900 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -ea -jar ROOT.war

When the following message is displayed, the web application has been started.

2017-10-19 16:36:01.065  INFO 5304 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8081 (http)
2017-10-19 16:36:01.075  INFO 5304 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2017-10-19 16:36:01.242  INFO 5304 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-10-19 16:36:01.249  INFO 5304 --- [           main] o.t.e.Easybuggy4ktApplicationKt          : Started Easybuggy4ktApplicationKt in 37.355 seconds (JVM running for 38.916)

Go to http: // localhost: 8080 and you will see the main page.

demo_ebk_ja_startup.gif

It starts up a little slow (about 15 seconds. EasyBuggy starts up in 3 seconds ...)

Startup methods other than the above

You can also start it by git clone and gradle bootRun.

$ git clone https://github.com/k-tamura/easybuggy4kt
$ cd easybuggy4kt
$ gradle bootRun
`server.port = $ {port: 8080}` line in `src / main / resources / application.properties` to` server.port = 9000` Then it will start on port 9000.

You can also deploy ROOT.war in a Java container such as Tomcat 8.5 and it will work as well.

Use of this app

Similar to "Easy Buggy" and "Easy Buggy Boot", the purpose is to reproduce, analyze, and deepen understanding of various obstacles. The reason I reimplemented it in Kotlin was because I wanted to know the following:

――Is it possible to create vulnerabilities and resource leaks in apps implemented with Kotlin? --What is required to reimplement a Java-implemented app in Kotlin? --Does Kotlin improve readability by reimplementing Java-implemented apps?

demo

The following is a demo of observing a memory leak by accessing the page where the memory leak occurs many times.

demo_ebk_ja_memleak.gif

Differences in configuration

The main differences in the configurations of "EasyBuggy", "EasyBuggy Boot", and "EasyBuggy Bootlin" are as follows.

Difference EasyBuggy EasyBuggy Boot EasyBuggy Bootlin
language Java Java Kotlin
Base technology Servlet 3.0.1 Spring Boot 1.5.6 (Servlet 3.0.1) Spring Boot 1.5.7 (Servlet 3.0.1)
Presentation layer unused(Some JSP 2.2 + JSTL 1.2) Thymeleaf 2.1.5 (Some JSP 2.3 + JSTL 1.2) Thymeleaf 2.1.5 (Some JSP 2.3 + JSTL 1.2)
Servlet container Tomcat 7.0.37 Tomcat 8.5.16 Tomcat 8.5.20
DB client/server JDBC / Derby 10.8.3.0 Spring JDBC 4.3.9 / Derby 10.12.1.1 (For Java 7), Or 10.13.1.1 (For Java 8) Spring JDBC 4.3.11 / Derby 10.13.1.1
LDAP client/server Apache DS Client API 1.0.0 / Server 1.5.5 Spring LDAP 2.3.1 / unboundid-ldapsdk 3.2.1 Spring LDAP 2.3.1 / unboundid-ldapsdk 3.2.1
Email JavaMail 1.5.1 JavaMail 1.5.1 (Java Mail introduced by Spring Boot Mail 1.5.Override 6) JavaMail 1.5.1 (Java Mail introduced by Spring Boot Mail 1.5.Override 6)
Development tools None Spring Boot Developer Tools 1.5.6 Spring Boot Developer Tools 1.5.7
Build tool Maven Maven Gradle
Java Supports Java 6 and above Supports Java 7 and above Supports Java 8 and above

How to build

You can create an executable and deployable war file with the following command.

$ gradle clean build

Development method

For the development of EasyBuggy Bootlin, we use IntelliJ IDEA from JetBrains, which developed Kotlin. I chose IntelliJ over STS because it had useful features like converting Java programs to Kotlin programs. Thanks to IntelliJ, I was able to develop this app in a fairly short time.

To speed up development, it's a good idea to start EasyBuggy Bootlin with gradle bootRun while building continuously with gradle build --continuous. With this method, if you modify the source code, Spring Boot DevTools will automatically reload it to reflect the modification.

demo_ebk_ja_devtool.gif

Recommended Posts