View Javadoc

1   /*
2    * $Id: HelloWorldResource.java 19270 2010-09-01 10:37:41Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.jersey;
12  
13  import javax.ws.rs.DELETE;
14  import javax.ws.rs.GET;
15  import javax.ws.rs.HeaderParam;
16  import javax.ws.rs.POST;
17  import javax.ws.rs.Path;
18  import javax.ws.rs.PathParam;
19  import javax.ws.rs.Produces;
20  import javax.ws.rs.QueryParam;
21  import javax.ws.rs.core.Response;
22  
23  @Path("/helloworld")
24  public class HelloWorldResource
25  {
26      @POST
27      @Produces("text/plain")
28      public String sayHelloWorld()
29      {
30          return "Hello World";
31      }
32  
33      @GET
34      @Produces("application/json")
35      @Path("/sayHelloWithJson/{name}")
36      public HelloBean sayHelloWithJson(@PathParam("name") String name)
37      {
38          HelloBean hello = new HelloBean();
39          hello.setMessage("Hello " + name);
40          return hello;
41      }
42  
43      @DELETE
44      @Produces("text/plain")
45      public String deleteHelloWorld()
46      {
47          return "Hello World Delete";
48      }
49  
50      @GET
51      @Produces("text/plain")
52      @Path("/sayHelloWithUri/{name}")
53      public String sayHelloWithUri(@PathParam("name") String name)
54      {
55          return "Hello " + name;
56      }
57  
58      @GET
59      @Produces("text/plain")
60      @Path("/sayHelloWithHeader")
61      public Response sayHelloWithHeader(@HeaderParam("X-Name") String name)
62      {
63          return Response.status(201).header("X-ResponseName", name).entity("Hello " + name).build();
64      }
65  
66      @GET
67      @Produces("text/plain")
68      @Path("/sayHelloWithQuery")
69      public String sayHelloWithQuery(@QueryParam("name") String name)
70      {
71          return "Hello " + name;
72      }
73  }