SlideShare ist ein Scribd-Unternehmen logo
1 von 21
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:

Weitere ähnliche Inhalte

Was ist angesagt?

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
 
Integration with dropbox using mule esb
Integration with dropbox using mule esbIntegration with dropbox using mule esb
Integration with dropbox using mule esbsivachandra mandalapu
 
Mule saas enablement
Mule  saas enablementMule  saas enablement
Mule saas enablementhimajareddys
 
Mule ESB
Mule ESBMule ESB
Mule ESBniravn
 
Mule google connectors
Mule  google connectorsMule  google connectors
Mule google connectorsD.Rajesh Kumar
 
Mulethenewtechnology 12549172699166-phpapp03-160421133841
Mulethenewtechnology 12549172699166-phpapp03-160421133841Mulethenewtechnology 12549172699166-phpapp03-160421133841
Mulethenewtechnology 12549172699166-phpapp03-160421133841ppts123456
 
(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 2014Amazon Web Services
 
Deployment Automation with Microservices
Deployment Automation with MicroservicesDeployment Automation with Microservices
Deployment Automation with MicroservicesGanesh Ghag
 
Build an API the right way
Build an API the right wayBuild an API the right way
Build an API the right waySoftware Guru
 
Lab - AWS Cross Account Access
Lab - AWS Cross Account AccessLab - AWS Cross Account Access
Lab - AWS Cross Account AccessAlbert Suwandhi
 
Custom connector development using mule DevKit
Custom connector development using mule DevKitCustom connector development using mule DevKit
Custom connector development using mule DevKitRamakrishna Narkedamilli
 

Was ist angesagt? (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
 

Ähnlich wie Enterprise Java Microservices : creating and managing large-scale Java applications

Service Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJSService Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJSAndolasoft Inc
 
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, HTTP2Atharva Jawalkar
 
Microservice architecture
Microservice architectureMicroservice architecture
Microservice architectureTouraj Ebrahimi
 
Rest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookRest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookKaty Slemon
 
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.pdfseo18
 
Latest Web development technologies 2021
 Latest Web development technologies 2021 Latest Web development technologies 2021
Latest Web development technologies 2021SWATHYSMOHAN
 
When to use serverless computing.pdf
When to use serverless computing.pdfWhen to use serverless computing.pdf
When to use serverless computing.pdfSGBSeo
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Bluegrass 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.pdfSufalam 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 JDBCChaithraCSHirematt
 

Ähnlich wie 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
 

Mehr von 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 learningManning 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 citizenManning Publications
 
Automated Machine Learning in Action
Automated Machine Learning in ActionAutomated Machine Learning in Action
Automated Machine Learning in ActionManning 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 codeManning 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 pipelineManning 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 smoothlyManning 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 MicroProfileManning 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 EdtionManning Publications
 
Microservices in .NET Core, Second Edition
Microservices in .NET Core, Second EditionMicroservices in .NET Core, Second Edition
Microservices in .NET Core, Second EditionManning Publications
 
Kubernetes in Action, Second Edition
Kubernetes in Action, Second EditionKubernetes in Action, Second Edition
Kubernetes in Action, Second EditionManning Publications
 
Machine Learning with TensorFlow, Second Edition
Machine Learning with TensorFlow, Second EditionMachine Learning with TensorFlow, Second Edition
Machine Learning with TensorFlow, Second EditionManning Publications
 
Spring Microservices in Action, Second Edition
Spring Microservices in Action, Second EditionSpring Microservices in Action, Second Edition
Spring Microservices in Action, Second EditionManning Publications
 

Mehr von 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
 

Kürzlich hochgeladen

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 

Kürzlich hochgeladen (20)

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

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: