1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2000 Regents of the University of California and the
|
4
|
* National Center for Ecological Analysis and Synthesis
|
5
|
*
|
6
|
* '$Author: Serhan AKIN $'
|
7
|
* '$Date: 2009-06-13 13:28:21 +0300 $'
|
8
|
*
|
9
|
* This program is free software; you can redistribute it and/or modify
|
10
|
* it under the terms of the GNU General Public License as published by
|
11
|
* the Free Software Foundation; either version 2 of the License, or
|
12
|
* (at your option) any later version.
|
13
|
*
|
14
|
* This program is distributed in the hope that it will be useful,
|
15
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
* GNU General Public License for more details.
|
18
|
*
|
19
|
* You should have received a copy of the GNU General Public License
|
20
|
* along with this program; if not, write to the Free Software
|
21
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
22
|
*/
|
23
|
package edu.ucsb.nceas.metacat.restservice;
|
24
|
|
25
|
import java.io.IOException;
|
26
|
|
27
|
import javax.servlet.ServletConfig;
|
28
|
import javax.servlet.ServletException;
|
29
|
import javax.servlet.http.HttpServlet;
|
30
|
import javax.servlet.http.HttpServletRequest;
|
31
|
import javax.servlet.http.HttpServletResponse;
|
32
|
|
33
|
import org.apache.log4j.Logger;
|
34
|
|
35
|
/**
|
36
|
* Metacat implemantation of Earthgrid (Ecogrid) REST API as a servlet. In each request
|
37
|
* REST Servlet initialize a ResourceHandler object and then ResourceHandler object
|
38
|
* handles with request and writes approriate response.
|
39
|
*
|
40
|
* @deprecated Only keeping this for reference in case we want to implement
|
41
|
* older Metacat API with REST
|
42
|
*/
|
43
|
public class RestServlet extends HttpServlet {
|
44
|
|
45
|
protected Logger logMetacat;
|
46
|
protected ResourceHandler handler;
|
47
|
|
48
|
/**
|
49
|
* Subclasses should override this method to provide the appropriate handler subclass
|
50
|
* @param request
|
51
|
* @param response
|
52
|
* @return
|
53
|
* @throws ServletException
|
54
|
* @throws IOException
|
55
|
*/
|
56
|
protected ResourceHandler createHandler(HttpServletRequest request, HttpServletResponse response)
|
57
|
throws ServletException, IOException {
|
58
|
ResourceHandler handler = new ResourceHandler(getServletContext(), request, response);
|
59
|
return handler;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Initalize servlet by setting logger
|
64
|
*/
|
65
|
@Override
|
66
|
public void init(ServletConfig config) throws ServletException {
|
67
|
logMetacat = Logger.getLogger(this.getClass());
|
68
|
super.init(config);
|
69
|
}
|
70
|
|
71
|
/** Handle "GET" method requests from HTTP clients */
|
72
|
@Override
|
73
|
protected void doGet(HttpServletRequest request,
|
74
|
HttpServletResponse response) throws ServletException, IOException {
|
75
|
System.out.println("HTTP Verb: GET");
|
76
|
handler = createHandler(request, response);
|
77
|
handler.handle(ResourceHandler.GET);
|
78
|
}
|
79
|
|
80
|
/** Handle "POST" method requests from HTTP clients */
|
81
|
@Override
|
82
|
protected void doPost(HttpServletRequest request,
|
83
|
HttpServletResponse response) throws ServletException, IOException {
|
84
|
System.out.println("HTTP Verb: POST");
|
85
|
handler = createHandler(request, response);
|
86
|
handler.handle(ResourceHandler.POST);
|
87
|
}
|
88
|
|
89
|
/** Handle "DELETE" method requests from HTTP clients */
|
90
|
@Override
|
91
|
protected void doDelete(HttpServletRequest request,
|
92
|
HttpServletResponse response) throws ServletException, IOException {
|
93
|
System.out.println("HTTP Verb: DELETE");
|
94
|
handler = createHandler(request, response);
|
95
|
handler.handle(ResourceHandler.DELETE);
|
96
|
}
|
97
|
|
98
|
/** Handle "PUT" method requests from HTTP clients */
|
99
|
@Override
|
100
|
protected void doPut(HttpServletRequest request,
|
101
|
HttpServletResponse response) throws ServletException, IOException {
|
102
|
System.out.println("HTTP Verb: PUT");
|
103
|
handler = createHandler(request, response);
|
104
|
handler.handle(ResourceHandler.PUT);
|
105
|
}
|
106
|
|
107
|
/** Handle "PUT" method requests from HTTP clients */
|
108
|
@Override
|
109
|
protected void doHead(HttpServletRequest request,
|
110
|
HttpServletResponse response) throws ServletException, IOException {
|
111
|
System.out.println("HTTP Verb: HEAD");
|
112
|
handler = createHandler(request, response);
|
113
|
handler.handle(ResourceHandler.HEAD);
|
114
|
}
|
115
|
}
|