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