Jersey – Case-insensitive @Path URLs

By default in JAX-RS, ALL URLs specified in @Path annotations are CASE-SENSITIVE. In this tutorial, I am giving a simple example of CASE-INSENSITIVE URLs which cane be used inside @Path annotation on any Jersey JAX-RS REST API.

How to make URLs case in-sensitive

To make URLs case-insensitive, change the @Path URLs like below:

@Path("/{employees}")
public class JerseyService 
{
	//Code
}

Change above declaration to this:

@Path("/{employees : (?i)employees}")
public class JerseyService 
{
	//Code
}

Now above @Path annotation will be able to match any variation of lowercase and UPPERCASE letters in employees.

Please note that for this example, I am using Jersey 2.19.

Demo Usage

Here, I am modified the sourcecode of my previous example of Jersey RESTful Client Examples.

I sent following requests to HTTP GET /{employees : (?i)employees} path, and all paths matches correctly.

http://localhost:8080/JerseyDemos/rest/EMPLOYEES

Case-insensitive URL - 1
Case-insensitive URL – 1

http://localhost:8080/JerseyDemos/rest/EmPlOyEEs

Case-insensitive URL - 2
Case-insensitive URL – 2

http://localhost:8080/JerseyDemos/rest/employees

Case-insensitive URL - 3
Case-insensitive URL – 3

Feel free to contact in you find any problem in this example.

Happy Learning !!

Was this post helpful?

Join 8000+ Awesome Developers, Like YOU!

2 thoughts on “Jersey – Case-insensitive @Path URLs”

Leave a Comment

About HowToDoInJava

This blog provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions, and frequently asked interview questions.