1 | /* |
---|
2 | * Copyright (C) 2014 CLARIN |
---|
3 | * |
---|
4 | * This program is free software: you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation, either version 3 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | */ |
---|
17 | package eu.clarin.cmdi.virtualcollectionregistry.rest; |
---|
18 | |
---|
19 | import java.io.IOException; |
---|
20 | import java.io.InputStream; |
---|
21 | import java.io.OutputStream; |
---|
22 | import javax.ws.rs.GET; |
---|
23 | import javax.ws.rs.Path; |
---|
24 | import javax.ws.rs.Produces; |
---|
25 | import javax.ws.rs.WebApplicationException; |
---|
26 | import javax.ws.rs.core.MediaType; |
---|
27 | import javax.ws.rs.core.Response; |
---|
28 | import javax.ws.rs.core.StreamingOutput; |
---|
29 | import org.apache.wicket.util.io.IOUtils; |
---|
30 | |
---|
31 | /** |
---|
32 | * |
---|
33 | * @author twagoo |
---|
34 | */ |
---|
35 | @Path("") |
---|
36 | public class BaseResource { |
---|
37 | |
---|
38 | /** |
---|
39 | * Serves a short description HTML page at the service root |
---|
40 | * |
---|
41 | * @return |
---|
42 | */ |
---|
43 | @GET |
---|
44 | @Path("/") |
---|
45 | @Produces({MediaType.TEXT_XML}) |
---|
46 | public Response getDescription() { |
---|
47 | final StreamingOutput writer = new StreamingOutput() { |
---|
48 | @Override |
---|
49 | public void write(OutputStream output) throws IOException, |
---|
50 | WebApplicationException { |
---|
51 | try (InputStream is = getClass().getResourceAsStream("/restIndex.html")) { |
---|
52 | IOUtils.copy(is, output); |
---|
53 | } finally { |
---|
54 | output.close(); |
---|
55 | } |
---|
56 | } |
---|
57 | }; |
---|
58 | return Response.ok(writer).type(MediaType.TEXT_HTML).build(); |
---|
59 | } |
---|
60 | |
---|
61 | } |
---|