SlideShare a Scribd company logo
Creating RESTFul endpoints
with JAX-RS for a simple
microservice.
By Ken Finnigan
Save 42% off Enterprise Java Microservices
with code slfinnigan at manning.com
A simple microservice.
Let’s pretend that we’re developing a simple application and that the
application will utilize JAX-RS for the RESTFul microservice, with a UI
built with ReactJS.
The application includes a UI as a way to utilize the microservice in an
easier manner. Without a UI it would require issuing curl commands
to interact with it, and UIs are nicer to look at than commands in a
terminal!
So what are we developing? A simple application for managing
addresses.
Here is what our app’s UI might look like.
Application Use Cases.
We’re focusing on address management, so we don’t need to cover a
large range of use cases. Our address microservice only needs to focus
on the CRUD operations that a data object requires to create, read,
update, and delete instances of.
The UI will call the CRUD operations on the microservice for
maintaining addresses. The microservice RESTFul endpoints could be
called from any client, but we will show them operating with our UI.
Address UI page flow.
Architecture of the Application.
Let’s take a moment and ignore microservices – the architecture for our
application would probably look something like:
Architecture of the Application.
At the Presentation Layer we use ReactJS for the UI. The API Layer
contains the RESTFul endpoints utilizing JAX-RS for employee and
address. CDI services for employee and address represent our Business
Layer, which is called by the API Layer. Finally there are JPA entities of
employee and address in our Data Layer that interact with the physical
database. The Business Layer is responsible for interacting with the
Data Layer to persist record updates.
Whether the API Layer and Business Layer would be separate or not
depends on preference, as they could be handled within a single layer.
Typically all these layers would be packaged within a single WAR for
deployment to an application server.
Architecture of the Application.
How does the architecture change when we shift to constructing a
microservice?
Our server side layers are encompassed in a single Microservice. Our UI
then sits in its own WAR, to package and deploy the UI to a separate
runtime.
As we’ve split our UI and services into separate runtimes, we need to
add support for cross origin resource sharing (CORS). If we don’t, the
browser will prevent the UI from making an HTTP request to the
microservice. To do this our microservice needs a filter:
Creating RESTFul endpoints with JAX-RS.
To keep the microservice simple we will focus on the RESTFul endpoint
--the API Layer-- and ignore the development of the additional layers.
Any Enterprise Java developer would then be able to take the
microservice and extend it to utilize CDI and JPA if they wanted.
Developing the AddressController.
Our AddressController will focus on making the CRUD style
operations for address data available from RESTFul endpoints. It
specifies that the RESTFul @Path for the controller is /address. We
then define a counter as a unique identifier, and a Map to store the
addresses in memory. Last, we populate an internal Map called
addresses with some initial data during construction of the instance.
As we’re storing data for addresses in our controller, we need to make
the class a singleton within JAX-RS. By default, all JAX-RS resource
instances are only active on a per-request basis. If we don’t change
that, then every request will see the same initial data state every time,
and the UI would never show different data no matter how many new
addresses were added or updated.
Developing the AddressController.
We need to define a JAX-RS
application that can indicate
to the implementation which
RESTFul endpoints we want to
be singletons:
Viewing all addresses.
Now it’s time to develop the RESTFul endpoints we need for CRUD of
our addresses.
Deleting an address.
Once we have an address, we need the ability to delete an old one that
isn’t used. For that we need to add a RESTFul endpoint for deleting an
address from the database.
Adding an address.
Here we have a RESTFul
endpoint to add a new
address into our database
and provide it with a
unique identifier.
Running the microservice.
Although we’ve indicated that our RESTFul endpoint is an Address
microservice, there’s actually nothing in the code we’ve developed that
prevents it from being built as a WAR and deployed to an application
server. As we’re only dealing with a UI communicating with a single
microservice, there isn’t any difference between that and existing
Enterprise Java development with WARs. The upside to the similarity is
that it makes it easier to migrate existing Enterprise Java code into a
Microservice if no code changes are required for a microservice
producer.
To give more of a microservice feel for our example, we will package it
as an uber jar with WildFly Swarm.
Running the microservice.
WildFly Swarm offers an alternative approach to packaging your
applications utilizing WildFly instead of a full Java EE Application Server.
It allows us to choose the parts we need from WildFly and package
them into an uber jar that can be run from the command line.
To do that we need to add the following plugin to our pom.xml:
Latest version of WildFly Swarm.
Specify a port offset of 1 so
our microservice will start on
port 8081.
Running the microservice.
That’s all we need to do to provide a way to run the microservice from
the directory, as well as package it as an uber jar.
So how and what do we run?
There are two pieces that need to be run, one for the UI and one for
the microservice. If you wanted to execute some tests against the
RESTFul endpoints directly, without using the UI, then you only need to
start the microservice.
Let’s see what we need to do to start our microservice:
Running the microservice.
Open a terminal, or command window, and navigate to the /chapter2/jaxrs
directory of the book example code (https://github.com/kenfinnigan/ejm-
samples). From that directory run:
This will start the microservice containing our RESTFul endpoints for
address crud. Once the log shows that the microservice is deployed you
can go to a browser and open it to:
Your browser will load the initial address
data and display it in JSON format. Now
we know the microservice is running,
let’s run the UI.
Running the microservice.
Now let’s start the UI.
Open a terminal and navigate to the /chapter2/ui directory of the book
example code. From that directory run:
This will start a web server with the UI code only. Once the log shows
that it’s deployed you can go to a browser and open it to:
Your browser will load the UI containing some sample address data.
Voila! That’s all for now.
We hope you found this presentation informative. Don’t forget to
save 42% off Enterprise Java Microservices with code slfinnigan at
manning.com.
Also see:

