3

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

Yogendra
  • 331
  • 5
  • 21
  • 1
    Easy tweak is to use both the Root level Path and method level Path... So you can use the combination of them as an URL to the function – rozar Feb 24 '14 at 06:24
  • I cannot do that because the client has a specific url in our case it is /services/rest as the Servlet Mapping and then /uploads or /downloads as the method. So I cannot ask the client to introduce may be say "/file" as the base path and then use /uploads and /downloads. Any other idea? – Yogendra Feb 24 '14 at 07:55
  • I exactly mentioned what Daniel suggested. Use the combination of both. Any ways cheers you fixed the issue :-) – rozar Feb 24 '14 at 15:19
  • Oh, I am sorry rozar, I was not able to understand that. Cheers!! I just marked your answer accepted too :) – Yogendra Feb 24 '14 at 18:05

1 Answers1

11

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(...) {
      ...
   }

}
Daniel Szalay
  • 4,041
  • 12
  • 57
  • 103