View Javadoc

1   /*
2    * $Id: HelloWorldResource.java 21492 2011-03-08 04:25:31Z 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  import org.mule.module.jersey.exception.HelloWorldException;
24  
25  @Path("/helloworld")
26  public class HelloWorldResource
27  {
28      @POST
29      @Produces("text/plain")
30      public String sayHelloWorld()
31      {
32          return "Hello World";
33      }
34  
35      @GET
36      @Produces("application/json")
37      @Path("/sayHelloWithJson/{name}")
38      public HelloBean sayHelloWithJson(@PathParam("name") String name)
39      {
40          HelloBean hello = new HelloBean();
41          hello.setMessage("Hello " + name);
42          return hello;
43      }
44  
45      @DELETE
46      @Produces("text/plain")
47      public String deleteHelloWorld()
48      {
49          return "Hello World Delete";
50      }
51  
52      @GET
53      @Produces("text/plain")
54      @Path("/sayHelloWithUri/{name}")
55      public String sayHelloWithUri(@PathParam("name") String name)
56      {
57          return "Hello " + name;
58      }
59  
60      @GET
61      @Produces("text/plain")
62      @Path("/sayHelloWithHeader")
63      public Response sayHelloWithHeader(@HeaderParam("X-Name") String name)
64      {
65          return Response.status(201).header("X-ResponseName", name).entity("Hello " + name).build();
66      }
67  
68      @GET
69      @Produces("text/plain")
70      @Path("/sayHelloWithQuery")
71      public String sayHelloWithQuery(@QueryParam("name") String name)
72      {
73          return "Hello " + name;
74      }
75      
76      @GET
77      @Produces("text/plain")
78      @Path("/throwException")
79      public String throwException() throws HelloWorldException
80      {
81          throw new HelloWorldException("This is an exception");
82      }
83  }