More Related Content

What's hot

Mule esb stripe
Mule esb stripeMule esb stripe
Mule esb stripe
D.Rajesh Kumar
 
Composite Enterprise Application Development with the WSO2 Developer Studio
Composite Enterprise Application Development with the WSO2 Developer StudioComposite Enterprise Application Development with the WSO2 Developer Studio
Composite Enterprise Application Development with the WSO2 Developer StudioWSO2
 
IoT in salsa serverless
IoT in salsa serverlessIoT in salsa serverless
IoT in salsa serverless
Massimo Bonanni
 
Integration with dropbox using mule esb
Integration with dropbox using mule esbIntegration with dropbox using mule esb
Integration with dropbox using mule esb
sivachandra mandalapu
 
Ng-init
Ng-init Ng-init
Ng-init
Hamdi Hmidi
 
Ng-init
Ng-init Ng-init
Ng-init
Hamdi Hmidi
 
Aws sqs component in mule
Aws sqs  component in muleAws sqs  component in mule
Aws sqs component in mule
Ramakrishna kapa
 
Mule saas enablement
Mule  saas enablementMule  saas enablement
Mule saas enablement
himajareddys
 
Muleesb
MuleesbMuleesb
Mule ESB
Mule ESBMule ESB
Mule ESBniravn
 
Mule connectors
Mule  connectorsMule  connectors
Mule connectors
charan teja R
 
CBDW2014 - ColdBox RESTFul Services
CBDW2014 - ColdBox RESTFul ServicesCBDW2014 - ColdBox RESTFul Services
CBDW2014 - ColdBox RESTFul Services
Ortus Solutions, Corp
 
Mule google connectors
Mule  google connectorsMule  google connectors
Mule google connectors
D.Rajesh Kumar
 
Mulethenewtechnology 12549172699166-phpapp03-160421133841
Mulethenewtechnology 12549172699166-phpapp03-160421133841Mulethenewtechnology 12549172699166-phpapp03-160421133841
Mulethenewtechnology 12549172699166-phpapp03-160421133841
ppts123456
 
(DEV304) What’s New in the AWS SDK for .NET | AWS re:Invent 2014
(DEV304) What’s New in the AWS SDK for .NET | AWS re:Invent 2014(DEV304) What’s New in the AWS SDK for .NET | AWS re:Invent 2014
(DEV304) What’s New in the AWS SDK for .NET | AWS re:Invent 2014
Amazon Web Services
 
