Quantcast
Channel: DevOps tips & tricks
Viewing all articles
Browse latest Browse all 181

Creating a RESTful web service using Java Microprofile

$
0
0
 Creating a RESTful web service using Java Microprofile - OpenLiberty guide

https://openliberty.io/guides/rest-intro.html?_ga=2.32933814.922244966.1570259159-606366657.1570259159


Install latest version of Maven  on Centos 7.6 ( sample failed with 3.0.5 default version)
https://www.tecmint.com/install-apache-maven-on-centos-7/

No implementation for org.codehaus.plexus.languages.java.jpms.LocationManager was bound.
  while locating org.apache.maven.plugin.surefire.SurefirePlugin

On Fedora 30 I get following error in Maven
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.wasdev.wlp.maven.plugins:liberty-maven-plugin:2.7:install-server (install-server) on project microprofile: Unable to resolve artifact: io.openliberty:openliberty-runtime:19.0.0.9: Could not transfer artifact io.openliberty:openliberty-runtime:zip:19.0.0.9 from/to central (https://repo.maven.apache.org/maven2): User-specified log class 'org.codehaus.mojo.pluginsupport.logging.DelegatingLog' cannot be found or is not useable. -> [Help 1]
Installing latest version of Maven removed error


Clone the tutorial  sample repo
https://github.com/eugenp/tutorials

Follow the tutorial article
https://www.baeldung.com/eclipse-microprofile

Change versions to latest in pom.xml - check versions at https://mvnrepository.com/artifact/io.openliberty/openliberty-runtime/

tail pom.xml 
    <properties>
        <app.name>library</app.name>
        <package.file>${project.build.directory}/${app.name}-service.jar</package.file>
        <packaging.type>runnable</packaging.type>
        <microprofile.version>1.2</microprofile.version>
        <liberty-maven-plugin.version>2.7</liberty-maven-plugin.version>
        <openliberty-runtime.version>19.0.0.9</openliberty-runtime.version>
    </properties>

Compile and start the service
mvn package
java -jar target/library-service.jar


microprofile]$ java -jar target/library-service.jar
Extracting files to /home/centos/wlpExtract/library-service_1453971251685/wlp
Successfully extracted all product files.
Launching defaultServer (Open Liberty 19.0.0.9/wlp-1.0.32.cl190920190905-0148) on OpenJDK 64-Bit Server VM, version 1.8.0_222-b10 (en_US)
[AUDIT   ] CWWKE0001I: The server defaultServer has been launched.
[AUDIT   ] CWWKZ0058I: Monitoring dropins for applications.
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://localhost:9080/
[AUDIT   ] CWWKZ0001I: Application microprofile-1.0-SNAPSHOT started in 1.746 seconds.
[AUDIT   ] CWWKF0012I: The server installed the following features: [cdi-1.2, jaxrs-2.0, jaxrsClient-2.0, jndi-1.0, json-1.0, jsonp-1.0, servlet-3.1].
[AUDIT   ] CWWKF0011I: The defaultServer server is ready to run a smarter planet. The defaultServer server started in 5.136 seconds.


Test the service



curl http://localhost:9080/library/books
[{"id":"0001-201910","isbn":"1","name":"Building Microservice With Eclipse MicroProfile","author":"baeldung","pages":"420"}]


Viewing all articles
Browse latest Browse all 181

Trending Articles