comparison src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorAnnotations.java @ 19:a681113fd0eb

PUT returns 303 according to spec now. seems not to work with the client :-(
author casties
date Fri, 23 Mar 2012 14:27:15 +0100
parents 383c0fee2d37
children 0cd1e7608d25
comparison
equal deleted inserted replaced
18:383c0fee2d37 19:a681113fd0eb
12 import org.json.JSONException; 12 import org.json.JSONException;
13 import org.json.JSONObject; 13 import org.json.JSONObject;
14 import org.restlet.Context; 14 import org.restlet.Context;
15 import org.restlet.data.Form; 15 import org.restlet.data.Form;
16 import org.restlet.data.MediaType; 16 import org.restlet.data.MediaType;
17 import org.restlet.data.Reference;
17 import org.restlet.data.Status; 18 import org.restlet.data.Status;
18 import org.restlet.ext.json.JsonRepresentation; 19 import org.restlet.ext.json.JsonRepresentation;
19 import org.restlet.representation.Representation; 20 import org.restlet.representation.Representation;
20 import org.restlet.representation.StringRepresentation; 21 import org.restlet.representation.StringRepresentation;
21 import org.restlet.resource.Delete; 22 import org.restlet.resource.Delete;
289 * @return 290 * @return
290 */ 291 */
291 @Put("json") 292 @Put("json")
292 public Representation doPutJSON(Representation entity) { 293 public Representation doPutJSON(Representation entity) {
293 logger.debug("AnnotatorAnnotations doPutJSON!"); 294 logger.debug("AnnotatorAnnotations doPutJSON!");
295 Reference thisUrl = this.getReference();
294 setCorsHeaders(); 296 setCorsHeaders();
295 // id from URI /annotations/{id} 297 // id from URI /annotations/{id}
296 String jsonId = (String) getRequest().getAttributes().get("id"); 298 String jsonId = (String) getRequest().getAttributes().get("id");
297 String id = decodeJsonId(jsonId); 299 String id = decodeJsonId(jsonId);
298 logger.debug("annotation-id=" + id); 300 logger.debug("annotation-id=" + id);
326 // update from posted JSON 328 // update from posted JSON
327 annot = updateAnnotation(storedAnnot, jo, entity); 329 annot = updateAnnotation(storedAnnot, jo, entity);
328 // store Annotation 330 // store Annotation
329 storedAnnot = new Convert("file:///annotations").storeAnnotation(annot); 331 storedAnnot = new Convert("file:///annotations").storeAnnotation(annot);
330 /* according to https://github.com/okfn/annotator/wiki/Storage 332 /* according to https://github.com/okfn/annotator/wiki/Storage
331 * we should return 303: see other. 333 * we should return 303: see other. */
332 * For now we return the annotation. 334 setStatus(Status.REDIRECTION_SEE_OTHER);
333 */ 335 // go to same URL as this one
334 jo = createAnnotatorJson(storedAnnot); 336 this.getResponse().setLocationRef(thisUrl);
335 JsonRepresentation retRep = new JsonRepresentation(jo);
336 return retRep;
337 } catch (TripleStoreHandlerException e) { 337 } catch (TripleStoreHandlerException e) {
338 e.printStackTrace(); 338 e.printStackTrace();
339 setStatus(Status.SERVER_ERROR_INTERNAL, "TripleStoreHandler Error"); 339 setStatus(Status.SERVER_ERROR_INTERNAL, "TripleStoreHandler Error");
340 } catch (TripleStoreSearchError e) { 340 } catch (TripleStoreSearchError e) {
341 e.printStackTrace(); 341 e.printStackTrace();