Revision 6396
Added by ben leinfelder over 13 years ago
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java | ||
---|---|---|
140 | 140 |
String resource = request.getPathInfo(); |
141 | 141 |
resource = resource.substring(resource.indexOf("/") + 1); |
142 | 142 |
|
143 |
// get the rest
|
|
143 |
// for the rest of the resouce
|
|
144 | 144 |
String extra = null; |
145 |
if (resource.lastIndexOf("/") != -1) { |
|
146 |
extra = resource.substring(resource.lastIndexOf("/") + 1); |
|
147 |
} |
|
148 | 145 |
|
149 | 146 |
logMetacat.debug("handling verb " + httpVerb + " request with resource '" + resource + "'"); |
150 | 147 |
boolean status = false; |
... | ... | |
160 | 157 |
} else if (resource.startsWith(RESOURCE_META)) { |
161 | 158 |
logMetacat.debug("Using resource: " + RESOURCE_META); |
162 | 159 |
|
160 |
// after the command |
|
161 |
extra = parseTrailing(resource, RESOURCE_META); |
|
162 |
|
|
163 | 163 |
// get |
164 | 164 |
if (httpVerb == GET) { |
165 | 165 |
getSystemMetadataObject(extra); |
... | ... | |
179 | 179 |
} |
180 | 180 |
} else if (resource.startsWith(RESOURCE_ASSERT_RELATION)) { |
181 | 181 |
|
182 |
// after the command |
|
183 |
extra = parseTrailing(resource, RESOURCE_ASSERT_RELATION); |
|
184 |
|
|
182 | 185 |
// reserve the ID (in params) |
183 | 186 |
if (httpVerb == GET) { |
184 | 187 |
assertRelation(extra); |
... | ... | |
186 | 189 |
} |
187 | 190 |
} else if (resource.startsWith(RESOURCE_RESOLVE)) { |
188 | 191 |
|
192 |
// after the command |
|
193 |
extra = parseTrailing(resource, RESOURCE_RESOLVE); |
|
194 |
|
|
189 | 195 |
// resolve the object location |
190 | 196 |
if (httpVerb == GET) { |
191 | 197 |
resolve(extra); |
... | ... | |
193 | 199 |
} |
194 | 200 |
} else if (resource.startsWith(RESOURCE_OWNER)) { |
195 | 201 |
|
202 |
// after the command |
|
203 |
extra = parseTrailing(resource, RESOURCE_OWNER); |
|
204 |
|
|
196 | 205 |
// set the owner |
197 | 206 |
if (httpVerb == PUT) { |
198 | 207 |
owner(extra); |
199 | 208 |
status = true; |
200 | 209 |
} |
201 |
} else if (resource.startsWith(RESOURCE_OWNER)) { |
|
202 |
|
|
203 |
// set the owner |
|
204 |
if (httpVerb == PUT) { |
|
205 |
owner(extra); |
|
206 |
status = true; |
|
207 |
} |
|
208 | 210 |
} else if (resource.startsWith(RESOURCE_IS_AUTHORIZED)) { |
209 | 211 |
|
212 |
// after the command |
|
213 |
extra = parseTrailing(resource, RESOURCE_IS_AUTHORIZED); |
|
214 |
|
|
210 | 215 |
// authorized? |
211 | 216 |
if (httpVerb == GET) { |
212 | 217 |
isAuthorized(extra); |
... | ... | |
216 | 221 |
logMetacat.debug("Using resource 'object'"); |
217 | 222 |
logMetacat.debug("D1 Rest: Starting resource processing..."); |
218 | 223 |
|
224 |
// after the command |
|
225 |
extra = parseTrailing(resource, RESOURCE_OBJECTS); |
|
226 |
|
|
219 | 227 |
logMetacat.debug("objectId: " + extra); |
220 | 228 |
logMetacat.debug("verb:" + httpVerb); |
221 | 229 |
|
... | ... | |
234 | 242 |
} else if (resource.startsWith(RESOURCE_FORMATS)) { |
235 | 243 |
logMetacat.debug("Using resource: " + RESOURCE_FORMATS); |
236 | 244 |
|
245 |
// after the command |
|
246 |
extra = parseTrailing(resource, RESOURCE_FORMATS); |
|
237 | 247 |
|
238 |
|
|
239 | 248 |
// handle each verb |
240 | 249 |
if (httpVerb == GET) { |
241 | 250 |
if (extra == null) { |
... | ... | |
258 | 267 |
|
259 | 268 |
} else if (resource.startsWith(RESOURCE_CHECKSUM)) { |
260 | 269 |
logMetacat.debug("Using resource: " + RESOURCE_CHECKSUM); |
270 |
|
|
271 |
// after the command |
|
272 |
extra = parseTrailing(resource, RESOURCE_CHECKSUM); |
|
273 |
|
|
261 | 274 |
//handle checksum requests |
262 | 275 |
if (httpVerb == GET) { |
263 | 276 |
|
... | ... | |
295 | 308 |
} |
296 | 309 |
} |
297 | 310 |
|
311 |
private String parseTrailing(String resource, String token) { |
|
312 |
// get the rest |
|
313 |
String extra = null; |
|
314 |
if (resource.indexOf(token) != -1) { |
|
315 |
// what comes after the token? |
|
316 |
extra = resource.substring(resource.indexOf(token) + token.length()); |
|
317 |
// remove the slash |
|
318 |
if (extra.startsWith("/")) { |
|
319 |
extra = extra.substring(1); |
|
320 |
} |
|
321 |
// is there anything left? |
|
322 |
if (extra.length() == 0) { |
|
323 |
extra = null; |
|
324 |
} |
|
325 |
} |
|
326 |
return extra; |
|
327 |
} |
|
328 |
|
|
298 | 329 |
/** |
299 | 330 |
* Get the checksum for the given guid |
300 | 331 |
* |
Also available in: Unified diff
do not parse from last slash ("/") to the end when processing the request uri - otherwise things like format ids (text/csv) will be handled incorrectly.
https://redmine.dataone.org/issues/1773