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
|
*/
|
41
|
public class RestServlet extends HttpServlet {
|
42
|
|
43
|
private Logger logMetacat;
|
44
|
private ResourceHandler handler;
|
45
|
|
46
|
/**
|
47
|
* Initalize servlet by setting logger
|
48
|
*/
|
49
|
@Override
|
50
|
public void init(ServletConfig config) throws ServletException {
|
51
|
logMetacat = Logger.getLogger(this.getClass());
|
52
|
super.init(config);
|
53
|
}
|
54
|
|
55
|
/** Handle "GET" method requests from HTTP clients */
|
56
|
@Override
|
57
|
protected void doGet(HttpServletRequest request,
|
58
|
HttpServletResponse response) throws ServletException, IOException {
|
59
|
System.out.println("HTTP Verb: GET");
|
60
|
handler = new ResourceHandler(getServletContext(), request, response);
|
61
|
handler.handle(ResourceHandler.GET);
|
62
|
}
|
63
|
|
64
|
/** Handle "POST" method requests from HTTP clients */
|
65
|
@Override
|
66
|
protected void doPost(HttpServletRequest request,
|
67
|
HttpServletResponse response) throws ServletException, IOException {
|
68
|
System.out.println("HTTP Verb: POST");
|
69
|
handler = new ResourceHandler(getServletContext(), request, response);
|
70
|
handler.handle(ResourceHandler.POST);
|
71
|
}
|
72
|
|
73
|
/** Handle "DELETE" method requests from HTTP clients */
|
74
|
@Override
|
75
|
protected void doDelete(HttpServletRequest request,
|
76
|
HttpServletResponse response) throws ServletException, IOException {
|
77
|
System.out.println("HTTP Verb: DELETE");
|
78
|
handler = new ResourceHandler(getServletContext(), request, response);
|
79
|
handler.handle(ResourceHandler.DELETE);
|
80
|
}
|
81
|
|
82
|
/** Handle "PUT" method requests from HTTP clients */
|
83
|
@Override
|
84
|
protected void doPut(HttpServletRequest request,
|
85
|
HttpServletResponse response) throws ServletException, IOException {
|
86
|
System.out.println("HTTP Verb: PUT");
|
87
|
handler = new ResourceHandler(getServletContext(), request, response);
|
88
|
handler.handle(ResourceHandler.PUT);
|
89
|
}
|
90
|
|
91
|
}
|