Created
March 27, 2015 14:42
-
-
Save nherbaut/46296403a5206d211ab4 to your computer and use it in GitHub Desktop.
jersey support several @consume with the same path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package net.viotech; | |
| import javax.ws.rs.Consumes; | |
| import javax.ws.rs.GET; | |
| import javax.ws.rs.POST; | |
| import javax.ws.rs.Path; | |
| import javax.ws.rs.Produces; | |
| import javax.ws.rs.core.MediaType; | |
| import javax.ws.rs.core.Response; | |
| import javax.ws.rs.core.Response.ResponseBuilder; | |
| @Path("myresource") | |
| public class MyResource { | |
| /** | |
| * Method handling HTTP GET requests. The returned object will be sent | |
| * to the client as "text/plain" media type. | |
| * | |
| * @return String that will be returned as a text/plain response. | |
| */ | |
| @POST | |
| @Consumes("text/plain") | |
| public Response getIt(String message) { | |
| return Response.accepted().header("X-MEDIA-HOME-PLAIN", message).build(); | |
| } | |
| @POST | |
| @Consumes("application/octet-stream") | |
| public Response getIt2(String message) { | |
| return Response.accepted().header("X-MEDIA-OCTET-STREAM", message).build(); | |
| } | |
| } | |
| /* | |
| nherbaut@nheraut-HP-EliteBook-840-G1:~$ curl -X POST -d "coucou" localhost:8080/myresource -H "Content-type:text/plain2" -v | |
| * Hostname was NOT found in DNS cache | |
| * Trying 127.0.0.1... | |
| * Connected to localhost (127.0.0.1) port 8080 (#0) | |
| > POST /myresource HTTP/1.1 | |
| > User-Agent: curl/7.35.0 | |
| > Host: localhost:8080 | |
| > Accept: */* | |
| > Content-type:text/plain2 | |
| > Content-Length: 6 | |
| > | |
| * upload completely sent off: 6 out of 6 bytes | |
| < HTTP/1.1 202 Accepted | |
| < Date: Fri, 27 Mar 2015 14:40:50 GMT | |
| < X-MEDIA-HOME-STREAM: coucou | |
| < Content-Length: 0 | |
| * Server Jetty(9.2.10.v20150310) is not blacklisted | |
| < Server: Jetty(9.2.10.v20150310) | |
| < | |
| * Connection #0 to host localhost left intact | |
| ----------------- | |
| nherbaut@nheraut-HP-EliteBook-840-G1:~$ curl -X POST -d "coucou" localhost:8080/myresource -H "Content-type:application/octet-stream" -v | |
| * Hostname was NOT found in DNS cache | |
| * Trying 127.0.0.1... | |
| * Connected to localhost (127.0.0.1) port 8080 (#0) | |
| > POST /myresource HTTP/1.1 | |
| > User-Agent: curl/7.35.0 | |
| > Host: localhost:8080 | |
| > Accept: */* | |
| > Content-type:application/octet-stream | |
| > Content-Length: 6 | |
| > | |
| ------------------------- | |
| nherbaut@nheraut-HP-EliteBook-840-G1:~$ curl -X POST -d "coucou" localhost:8080/myresource -H "Content-type:text/plain" -v | |
| * Hostname was NOT found in DNS cache | |
| * Trying 127.0.0.1... | |
| * Connected to localhost (127.0.0.1) port 8080 (#0) | |
| > POST /myresource HTTP/1.1 | |
| > User-Agent: curl/7.35.0 | |
| > Host: localhost:8080 | |
| > Accept: */* | |
| > Content-type:text/plain | |
| > Content-Length: 6 | |
| > | |
| * upload completely sent off: 6 out of 6 bytes | |
| < HTTP/1.1 202 Accepted | |
| < Date: Fri, 27 Mar 2015 14:41:29 GMT | |
| < X-MEDIA-HOME-PLAIN: coucou | |
| < Content-Length: 0 | |
| * Server Jetty(9.2.10.v20150310) is not blacklisted | |
| < Server: Jetty(9.2.10.v20150310) | |
| < | |
| * Connection #0 to host localhost left intact | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment