-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to look up a resource by its URI #2444
Comments
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented
I can't use a request filter because I need to process this information inside resource methods (once I understand what kind of operation was invoked), besides which it sounds like this operation would be overkill for what I'm trying to accomplish. |
@glassfishrobot Commented
creates a connection between participants 31 and 32. How is the server supposed to honor this request? In Jersey 1.0 I would resolve each URI back to a resource. Each resource contains the following methods: long getId(); So, once I've got the resource, I invoke getId() to get the database identifier and create the connection. When someone invokes GET /connections/321213 I convert the database id to a resource and from there invoke getUri(). I take the resulting URI and add it to the response body. |
@glassfishrobot Commented |
@glassfishrobot Commented Would these 2 methods help in your use case? |
@glassfishrobot Commented
In the above example, I'd have something like this:
Notice how I use both a conversion from URI to id and id to URI. As mentioned in https://java.net/projects/jersey/lists/users/archive/2013-11/message/62 I now realize that Jersey has no concept of what I call a HTTP Resource (meaning the concept of a resource independent of the response format). I'm looking for a mapping from URI to a resource, independent of the response format, and Jersey doesn't seem to have such a concept per-se. If it had such a concept, the question of how this feature should intersect with filters probably wouldn't be relevant because they wouldn't affect the URI to Resource mapping. Jersey 1.x ResourceContext.matchResource(URI) seemed to behave this way (although maybe not intentionally). At this point, it's not clear how I can implement this without repeating the URI to Resource mapping twice (once for Jersey using @path and sub-resource locators, once for my code that implements URI to Resource mapping). |
@glassfishrobot Commented I tried using ResourceModel to implement this outside of Jersey but:
It seems that all roads lead to Rome. Jersey needs to provide a mechanism to construct a UriInfo or ContainerRequest to an arbitrary URI. If you know of another way, please point me in the right direction. I believe this is the only remaining feature preventing me from migrating to Jersey 2. |
@glassfishrobot Commented |
@glassfishrobot Commented Thanks, |
@glassfishrobot Commented Take a look at http://stackoverflow.com/a/23620747/14731 It's ugly code, but it works. We can only hope that this will get folded into Jersey proper (so we can use this functionality in a cleaner fashion). |
@glassfishrobot Commented |
|
In Jersey 1.0 we could look up a resource by URI using ResourceContext.matchResource(URI). There doesn't seem to be an equivalent functionality in Jersey 2.0.
Use-case: The request entity body references the URI of a resource. I need to convert this URI into a resource class, then drill down into its database id in order to honor the request.
Affected Versions
[2.4]
The text was updated successfully, but these errors were encountered: