This article is the 17th day of FUJITSU Advent Calendar 2017.
In this article, we will introduce how to create a program that provides frontale player information using the REST API using Launcher, which is Fujitsu's MicroProfile implementation.
MicroProfile is a community that studies specifications for realizing enterprise microservices in Java. (http://microprofile.io) In this article, we will use the following four APIs defined in MicroProfile 1.1.
Since all the above four APIs are included in Launcher, no other library or development environment for Java EE is required.
Only the Config API of Frontale.java is explained.
Frontale.java
71 Config config = ConfigProvider.getConfig();
Get the Config object from the ConfigProvider. The actual property value is obtained through this Config object.
Frontale.java
77 url = config.getValue("frontale.url", String.class);
Pass the property name in the first argument of the getValue method and the type in the second argument. If the property value is not found, a NoSuchElementException is thrown.
There are various ways to specify the property, but this program uses the default property file and describes it as follows.
microprofile-config.properties
frontale.url = http://www.frontale.co.jp/profile/2017/number.html
% javac -classpath launcher-1.0.jar -d classes *.java
The class file and property file are put together in a jar as shown below.
% jar tf frontale.jar
META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/classes/
WEB-INF/classes/META-INF/
WEB-INF/classes/kzr/
WEB-INF/classes/kzr/frontale/
WEB-INF/classes/META-INF/microprofile-config.properties
WEB-INF/classes/kzr/frontale/Frontale$1.class
WEB-INF/classes/kzr/frontale/Frontale$Parser.class
WEB-INF/classes/kzr/frontale/Frontale$Parser2.class
WEB-INF/classes/kzr/frontale/Frontale.class
WEB-INF/classes/kzr/frontale/FrontaleApplication.class
WEB-INF/classes/kzr/frontale/FrontaleService.class
WEB-INF/classes/kzr/frontale/Player.class
Just run the following command. No prior installation is required except for the JDK.
% java -Djava.io.tmpdir=. -jar launcher-1.0.jar --deploy frontale.jar
--List of player numbers (http : // localhost: 8080 / list)
--Kenta Kano's information (http : // localhost: 8080/25)
"Microservices" was an overstatement, but as introduced here, MicroProfile makes it easy to create applications that run in lightweight containers.