Deployment Automation with Microservices
Deployment Automation with MicroservicesDeployment Automation with Microservices
Deployment Automation with Microservices
Ganesh Ghag
 
Build an API the right way
Build an API the right wayBuild an API the right way
Build an API the right way
Software Guru
 
Lab - AWS Cross Account Access
Lab - AWS Cross Account AccessLab - AWS Cross Account Access
Lab - AWS Cross Account Access
Albert Suwandhi
 
Custom connector development using mule DevKit
Custom connector development using mule DevKitCustom connector development using mule DevKit
Custom connector development using mule DevKit
Ramakrishna Narkedamilli
 

What's hot (19)

Mule esb stripe
Mule esb stripeMule esb stripe
Mule esb stripe
 
Composite Enterprise Application Development with the WSO2 Developer Studio
Composite Enterprise Application Development with the WSO2 Developer StudioComposite Enterprise Application Development with the WSO2 Developer Studio
Composite Enterprise Application Development with the WSO2 Developer Studio
 
IoT in salsa serverless
IoT in salsa serverlessIoT in salsa serverless
IoT in salsa serverless
 
Integration with dropbox using mule esb
Integration with dropbox using mule esbIntegration with dropbox using mule esb
Integration with dropbox using mule esb
 
Ng-init
Ng-init Ng-init
Ng-init
 
Ng-init
Ng-init Ng-init
Ng-init
 
Aws sqs component in mule
Aws sqs  component in muleAws sqs  component in mule
Aws sqs component in mule
 
Mule saas enablement
Mule  saas enablementMule  saas enablement
Mule saas enablement
 
Muleesb
MuleesbMuleesb
Muleesb
 
Mule ESB
Mule ESBMule ESB
Mule ESB
 
Mule connectors
Mule  connectorsMule  connectors
Mule connectors
 
CBDW2014 - ColdBox RESTFul Services
CBDW2014 - ColdBox RESTFul ServicesCBDW2014 - ColdBox RESTFul Services
CBDW2014 - ColdBox RESTFul Services
 
Mule google connectors
Mule  google connectorsMule  google connectors
Mule google connectors
 
Mulethenewtechnology 12549172699166-phpapp03-160421133841
Mulethenewtechnology 12549172699166-phpapp03-160421133841Mulethenewtechnology 12549172699166-phpapp03-160421133841
Mulethenewtechnology 12549172699166-phpapp03-160421133841
 
(DEV304) What’s New in the AWS SDK for .NET | AWS re:Invent 2014
(DEV304) What’s New in the AWS SDK for .NET | AWS re:Invent 2014(DEV304) What’s New in the AWS SDK for .NET | AWS re:Invent 2014
(DEV304) What’s New in the AWS SDK for .NET | AWS re:Invent 2014
 
Deployment Automation with Microservices
Deployment Automation with MicroservicesDeployment Automation with Microservices
Deployment Automation with Microservices
 
Build an API the right way
Build an API the right wayBuild an API the right way
Build an API the right way
 
Lab - AWS Cross Account Access
Lab - AWS Cross Account AccessLab - AWS Cross Account Access
Lab - AWS Cross Account Access
 
Custom connector development using mule DevKit
Custom connector development using mule DevKitCustom connector development using mule DevKit
Custom connector development using mule DevKit
 

Similar to Enterprise Java Microservices : creating and managing large-scale Java applications

Microservices
MicroservicesMicroservices
Microservices
Ramesh (@Mavuluri)
 
Spring interview questions
Spring interview questionsSpring interview questions
Spring interview questions
SkillPracticalEdTech
 
Spring learning path
Spring learning pathSpring learning path
Spring learning path
SkillPracticalEdTech
 
Service Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJSService Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJS
Andolasoft Inc
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
Aishura Aishu
 
Spring diy projects
Spring diy projectsSpring diy projects
Spring diy projects
SkillPracticalEdTech
 
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Atharva Jawalkar
 
Microservice architecture
Microservice architectureMicroservice architecture
Microservice architecture
Touraj Ebrahimi
 
Rest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookRest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbook
Katy Slemon
 
REST full API Design
REST full API DesignREST full API Design
REST full API Design
Christian Guenther
 
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdfSchema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
seo18
 
