1   /*
2    * Copyright 2009, Josh Devins, Jitr.org.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.jitr.test.server;
18  
19  import javax.ws.rs.Consumes;
20  import javax.ws.rs.DELETE;
21  import javax.ws.rs.GET;
22  import javax.ws.rs.POST;
23  import javax.ws.rs.PUT;
24  import javax.ws.rs.Path;
25  import javax.ws.rs.Produces;
26  import javax.ws.rs.core.MediaType;
27  
28  import org.jitr.test.service.TestService;
29  import org.springframework.beans.factory.annotation.Autowired;
30  import org.springframework.stereotype.Component;
31  
32  @Component
33  @Path("string")
34  public final class TestResource {
35  
36      private final TestService testService;
37  
38      @Autowired
39      TestResource(final TestService testService) {
40          this.testService = testService;
41      }
42  
43      @DELETE
44      @Produces(MediaType.TEXT_PLAIN)
45      public String delete() {
46          return testService.clearString();
47      }
48  
49      @POST
50      @Consumes(MediaType.TEXT_PLAIN)
51      @Produces(MediaType.TEXT_PLAIN)
52      @Path("echo")
53      public String echo(final String string) {
54          return testService.echoString(string);
55      }
56  
57      @GET
58      @Produces(MediaType.TEXT_PLAIN)
59      public String get() {
60          return testService.getString();
61      }
62  
63      @PUT
64      @Consumes(MediaType.TEXT_PLAIN)
65      @Produces(MediaType.TEXT_PLAIN)
66      public String set(final String string) {
67          return testService.setString(string);
68      }
69  }