Close Menu
Java HelpsJava Helps
    What's Hot

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022
    Facebook X (Twitter) Instagram
    Java HelpsJava Helps
    • Home
    • How To
      1. Install
      2. Run
      3. Configure
      4. View All

      How to Install MySQL with phpMyAdmin on Ubuntu?

      December 4, 2022

      Install The Latest IntelliJ IDEA on Linux

      November 28, 2022

      Install The Latest Apache Maven on Linux

      November 27, 2022

      Install The Latest Oracle JDK on Linux

      November 27, 2022

      Run NiFi Cluster in Docker with SSL Enabled

      December 6, 2022

      How to Run Apache NiFi Docker on Mac M1?

      December 1, 2022

      How to Run Apache NiFi on Docker?

      December 1, 2022

      Create A New Maven Project In IntelliJ IDEA

      November 29, 2022

      Things To Do After Installing IntelliJ IDEA

      December 20, 2022

      How to Set Proxy for IntelliJ IDEA?

      December 20, 2022

      How to Set Proxy for Maven?

      December 6, 2022

      How to Create a Fat JAR Using Maven?

      December 5, 2022

      Things To Do After Installing IntelliJ IDEA

      December 20, 2022

      How to Set Proxy for IntelliJ IDEA?

      December 20, 2022

      Manage GitHub Artifact Storage Quota

      December 6, 2022

      Run NiFi Cluster in Docker with SSL Enabled

      December 6, 2022
    • Hello World
      1. Framework
      2. Library
      3. View All

      JPA Hello World! using Hibernate and MySQL

      December 3, 2022

      Jersey 3.x – Hello World!

      December 2, 2022

      Microservices Framework for Java (MSF4J) – Hello World!

      December 1, 2022

      How to Parse PCAP files in Java?

      November 30, 2022

      JPA Hello World! using Hibernate and MySQL

      December 3, 2022

      Jersey 3.x – Hello World!

      December 2, 2022

      Microservices Framework for Java (MSF4J) – Hello World!

      December 1, 2022

      How to Parse PCAP files in Java?

      November 30, 2022
    • More
      • Privacy Policy
        • Java Helps
        • Android Apps
      • Contact US
      • About
    Facebook X (Twitter) Instagram
    Java HelpsJava Helps
    Home » Microservices Framework for Java (MSF4J) – Hello World!
    Hello World
    Hello World
    Framework

    Microservices Framework for Java (MSF4J) – Hello World!

    Gobinath LoganathanBy Gobinath LoganathanDecember 1, 2022Updated:December 4, 2022No Comments3 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest Email

    The sparking fame of the Spring Boot framework in the Java ecosystem dims the mighty but tiny microservice frameworks out there. There is no doubt that the Spring Boot is a well-known all-rounder. However, this article explains a lightweight microservice framework from the company named WSO2. As a former employee of WSO2, I can guarantee their expertise in different service-oriented solutions. The founder of WSO2: Sanjiva Weerawarana is a key contributor to Apache SOAP and Axis2 projects and his passion for web services also reflects on MSF4J.

    Requirements

    • Java Development Kit
    • IntelliJ Idea Community/Ultimate or Eclipse with Maven Support
    • Apache Maven (Not necessary if you are not going to build the project outside of the IDE)

    Create a New Hello World Project

    Step 1:
    Create a new Maven project in IntelliJ Idea with the group id: com.javahelps.helloworld and artifact id: msf4j-hello-world.

    Step 2:
    Add the following dependencies and repositories to the pom.xml file. Prior to Java 9, the MSF4J core jar itself was enough because until Java 8 some of the Java EE packages were part of Java SE. From Java 9, Java EE packages were stripped from the standard edition. Therefore the JAXB API binding dependency is required to run MSF4J if you are using Java 9 or later.

    <dependency>
    <groupId>org.wso2.msf4j</groupId>
    <artifactId>msf4j-core</artifactId>
    <version>${msf4j.version}</version>
    </dependency>

    <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>${jaxb.api.version}</version>
    </dependency>
    <repositories>
    <repository>
    <id>wso2.releases</id>
    <name>WSO2 Internal Repository</name>
    <url>https://maven.wso2.org/nexus/content/repositories/releases/</url>
    <releases>
    <enabled>true</enabled>
    <updatePolicy>daily</updatePolicy>
    <checksumPolicy>fail</checksumPolicy>
    </releases>
    </repository>

    <repository>
    <id>wso2-maven2-repository</id>
    <name>WSO2 Maven2 Repository</name>
    <url>https://dist.wso2.org/maven2</url>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    <releases>
    <enabled>true</enabled>
    <updatePolicy>never</updatePolicy>
    <checksumPolicy>fail</checksumPolicy>
    </releases>
    </repository>
    </repositories>

    After adding the dependencies, the pom.xml should look like this:

    Not all newer versions of libraries guarantee backward compatibility with previous versions. Therefore, I recommend using the same version of the library as in the following pom.xml for your first run. Once you get the code working, search for the artifact ids in the public Maven Repository and use the latest version of the dependencies in your production code. Please note that older versions may have unpatched vulnerabilities and make your code vulnerable to attacks. I will try my best to keep the articles up to date but it is impossible for me to keep track of all libraries used in Java Helps. If you find any breaking changes in newer versions, please comment below.

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.javahelps.helloworld</groupId>
    <artifactId>msf4j-hello-world</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <msf4j.version>2.8.7</msf4j.version>
    <jaxb.api.version>2.3.1</jaxb.api.version>
    </properties>

    <dependencies>
    <dependency>
    <groupId>org.wso2.msf4j</groupId>
    <artifactId>msf4j-core</artifactId>
    <version>${msf4j.version}</version>
    </dependency>

    <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>${jaxb.api.version}</version>
    </dependency>
    </dependencies>

    <!-- Use the WSO2 repositories -->
    <repositories>
    <repository>
    <id>wso2.releases</id>
    <name>WSO2 Internal Repository</name>
    <url>https://maven.wso2.org/nexus/content/repositories/releases/</url>
    <releases>
    <enabled>true</enabled>
    <updatePolicy>daily</updatePolicy>
    <checksumPolicy>fail</checksumPolicy>
    </releases>
    </repository>

    <repository>
    <id>wso2-maven2-repository</id>
    <name>WSO2 Maven2 Repository</name>
    <url>https://dist.wso2.org/maven2</url>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    <releases>
    <enabled>true</enabled>
    <updatePolicy>never</updatePolicy>
    <checksumPolicy>fail</checksumPolicy>
    </releases>
    </repository>
    </repositories>
    </project>
    pom.xml

    Implement an MSF4J Service

    Step 1:
    Create a new class named HelloService.java with the following code. I hope the code is self-explanatory.

    package com.javahelps.helloworld;

    import javax.ws.rs.*;

    @Path("/service")
    public class HelloService {

    @GET
    @Path("/")
    public String get() {
    System.out.println("GET invoked");
    return "Hello world!";
    }

    @POST
    @Path("/")
    public void post() {
    System.out.println("POST invoked");
    }

    @PUT
    @Path("/")
    public void put() {
    System.out.println("PUT invoked");
    }

    @DELETE
    @Path("/")
    public void delete() {
    System.out.println("DELETE invoked");
    }
    }

    Step 2:
    Create a MicroservicesRunner and deploy the HelloService in the main method of the Main class as shown below.

    package com.javahelps.helloworld;

    import org.wso2.msf4j.MicroservicesRunner;

    public class Main {
    public static void main(String[] args) {
    new MicroservicesRunner()
    .deploy(new HelloService())
    .start();
    }
    }

    Run the MSF4J Service

    After saving all the changes run the Main class from IntelliJ IDEA. By default, the web service will run on port 9090.

    Using the Postman or CURL, send an HTTP request to any of the endpoints defined in the HelloService class. The following CURL command sends an HTTP GET request to the service.

    curl http://localhost:9090/service

    I hope you find MSF4J simple enough and lightweight for your needs. Still, Spring Boot has its advantages due to the large community behind it and the unlimited list of features. For long-term projects, choosing a framework backed by a large community with frequent bug/security fixes is important. However, if you are looking for lightweight alternatives to Spring Boot for a valid reason, MSF4J is definitely something worth considering.

    You can download the complete source code of this project along with all the resources from our Git Hub repository.

    msf4j-hello-world

    If you find this article useful, please share your thoughts below. If you have any questions or issues with getting MSF4J working, you can ask your questions in the comments. Java Helps community will try our best to answer your questions.

    framework hello world java
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    What is Garbage Collection?

    December 7, 2022

    JPA Hello World! using Hibernate and MySQL

    December 3, 2022

    Jersey 3.x – Hello World!

    December 2, 2022

    How to Parse PCAP files in Java?

    November 30, 2022
    Don't Miss
    Configure

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    IntelliJ Idea: the famous IDE for JVM languages including Java, Scala, and Kotlin. If you…

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022

    Manage GitHub Artifact Storage Quota

    December 6, 2022
    Our Picks

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022

    Manage GitHub Artifact Storage Quota

    December 6, 2022
    About Us
    About Us

    Java Helps is the platform to share all about the Java ecosystem. All the sample code available on Java Helps articles are published under Apache 2.0 License. Readers are free to use them according to the Apache 2.0 License.

    "The world is my town; its people my kinsmen."
    -Kaṉiyan Pūngunṟanār

    Email Us: www.javahelps@gmail.com

    Our Picks

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022
    New Comments

      Type above and press Enter to search. Press Esc to cancel.

      Go to mobile version