Osbsoa1
Osbsoa1Osbsoa1
Osbsoa1
xavier john
 
locize tech stack
locize tech stacklocize tech stack
locize tech stack
Adriano Raiano
 
Latest Web development technologies 2021
 Latest Web development technologies 2021 Latest Web development technologies 2021
Latest Web development technologies 2021
SWATHYSMOHAN
 
When to use serverless computing.pdf
When to use serverless computing.pdfWhen to use serverless computing.pdf
When to use serverless computing.pdf
SGBSeo
 
6. The grid-COMPUTING OGSA and WSRF
6. The grid-COMPUTING OGSA and WSRF6. The grid-COMPUTING OGSA and WSRF
6. The grid-COMPUTING OGSA and WSRF
Dr Sandeep Kumar Poonia
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
Bluegrass Digital
 
Node.js Microservices Building Scalable and Reliable Applications.pdf
Node.js Microservices Building Scalable and Reliable Applications.pdfNode.js Microservices Building Scalable and Reliable Applications.pdf
Node.js Microservices Building Scalable and Reliable Applications.pdf
Sufalam Technologies
 
J2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBCJ2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBC
ChaithraCSHirematt
 

Similar to Enterprise Java Microservices : creating and managing large-scale Java applications (20)

Microservices
MicroservicesMicroservices
Microservices
 
Spring interview questions
Spring interview questionsSpring interview questions
Spring interview questions
 
Spring learning path
Spring learning pathSpring learning path
Spring learning path
 
Service Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJSService Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJS
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
 
Spring diy projects
Spring diy projectsSpring diy projects
Spring diy projects
 
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
 
Microservice architecture
Microservice architectureMicroservice architecture
Microservice architecture
 
Rest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookRest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbook
 
REST full API Design
REST full API DesignREST full API Design
REST full API Design
 
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdfSchema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
Schema-based multi-tenant architecture using Quarkus & Hibernate-ORM.pdf
 
Osbsoa1
Osbsoa1Osbsoa1
Osbsoa1
 
locize tech stack
locize tech stacklocize tech stack
locize tech stack
 
Latest Web development technologies 2021
 Latest Web development technologies 2021 Latest Web development technologies 2021
Latest Web development technologies 2021
 
When to use serverless computing.pdf
When to use serverless computing.pdfWhen to use serverless computing.pdf
When to use serverless computing.pdf
 
6. The grid-COMPUTING OGSA and WSRF
6. The grid-COMPUTING OGSA and WSRF6. The grid-COMPUTING OGSA and WSRF
6. The grid-COMPUTING OGSA and WSRF
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
 
Node.js Microservices Building Scalable and Reliable Applications.pdf
Node.js Microservices Building Scalable and Reliable Applications.pdfNode.js Microservices Building Scalable and Reliable Applications.pdf
Node.js Microservices Building Scalable and Reliable Applications.pdf
 
Single Page Application
Single Page ApplicationSingle Page Application
Single Page Application
 
J2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBCJ2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBC
 

More from Manning Publications

Privacy-Preserving Machine Learning: secure user data without sacrificing mod...
Privacy-Preserving Machine Learning: secure user data without sacrificing mod...Privacy-Preserving Machine Learning: secure user data without sacrificing mod...
Privacy-Preserving Machine Learning: secure user data without sacrificing mod...
Manning Publications
 
Inside Deep Learning: theory and practice of modern deep learning
Inside Deep Learning: theory and practice of modern deep learningInside Deep Learning: theory and practice of modern deep learning
Inside Deep Learning: theory and practice of modern deep learning
Manning Publications
 
Data-Oriented Programming: making data a first-class citizen
Data-Oriented Programming: making data a first-class citizenData-Oriented Programming: making data a first-class citizen
Data-Oriented Programming: making data a first-class citizen
Manning Publications
 
Automated Machine Learning in Action
Automated Machine Learning in ActionAutomated Machine Learning in Action
Automated Machine Learning in Action
Manning Publications
 
The Programmer's Brain: improve the way you learn and think about code
The Programmer's Brain: improve the way you learn and think about codeThe Programmer's Brain: improve the way you learn and think about code
The Programmer's Brain: improve the way you learn and think about code
Manning Publications
 
Pipeline as Code: building a great deployment pipeline
Pipeline as Code: building a great deployment pipelinePipeline as Code: building a great deployment pipeline
Pipeline as Code: building a great deployment pipeline
Manning Publications
 
Tuning Up: keep your systems running smoothly
Tuning Up: keep your systems running smoothlyTuning Up: keep your systems running smoothly
Tuning Up: keep your systems running smoothly
Manning Publications
 
Kubernetes Native Microservices with Quarkus and MicroProfile
Kubernetes Native Microservices with Quarkus and MicroProfileKubernetes Native Microservices with Quarkus and MicroProfile
Kubernetes Native Microservices with Quarkus and MicroProfile
Manning Publications
 
Cloud Native Machine Learning
Cloud Native Machine Learning Cloud Native Machine Learning
Cloud Native Machine Learning
Manning Publications
 
Spring in Action, Sixth Edition
Spring in Action, Sixth EditionSpring in Action, Sixth Edition
Spring in Action, Sixth Edition
Manning Publications
 
Crafting interactive troubleshooting guides and team documentation for your K...
Crafting interactive troubleshooting guides and team documentation for your K...Crafting interactive troubleshooting guides and team documentation for your K...
Crafting interactive troubleshooting guides and team documentation for your K...
Manning Publications
 
Entity Framework Core in Action, Second Edtion
Entity Framework Core in Action, Second EdtionEntity Framework Core in Action, Second Edtion
Entity Framework Core in Action, Second Edtion
Manning Publications
 
Code like a Pro in C#
Code like a Pro in C#Code like a Pro in C#
Code like a Pro in C#
Manning Publications
 
Microservices in .NET Core, Second Edition
Microservices in .NET Core, Second EditionMicroservices in .NET Core, Second Edition
Microservices in .NET Core, Second Edition
Manning Publications
 
Kubernetes in Action, Second Edition
Kubernetes in Action, Second EditionKubernetes in Action, Second Edition
Kubernetes in Action, Second Edition
Manning Publications
 
Core Kubernetes
Core KubernetesCore Kubernetes
Core Kubernetes
Manning Publications
 
Machine Learning Bookcamp
Machine Learning BookcampMachine Learning Bookcamp
Machine Learning Bookcamp
Manning Publications
 
Machine Learning with TensorFlow, Second Edition
Machine Learning with TensorFlow, Second EditionMachine Learning with TensorFlow, Second Edition
Machine Learning with TensorFlow, Second Edition
Manning Publications
 
Spring Security in Action
Spring Security in ActionSpring Security in Action
Spring Security in Action
Manning Publications
 
Spring Microservices in Action, Second Edition
Spring Microservices in Action, Second EditionSpring Microservices in Action, Second Edition
Spring Microservices in Action, Second Edition
Manning Publications
 

More from Manning Publications (20)

Privacy-Preserving Machine Learning: secure user data without sacrificing mod...
Privacy-Preserving Machine Learning: secure user data without sacrificing mod...Privacy-Preserving Machine Learning: secure user data without sacrificing mod...
Privacy-Preserving Machine Learning: secure user data without sacrificing mod...
 
Inside Deep Learning: theory and practice of modern deep learning
Inside Deep Learning: theory and practice of modern deep learningInside Deep Learning: theory and practice of modern deep learning
Inside Deep Learning: theory and practice of modern deep learning
 
Data-Oriented Programming: making data a first-class citizen
Data-Oriented Programming: making data a first-class citizenData-Oriented Programming: making data a first-class citizen
Data-Oriented Programming: making data a first-class citizen
 
Automated Machine Learning in Action
Automated Machine Learning in ActionAutomated Machine Learning in Action
Automated Machine Learning in Action
 
The Programmer's Brain: improve the way you learn and think about code
The Programmer's Brain: improve the way you learn and think about codeThe Programmer's Brain: improve the way you learn and think about code
The Programmer's Brain: improve the way you learn and think about code
 
