Revision 6271
Added by ben leinfelder over 13 years ago
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java | ||
---|---|---|
29 | 29 |
import java.io.IOException; |
30 | 30 |
import java.io.InputStream; |
31 | 31 |
import java.io.OutputStream; |
32 |
import java.io.PrintWriter; |
|
33 | 32 |
import java.io.StringReader; |
34 | 33 |
import java.io.UnsupportedEncodingException; |
35 | 34 |
import java.text.DateFormat; |
... | ... | |
37 | 36 |
import java.text.SimpleDateFormat; |
38 | 37 |
import java.util.Date; |
39 | 38 |
import java.util.Enumeration; |
40 |
import java.util.Hashtable; |
|
41 | 39 |
import java.util.Iterator; |
42 | 40 |
import java.util.List; |
43 | 41 |
import java.util.Map; |
44 |
import java.util.Timer; |
|
45 | 42 |
|
46 | 43 |
import javax.servlet.ServletContext; |
47 | 44 |
import javax.servlet.http.HttpServletRequest; |
... | ... | |
50 | 47 |
import org.apache.commons.io.IOUtils; |
51 | 48 |
import org.apache.log4j.Logger; |
52 | 49 |
import org.dataone.client.ObjectFormatCache; |
53 |
import org.dataone.client.auth.CertificateManager; |
|
54 | 50 |
import org.dataone.mimemultipart.MultipartRequest; |
55 | 51 |
import org.dataone.mimemultipart.MultipartRequestResolver; |
56 | 52 |
import org.dataone.service.exceptions.BaseException; |
... | ... | |
82 | 78 |
import org.dataone.service.types.SystemMetadata; |
83 | 79 |
import org.jibx.runtime.JiBXException; |
84 | 80 |
|
85 |
import edu.ucsb.nceas.metacat.MetacatHandler; |
|
86 | 81 |
import edu.ucsb.nceas.metacat.dataone.MNodeService; |
87 | 82 |
|
88 | 83 |
/** |
... | ... | |
140 | 135 |
} |
141 | 136 |
|
142 | 137 |
/** |
143 |
* This function is called from REST APU servlet and handles each request to the servlet
|
|
138 |
* This function is called from REST API servlet and handles each request to the servlet
|
|
144 | 139 |
* |
145 | 140 |
* @param httpVerb (GET, POST, PUT or DELETE) |
146 | 141 |
*/ |
142 |
@Override |
|
147 | 143 |
public void handle(byte httpVerb) { |
148 |
logMetacat = Logger.getLogger(MNResourceHandler.class); |
|
144 |
// prepare the handler |
|
145 |
super.handle(httpVerb); |
|
146 |
|
|
149 | 147 |
try { |
150 | 148 |
String resourcePrefix = RESOURCE_BASE_URL + "/mn/"; |
151 | 149 |
String resource = request.getServletPath(); |
... | ... | |
162 | 160 |
System.out.println("handling verb " + httpVerb + " request with resource '" + resource + "'"); |
163 | 161 |
System.out.println("resource: '" + resource + "'"); |
164 | 162 |
boolean status = false; |
165 |
|
|
166 |
// load session from certificate in request |
|
167 |
session = CertificateManager.getInstance().getSession(request); |
|
168 | 163 |
|
169 | 164 |
if (resource != null) { |
170 |
//resource = request.getServletPath().substring(1); |
|
171 | 165 |
|
172 |
params = new Hashtable<String, String[]>(); |
|
173 |
initParams(); |
|
174 |
|
|
175 |
Timer timer = new Timer(); |
|
176 |
handler = new MetacatHandler(timer); |
|
177 |
|
|
178 | 166 |
if (resource.equals(RESOURCE_NODE)) { |
179 | 167 |
// node response |
180 | 168 |
node(); |
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java | ||
---|---|---|
31 | 31 |
import java.io.PrintWriter; |
32 | 32 |
import java.io.UnsupportedEncodingException; |
33 | 33 |
import java.util.Date; |
34 |
import java.util.Hashtable; |
|
35 | 34 |
import java.util.Map; |
36 |
import java.util.Timer; |
|
37 | 35 |
|
38 | 36 |
import javax.servlet.ServletContext; |
39 | 37 |
import javax.servlet.http.HttpServletRequest; |
... | ... | |
43 | 41 |
import org.apache.commons.io.IOUtils; |
44 | 42 |
import org.apache.log4j.Logger; |
45 | 43 |
import org.dataone.client.ObjectFormatCache; |
46 |
import org.dataone.client.auth.CertificateManager; |
|
47 | 44 |
import org.dataone.service.exceptions.BaseException; |
48 | 45 |
import org.dataone.service.exceptions.IdentifierNotUnique; |
49 | 46 |
import org.dataone.service.exceptions.InsufficientResources; |
... | ... | |
69 | 66 |
import org.dataone.service.types.SystemMetadata; |
70 | 67 |
import org.jibx.runtime.JiBXException; |
71 | 68 |
|
72 |
import edu.ucsb.nceas.metacat.MetacatHandler; |
|
73 | 69 |
import edu.ucsb.nceas.metacat.dataone.CNodeService; |
74 | 70 |
|
75 | 71 |
/** |
... | ... | |
114 | 110 |
|
115 | 111 |
/** CN-specific operations **/ |
116 | 112 |
protected static final String RESOURCE_RESERVE = "reserve"; |
117 |
protected static final String RESOURCE_FORMATS = "formats"; //remove from super
|
|
113 |
protected static final String RESOURCE_FORMATS = "formats"; |
|
118 | 114 |
protected static final String RESOURCE_RESOLVE = "resolve"; |
119 | 115 |
protected static final String RESOURCE_ASSERT_RELATION = "assertRelation"; |
120 | 116 |
protected static final String RESOURCE_OWNER = "owner"; |
... | ... | |
129 | 125 |
} |
130 | 126 |
|
131 | 127 |
/** |
132 |
* This function is called from REST APU servlet and handles each request to the servlet
|
|
128 |
* This function is called from REST API servlet and handles each request to the servlet
|
|
133 | 129 |
* |
134 | 130 |
* @param httpVerb (GET, POST, PUT or DELETE) |
135 | 131 |
*/ |
132 |
@Override |
|
136 | 133 |
public void handle(byte httpVerb) { |
134 |
// prepare the handler |
|
135 |
super.handle(httpVerb); |
|
136 |
|
|
137 | 137 |
try { |
138 | 138 |
//substring off the "d1/cn/" part of the url |
139 | 139 |
String resourcePrefix = RESOURCE_BASE_URL + "/cn/"; |
... | ... | |
143 | 143 |
|
144 | 144 |
logMetacat.debug("handling verb " + httpVerb + " request with resource '" + resource + "'"); |
145 | 145 |
boolean status = false; |
146 |
|
|
147 |
// load session from certificate in request |
|
148 |
// TODO: move to superclass |
|
149 |
session = CertificateManager.getInstance().getSession(request); |
|
150 |
|
|
146 |
|
|
151 | 147 |
if (resource != null) { |
152 | 148 |
|
153 |
params = new Hashtable<String, String[]>(); |
|
154 |
initParams(); |
|
155 |
|
|
156 |
Timer timer = new Timer(); |
|
157 |
handler = new MetacatHandler(timer); |
|
158 |
|
|
159 | 149 |
if (resource.equals(RESOURCE_ACCESS_RULES) && httpVerb == PUT) { |
160 | 150 |
logMetacat.debug("Setting access policy"); |
161 | 151 |
setAccess(); |
... | ... | |
256 | 246 |
} else if (httpVerb == POST) { |
257 | 247 |
putObject(objectId, FUNCTION_NAME_INSERT); |
258 | 248 |
status = true; |
259 |
} else if (httpVerb == PUT) { |
|
260 |
// TODO: this is not applicable for CN |
|
261 |
putObject(objectId, FUNCTION_NAME_UPDATE); |
|
262 |
status = true; |
|
263 | 249 |
} |
264 | 250 |
|
265 | 251 |
} else if (resource.equals(RESOURCE_FORMATS)) { |
... | ... | |
309 | 295 |
} |
310 | 296 |
|
311 | 297 |
if (!status) { |
312 |
throw new ServiceFailure("0000", "Unknown error, status=" + status);
|
|
298 |
throw new ServiceFailure("0000", "Unknown error, status = " + status);
|
|
313 | 299 |
} |
314 | 300 |
} else { |
315 | 301 |
throw new InvalidRequest("0000", "No resource matched for " + resource); |
src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java | ||
---|---|---|
84 | 84 |
/* |
85 | 85 |
* API Resources |
86 | 86 |
*/ |
87 |
protected static final String RESOURCE_BASE_URL = "d1"; |
|
88 |
|
|
87 | 89 |
protected static final String RESOURCE_OBJECTS = "object"; |
88 |
protected static final String RESOURCE_FORMATS = "formats"; |
|
89 | 90 |
protected static final String RESOURCE_META = "meta"; |
90 |
protected static final String RESOURCE_SESSION = "session"; |
|
91 |
protected static final String RESOURCE_IDENTIFIER = "identifier"; |
|
92 | 91 |
protected static final String RESOURCE_LOG = "log"; |
93 | 92 |
protected static final String RESOURCE_CHECKSUM = "checksum"; |
94 |
protected static final String RESOURCE_MONITOR = "monitor"; |
|
95 |
protected static final String RESOURCE_BASE_URL = "d1"; |
|
96 |
protected static final String RESOURCE_REPLICATE = "replicate"; |
|
97 | 93 |
|
98 | 94 |
protected static final String RESOURCE_IS_AUTHORIZED = "isAuthorized"; |
99 | 95 |
protected static final String RESOURCE_ACCESS_RULES = "accessRules"; |
... | ... | |
101 | 97 |
/* |
102 | 98 |
* API Functions used as URL parameters |
103 | 99 |
*/ |
104 |
protected static final String FUNCTION_KEYWORD = "op"; |
|
105 |
protected static final String FUNCTION_NAME_LOGIN = "login"; |
|
106 |
protected static final String FUNCTION_NAME_LOGOUT = "logout"; |
|
107 |
protected static final String FUNCTION_NAME_SET_ACCESS = "setaccess"; |
|
108 |
protected static final String FUNCTION_NAME_ISREGISTERED = "isregistered"; |
|
109 |
protected static final String FUNCTION_NAME_GETALLDOCS = "getalldocids"; |
|
110 |
protected static final String FUNCTION_NAME_GETNEXTREV = "getnextrevision"; |
|
111 |
protected static final String FUNCTION_NAME_GETNEXTOBJ = "getnextobject"; |
|
112 | 100 |
protected static final String FUNCTION_NAME_INSERT = "insert"; |
113 | 101 |
protected static final String FUNCTION_NAME_UPDATE = "update"; |
114 |
protected static final String FUNCTION_NAME_GENERATE_MISSING_SYSTEM_METADATA = "generatemissingsystemmetadata"; |
|
115 | 102 |
|
116 | 103 |
protected static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); |
117 | 104 |
|
... | ... | |
120 | 107 |
protected MetacatHandler handler; |
121 | 108 |
protected HttpServletRequest request; |
122 | 109 |
protected HttpServletResponse response; |
123 |
protected String username; |
|
124 |
protected String password; |
|
125 |
protected String sessionId; |
|
126 |
protected String[] groupNames; |
|
127 | 110 |
|
128 | 111 |
protected Hashtable<String, String[]> params; |
129 | 112 |
protected Map<String, List<String>> multipartparams; |
Also available in: Unified diff
consolidate session management and parameter preparation in the superclass