Re: Digest for list users@jersey.java.net

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Digest for list users@jersey.java.net

Simon Roberts-3
If you want a sub resource, you must not use the HTTP method annotation on the method. 

On Dec 7, 2016 03:05, <[hidden email]> wrote:
Table of contents:

1. [Jersey] PUT not delegating to sub-resource - "Trenton D. Adams" <[hidden email]>



---------- Forwarded message ----------
From: "Trenton D. Adams" <[hidden email]>
To: [hidden email]
Cc: 
Date: Tue, 6 Dec 2016 03:15:31 -0700
Subject: [Jersey] PUT not delegating to sub-resource
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@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;
}

End of digest for list [hidden email] - Wed, 07 Dec 2016