Pipeline as Code: building a great deployment pipeline
Pipeline as Code: building a great deployment pipelinePipeline as Code: building a great deployment pipeline
Pipeline as Code: building a great deployment pipeline
 
Tuning Up: keep your systems running smoothly
Tuning Up: keep your systems running smoothlyTuning Up: keep your systems running smoothly
Tuning Up: keep your systems running smoothly
 
Kubernetes Native Microservices with Quarkus and MicroProfile
Kubernetes Native Microservices with Quarkus and MicroProfileKubernetes Native Microservices with Quarkus and MicroProfile
Kubernetes Native Microservices with Quarkus and MicroProfile
 
Cloud Native Machine Learning
Cloud Native Machine Learning Cloud Native Machine Learning
Cloud Native Machine Learning
 
Spring in Action, Sixth Edition
Spring in Action, Sixth EditionSpring in Action, Sixth Edition
Spring in Action, Sixth Edition
 
Crafting interactive troubleshooting guides and team documentation for your K...
Crafting interactive troubleshooting guides and team documentation for your K...Crafting interactive troubleshooting guides and team documentation for your K...
Crafting interactive troubleshooting guides and team documentation for your K...
 
Entity Framework Core in Action, Second Edtion
Entity Framework Core in Action, Second EdtionEntity Framework Core in Action, Second Edtion
Entity Framework Core in Action, Second Edtion
 
Code like a Pro in C#
Code like a Pro in C#Code like a Pro in C#
Code like a Pro in C#
 
Microservices in .NET Core, Second Edition
Microservices in .NET Core, Second EditionMicroservices in .NET Core, Second Edition
Microservices in .NET Core, Second Edition
 
Kubernetes in Action, Second Edition
Kubernetes in Action, Second EditionKubernetes in Action, Second Edition
Kubernetes in Action, Second Edition
 
Core Kubernetes
Core KubernetesCore Kubernetes
Core Kubernetes
 
Machine Learning Bookcamp
Machine Learning BookcampMachine Learning Bookcamp
Machine Learning Bookcamp
 
Machine Learning with TensorFlow, Second Edition
Machine Learning with TensorFlow, Second EditionMachine Learning with TensorFlow, Second Edition
Machine Learning with TensorFlow, Second Edition
 
Spring Security in Action
Spring Security in ActionSpring Security in Action
Spring Security in Action
 
Spring Microservices in Action, Second Edition
Spring Microservices in Action, Second EditionSpring Microservices in Action, Second Edition
Spring Microservices in Action, Second Edition
 

Recently uploaded

A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 

Recently uploaded (20)

A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 

