blogger templates blogger widgets
This is part of a list of blog posts.
To browse the contents go to

JAX-RS: Request Method Designator Annotations

Request method designator annotations are runtime annotations, defined by JAX-RS, that correspond to the similarly named HTTP methods.
By default, the JAX-RS runtime will automatically support the methods HEAD and OPTIONS if not explicitly implemented. For HEAD, the runtime will invoke the implemented GET method, if present, and ignore the response entity, if set. For OPTIONS, the Allow response header will be set to the set of HTTP methods supported by the resource.

Sample using POST request method,
@Path("/hello")
public class HelloResource {
    @POST
    @Produces("text/plain")
    @Consumes("text/plain")
    public String helloPost(String username) {
        return "[POST] Hello "+username+" from JAX-RS on WebSphere Application server";
    }
}

Client code,
String lsUrl = "http://localhost:9080/RSServer/HelloApp/hello";
RestClient client = new RestClient();
Resource resource = client.resource(lsUrl);
String result = resource.contentType(MediaType.TEXT_PLAIN).post(String.class, new String("John"));
System.out.println(result);

No comments:

Post a Comment