SlideShare a Scribd company logo
By Anirban Sen Chowdhary
Using jersey exception mapper
.
Here I will show you how ……
Let us consider we have a following Mule flow :-
As you can we have exposed a REST web service in our
application. Now if we test this web service it will fetch some
records from Database and display in browser
As you can see that we have hit the url
http://localhost:8082/getData/retrieve/?id=1 on browser and
getting the desired result on it
Now, let’s use jersey:exception-mapper in our Mule flow to map the
jersey based exception that allow mapping generic exceptions that may
be thrown in the component class to HTTP response codes like the
following :-
<flow name="MainService" doc:name="MainService">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost"
port="8082" doc:name="HTTP"/>
<logger message="RequestLog :- #[message.payloadAs(java.lang.String)]" level="INFO"
doc:name="RequestLogger"/>
<jersey:resources doc:name="REST">
<component class="com.testservices.schema.maindata.v1.Impl.MainDataImpl"/>
<jersey:exception-mapper class="com.test.custom.response.NotFound" />
</jersey:resources>
<logger message="ResponseLog :- #[message.payloadAs(java.lang.String)]"
level="INFO" doc:name="ResponseLogger"/>
</flow>
That’s it…. Now our jersey:exception-mapper java class NotFound :-
public class NotFound implements
ExceptionMapper<NotFoundException> {
public Response toResponse(NotFoundException exception){
return Response.status(Response.Status.BAD_REQUEST).entity("No
Resources available at :- : " +
exception.getNotFoundUri().toString()).build();
}
}
You can see that we can also customize the http code and can generate
our custom message. Now generally if a resource is not found the http
code will be 404. But we can customize the http code even this
jersey:exception-mapper and we have put here http code 400
Now you can see that if we pass any wrong url it is displaying our custom
message that we have written in our Java :-
Also you can see that we have successfully customized and changed the
http status code to 400 :-
Hope you enjoyed the simple yet an amazing trick in Mule
Using jersey exception mapper

More Related Content

PPTX
Playing with cxf interceptor in mule
PPTX
Playing with cxf interceptor in mule
PDF
MuleSoft ESB Message Enricher
PPTX
Message enricher in mule
PDF
RESTful Web Services
PPTX
Ch7(publishing my sql data on the web)
Playing with cxf interceptor in mule
Playing with cxf interceptor in mule
MuleSoft ESB Message Enricher
Message enricher in mule
RESTful Web Services
Ch7(publishing my sql data on the web)

What's hot (17)

PDF
Security in php
PPTX
Whats new in ASP.NET 4.0
ODP
Dropbox connector Mule ESB Integration
PPTX
Designing CakePHP plugins for consuming APIs
PPT
Securing Your Web Server
PPTX
Mule flow complete
PPTX
Request dispacther interface ppt
PPTX
Mule idempotent filter and Object Store
PPTX
Configurare https mule
PPT
J M Githeko Agenda Software installation – Apche, MySQL, PHP
PPT
Anypoint connectorfor ibm as 400
ODP
Running ms sql stored procedures in mule
PPTX
Basics of web technologies
PPT
JSP/Servlet Core Concept
PPTX
PPTX
Scalling web applications using memcache
PPTX
Mule esb :Data Weave
Security in php
Whats new in ASP.NET 4.0
Dropbox connector Mule ESB Integration
Designing CakePHP plugins for consuming APIs
Securing Your Web Server
Mule flow complete
Request dispacther interface ppt
Mule idempotent filter and Object Store
Configurare https mule
J M Githeko Agenda Software installation – Apche, MySQL, PHP
Anypoint connectorfor ibm as 400
Running ms sql stored procedures in mule
Basics of web technologies
JSP/Servlet Core Concept
Scalling web applications using memcache
Mule esb :Data Weave
Ad

Viewers also liked (12)

PPTX
Restrict an ip
PPTX
Converting with custom transformer
PPTX
Converting with custom transformer part 2
PPTX
Mule requesterdemo
PPT
PDF
Making strategy a reality jwilliamson
DOC
swipe file
PPT
Vizitaţi şcoala noastră
PPT
Group3-ps number 9
PDF
特にオチのないゲームの小ネタ
PPTX
Exception handling in mule
Restrict an ip
Converting with custom transformer
Converting with custom transformer part 2
Mule requesterdemo
Making strategy a reality jwilliamson
swipe file
Vizitaţi şcoala noastră
Group3-ps number 9
特にオチのないゲームの小ネタ
Exception handling in mule
Ad

Similar to Using jersey exception mapper (10)

PDF
Exception mapping using api kit
PPTX
Mulesoft meetup slides mumbai_20113019_exception_handling
PPT
Mule exception strategies - Choice Exception Strategy
PPTX
Exception handling in Mule 4 _Virtual mule soft meetup may_2020
PPTX
Virtual MuleSoft Meetup may_2020
PDF
Engineering Student MuleSoft Meetup#5 - Error Handling With MuleSoft
PPTX
Elements in a muleflow
PPTX
Mule meetup Hyderabad
PPTX
Defining global exception strategies
PPTX
Elements in a mule flow
Exception mapping using api kit
Mulesoft meetup slides mumbai_20113019_exception_handling
Mule exception strategies - Choice Exception Strategy
Exception handling in Mule 4 _Virtual mule soft meetup may_2020
Virtual MuleSoft Meetup may_2020
Engineering Student MuleSoft Meetup#5 - Error Handling With MuleSoft
Elements in a muleflow
Mule meetup Hyderabad
Defining global exception strategies
Elements in a mule flow

More from Anirban Sen Chowdhary (20)

PPTX
Change the game with Game changer
PPTX
Ring central desktop app overview
PPTX
Overview in ringcentral digital line
PPTX
Some basics with ring central
PPTX
Ring central and python
PPTX
RingCentral application development overview
PPTX
Cloze connect ringcentral
PPTX
Overview on ring central errors part 4
PPTX
Setting up your ring central sandbox in steps
PPTX
Overview on ring central errors: part 2
PPTX
Overview on ring central errors
PPTX
Call recording overview ring central
PPTX
Ring central engaging with amazon alexa
PPTX
How ring central sdk changing the game
PPTX
When ring central connect salesforce
PPTX
Mule 4 connecting ring central
PPTX
Ring central sdk
PPTX
Ring central with okta
PPTX
Ring central connecting salesforce overview
PPTX
Ring central call logs overview (part 2)
Change the game with Game changer
Ring central desktop app overview
Overview in ringcentral digital line
Some basics with ring central
Ring central and python
RingCentral application development overview
Cloze connect ringcentral
Overview on ring central errors part 4
Setting up your ring central sandbox in steps
Overview on ring central errors: part 2
Overview on ring central errors
Call recording overview ring central
Ring central engaging with amazon alexa
How ring central sdk changing the game
When ring central connect salesforce
Mule 4 connecting ring central
Ring central sdk
Ring central with okta
Ring central connecting salesforce overview
Ring central call logs overview (part 2)

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
sap open course for s4hana steps from ECC to s4
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPT
Teaching material agriculture food technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation theory and applications.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
sap open course for s4hana steps from ECC to s4
The Rise and Fall of 3GPP – Time for a Sabbatical?
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MYSQL Presentation for SQL database connectivity
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Digital-Transformation-Roadmap-for-Companies.pptx
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Teaching material agriculture food technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Understanding_Digital_Forensics_Presentation.pptx
Machine learning based COVID-19 study performance prediction
Encapsulation theory and applications.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Per capita expenditure prediction using model stacking based on satellite ima...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Using jersey exception mapper

  • 1. By Anirban Sen Chowdhary
  • 3. .
  • 4. Here I will show you how ……
  • 5. Let us consider we have a following Mule flow :- As you can we have exposed a REST web service in our application. Now if we test this web service it will fetch some records from Database and display in browser
  • 6. As you can see that we have hit the url http://localhost:8082/getData/retrieve/?id=1 on browser and getting the desired result on it
  • 7. Now, let’s use jersey:exception-mapper in our Mule flow to map the jersey based exception that allow mapping generic exceptions that may be thrown in the component class to HTTP response codes like the following :- <flow name="MainService" doc:name="MainService"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/> <logger message="RequestLog :- #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="RequestLogger"/> <jersey:resources doc:name="REST"> <component class="com.testservices.schema.maindata.v1.Impl.MainDataImpl"/> <jersey:exception-mapper class="com.test.custom.response.NotFound" /> </jersey:resources> <logger message="ResponseLog :- #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="ResponseLogger"/> </flow>
  • 8. That’s it…. Now our jersey:exception-mapper java class NotFound :- public class NotFound implements ExceptionMapper<NotFoundException> { public Response toResponse(NotFoundException exception){ return Response.status(Response.Status.BAD_REQUEST).entity("No Resources available at :- : " + exception.getNotFoundUri().toString()).build(); } } You can see that we can also customize the http code and can generate our custom message. Now generally if a resource is not found the http code will be 404. But we can customize the http code even this jersey:exception-mapper and we have put here http code 400
  • 9. Now you can see that if we pass any wrong url it is displaying our custom message that we have written in our Java :-
  • 10. Also you can see that we have successfully customized and changed the http status code to 400 :-
  • 11. Hope you enjoyed the simple yet an amazing trick in Mule