Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAX-RS - Can two classes have the same @Path identifier?

Tags:

java

jax-rs

cxf

I have a webapp that redirects to a particular URI: let's say /service/library. In another bundle, I have a jaxrs server that listens for /service in the URI, and defines some beans to handle the request. There are quite a few beans there already, and one of the classes is already implemented to handle requests for /service/library. I am trying to create a new class that also handles requests for /service/library, but with a different absolute URI path, for example: /service/library/mynewlibrary. My question is, is it possible to define the same @Path identifier in two classes, or must they be unique, in other words, will I need to use a URI like /service/mylibrary for my new class implementation instead of implementing a second class that also uses the same @Path identifier? I am pretty new to JAX-RS, so I hope my question makes sense!

Thanks!

like image 871
Stephen Avatar asked Apr 18 '11 21:04

Stephen


People also ask

What is javax Ws RS Path?

javax.ws.rsIdentifies the URI path that a resource class or class method will serve requests for. Paths are relative. For an annotated class the base URI is the application path, see ApplicationPath . For an annotated method the base URI is the effective URI of the containing class.

Which method allow you to verify that the incoming request path matches a given pattern?

rs. Path annotation in JAX-RS is used to define a URI matching pattern for incoming HTTP requests. It can be placed upon a class or on one or more Java methods.

Which annotation helps to extract information from the URI directly?

PathParam. This annotation allows you to extract values from URI template parameters.


1 Answers

It's possible to have two @Path annotations that match the URI. In your case, if servlet-mapping is service, you may have @Path("/library") and @Path("library/mynewlibrary"). When request arrives, the matching paths are sorted in descending order, so the second class should be called, when a request with /service/library/mynewlibrary arrives.

like image 86
Tarlog Avatar answered Oct 30 '22 18:10

Tarlog