Enterprise Java Microservices : creating and managing large-scale Java applications

  • 1. Creating RESTFul endpoints with JAX-RS for a simple microservice. By Ken Finnigan Save 42% off Enterprise Java Microservices with code slfinnigan at manning.com
  • 2. A simple microservice. Let’s pretend that we’re developing a simple application and that the application will utilize JAX-RS for the RESTFul microservice, with a UI built with ReactJS. The application includes a UI as a way to utilize the microservice in an easier manner. Without a UI it would require issuing curl commands to interact with it, and UIs are nicer to look at than commands in a terminal! So what are we developing? A simple application for managing addresses.
  • 3. Here is what our app’s UI might look like.
  • 4. Application Use Cases. We’re focusing on address management, so we don’t need to cover a large range of use cases. Our address microservice only needs to focus on the CRUD operations that a data object requires to create, read, update, and delete instances of. The UI will call the CRUD operations on the microservice for maintaining addresses. The microservice RESTFul endpoints could be called from any client, but we will show them operating with our UI.
  • 6. Architecture of the Application. Let’s take a moment and ignore microservices – the architecture for our application would probably look something like:
  • 7. Architecture of the Application. At the Presentation Layer we use ReactJS for the UI. The API Layer contains the RESTFul endpoints utilizing JAX-RS for employee and address. CDI services for employee and address represent our Business Layer, which is called by the API Layer. Finally there are JPA entities of employee and address in our Data Layer that interact with the physical database. The Business Layer is responsible for interacting with the Data Layer to persist record updates. Whether the API Layer and Business Layer would be separate or not depends on preference, as they could be handled within a single layer. Typically all these layers would be packaged within a single WAR for deployment to an application server.
  • 8. Architecture of the Application. How does the architecture change when we shift to constructing a microservice? Our server side layers are encompassed in a single Microservice. Our UI then sits in its own WAR, to package and deploy the UI to a separate runtime.
  • 9. As we’ve split our UI and services into separate runtimes, we need to add support for cross origin resource sharing (CORS). If we don’t, the browser will prevent the UI from making an HTTP request to the microservice. To do this our microservice needs a filter:
  • 10. Creating RESTFul endpoints with JAX-RS. To keep the microservice simple we will focus on the RESTFul endpoint --the API Layer-- and ignore the development of the additional layers. Any Enterprise Java developer would then be able to take the microservice and extend it to utilize CDI and JPA if they wanted.
  • 11. Developing the AddressController. Our AddressController will focus on making the CRUD style operations for address data available from RESTFul endpoints. It specifies that the RESTFul @Path for the controller is /address. We then define a counter as a unique identifier, and a Map to store the addresses in memory. Last, we populate an internal Map called addresses with some initial data during construction of the instance. As we’re storing data for addresses in our controller, we need to make the class a singleton within JAX-RS. By default, all JAX-RS resource instances are only active on a per-request basis. If we don’t change that, then every request will see the same initial data state every time, and the UI would never show different data no matter how many new addresses were added or updated.
  • 12. Developing the AddressController. We need to define a JAX-RS application that can indicate to the implementation which RESTFul endpoints we want to be singletons:
  • 13. Viewing all addresses. Now it’s time to develop the RESTFul endpoints we need for CRUD of our addresses.
  • 14. Deleting an address. Once we have an address, we need the ability to delete an old one that isn’t used. For that we need to add a RESTFul endpoint for deleting an address from the database.
  • 15. Adding an address. Here we have a RESTFul endpoint to add a new address into our database and provide it with a unique identifier.
  • 16. Running the microservice. Although we’ve indicated that our RESTFul endpoint is an Address microservice, there’s actually nothing in the code we’ve developed that prevents it from being built as a WAR and deployed to an application server. As we’re only dealing with a UI communicating with a single microservice, there isn’t any difference between that and existing Enterprise Java development with WARs. The upside to the similarity is that it makes it easier to migrate existing Enterprise Java code into a Microservice if no code changes are required for a microservice producer. To give more of a microservice feel for our example, we will package it as an uber jar with WildFly Swarm.
  • 17. Running the microservice. WildFly Swarm offers an alternative approach to packaging your applications utilizing WildFly instead of a full Java EE Application Server. It allows us to choose the parts we need from WildFly and package them into an uber jar that can be run from the command line. To do that we need to add the following plugin to our pom.xml: Latest version of WildFly Swarm. Specify a port offset of 1 so our microservice will start on port 8081.
  • 18. Running the microservice. That’s all we need to do to provide a way to run the microservice from the directory, as well as package it as an uber jar. So how and what do we run? There are two pieces that need to be run, one for the UI and one for the microservice. If you wanted to execute some tests against the RESTFul endpoints directly, without using the UI, then you only need to start the microservice. Let’s see what we need to do to start our microservice:
  • 19. Running the microservice. Open a terminal, or command window, and navigate to the /chapter2/jaxrs directory of the book example code (https://github.com/kenfinnigan/ejm- samples). From that directory run: This will start the microservice containing our RESTFul endpoints for address crud. Once the log shows that the microservice is deployed you can go to a browser and open it to: Your browser will load the initial address data and display it in JSON format. Now we know the microservice is running, let’s run the UI.
  • 20. Running the microservice. Now let’s start the UI. Open a terminal and navigate to the /chapter2/ui directory of the book example code. From that directory run: This will start a web server with the UI code only. Once the log shows that it’s deployed you can go to a browser and open it to: Your browser will load the UI containing some sample address data.
  • 21. Voila! That’s all for now. We hope you found this presentation informative. Don’t forget to save 42% off Enterprise Java Microservices with code slfinnigan at manning.com. Also see: