A Hello World Fabric application showcasing a sample Java service, pre-processor and post-processor.
This repo uses a Monorepo approach in order to version both the Fabric application and the source code for its Java dependencies in the same location.
.
├── fabric
│ └── HelloWorld
│ └── Apps
└── java
└── HelloWorld
├── pom.xml
└── src
The fabric/HelloWorld subdirectory stores the Fabric application as it would result from exporting and
extracting the Fabric application into a directory by the same name.
As this is just a "Hello World" example, the app itself is not very interesting. The intent of this project and repository is to show how to develop, test, version and use custom Java code in Fabric.
In the image below shows the service definition.
- The Fabric app has one single service of the Java Adapter type.
- The JAR generated from the Java source code in this repository has been uploaded and selected as part of the service definition.
In the image below shows the definition of one of the service operations:
- The class
com.acme.services.HelloWorldServicehas been selected as the supporting implementation of the service operation. Note that you should ideally implement each service in a different class. - The class
com.acme.pre.TimestampPreProcessorhas been selected as the pre-processor for the service operation. - The class
com.acme.pre.TimestampPostProcessorhas been selected as the post-processor for the service operation.
The java/HelloWorld subdirectory stores the source code for a Java project which implements a custom service
HelloWorldService, a pre-processor TimestampPreProcessor and a post-processor TimestampPostProcessor which
are in turn used by the Fabric application stored under fabric/HelloWorld. It includes:
A service with two operations sayHello and sayGoodbye, and sample code on how to test them.
A pre-processor which adds a timestamp parameter and a x-timestamp header to a service operation's invocation.
A post-processor which adds a timestamp parameter to the service operation's outputs.
In short, just run make. If you need more info, continue reading.
Notice that fabric/.gigignore makes sure that you don't push into source control any of the Zip or JAR files that
would result from exporting the app from the Fabric Console and decompressing it. This is meant to help enforce the
best practice that compressed files and binaries should not go into source control.
As a consequence, just compressing and importing the contents of fabric/HelloWorld will not result in a working
Fabric application. You will need to first build the Java dependencies and then add them to the Fabric app bundle before
importing it.
Steps:
- Build the Java project in the
java/HelloWorlddirectory. You can do this by stepping into it and runningmvn package. - Copy the resulting JAR file from the
java/HelloWorld/target/directory to thefabric/HelloWorld/Apps/_JARs/directory. - Compress the
fabric/HelloWorlddirectory in Zip format. - Import the resulting Zip file into the Fabric Console.
The end result just before step #3 should be that your _JARs subdirectory looks like this:
fabric/HelloWorld/Apps/_JARs/
├── HelloWorld-1.0-SNAPSHOT.jar
└── HelloWorld-1.0-SNAPSHOT.meta.json
You can do this by running the make file included with this repository. Just open the command line prompt into the root of the repository and run:
make
You will see the Maven and Zip output, and at the end you'll see this message.
Done!
Now import HelloWorld.zip into Fabric.
As the message states, you can now import HelloWorld.zip into the Fabric Console. Either manually through the UI, or by using the Fabric CLI.
About the Java dependencies under the java/HelloWorld subdirectory:
- The project was created with IntelliJ but you can import it into any other Java IDE of your choice —e.g. Eclipse, Netbeans, etc— to modify, test and build it there.
- The project uses Maven as a dependency manager. The POM file at
java/HelloWorld/pom.xmlis a good example to use for your own Java dependencies project if you need one. - The project uses TestNG as a test automation framework, and Mockito to
instantiate some of the input parameters that the services, pre-processors and post-processors would receive
from the Fabric server during runtime —i.e.:
com.konylabs.middleware.controller.DataControllerRequestandcom.konylabs.middleware.controller.DataControllerRequest.

