Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Single Jersey REST class for multiple PATH

I have started developing REST services using JAX-RS. Using Jersey is pretty straightforward however one difference which I come across using Spring MVC and Jersey REST classes is, Spring supports having to ignore the Root Path element and have individual path mappings at Method Level. So if there is a Upload / Download Functionality, I may not want to have 2 classes one with upload and one with download which Jersey asks me to do now because there could be only 1 Root Path at class level like this:

@Path("/uploads")
public class FileDownloadController {
......
}

If I ignore the root level @Path i.e at the class level, Jersey while starting up the server doesn't recognize my class. Here is what I want to achieve:

public class FileProcessController {

   @Path("/uploads")
   public Response uploadFile(...) {
       ......
   }

   @Path("/downloads")
   public Response downloadFile(...) {
      ......
   }
}

Any clues will be appreciated.

Thanks

like image 571
Yogendra Avatar asked Jun 27 '26 21:06

Yogendra


1 Answers

Not sure if I understand the question correctly, but the following will create two endpoints in the 'Jersey root' as /uploads and /downloads. You will be able to specify other methods in the root; all of this in the same class.

@Path("/")  
public class FileProcessController {

   @Path("uploads")
   public Response uploadFile(...) {
       ...
   }

   @Path("downloads")
   public Response downloadFile(...) {
      ...
   }

}
like image 186
Daniel Szalay Avatar answered Jun 30 '26 12:06

Daniel Szalay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!