users@jersey.java.net

[Jersey] Re: PUT not delegating to sub-resource

From: Trenton D. Adams <trenton.d.adams_at_gmail.com>
Date: Wed, 7 Dec 2016 01:20:24 -0700

My bad, I just re-read the JSR on sub-resources. Putting a method (e.g.
@PUT) makes it a sub-resource method, not a sub-resource locator. So
naturally, it just toStrings the result.


On Tue, Dec 6, 2016 at 3:15 AM, Trenton D. Adams <trenton.d.adams_at_gmail.com>
wrote:

> I'm playing around with Jersey. I'm finding that PUT doesn't seem to
> delegate to a sub-resource, while POST does...
>
> Note how it simply outputs the class name...
>
>
> @PUT
> @Path("{keyId}")
> public Class<? extends PostApiKeys> putApiKey(
> @PathParam("keyId") final String keyId, @Valid ApiKey apiKey)
> {
> return PostApiKeys.class;
> }
>
> $ curl -X PUT -H 'Accept: application/json' -H "Content-Type:
> application/json" -d '{"keyId": "2123", "verificationCode":
> "cjklsdjlkjsdf"}' 'http://localhost:8080/eve-manufacturing-manager/api-
> keys/2123'
>
> "com.github.trentonadams.eve.features.apikeys.services.PostApiKeys"
>
>
> But with a POST, it works just fine...
>
> /**
> * Stores api keys using a service which simple returns 200, with a JSON
> * response.
> *
> * @return the service for posting api keys.
> */
> @Path("post")
> public Class<? extends PostApiKeys> postService()
> {
> return PostApiKeys.class;
> }
>
> [03:12:12 trenta_at_developer-VirtualBox ~/LocalDocuments/development/
> java/eve-manufacturing-manager]
> $ curl -X POST -H 'Accept: application/json' -H "Content-Type:
> application/json" -d '{"keyId": "2123", "verificationCode":
> "cjklsdjlkjsdf"}' 'http://localhost:8080/eve-manufacturing-manager/api-
> keys/post'
>
> {"keyId":"2123","verificationCode":"cjklsdjlkjsdf"}
>
>
> public interface IPostApiKeys
> {
> @POST
> @Consumes({
> MediaType.APPLICATION_JSON, MediaType.MULTIPART_FORM_DATA,
> MediaType.APPLICATION_XML})
> @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
> Response postForm(@Valid ApiKey apiKey) throws URISyntaxException;
>
> @PUT
> @Consumes({
> MediaType.APPLICATION_JSON,
> MediaType.APPLICATION_XML})
> @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
> @Path("{keyId}")
> Response putForm(@PathParam("keyId") String keyId, @Valid ApiKey apiKey)
> throws URISyntaxException;
> }
>
>