/** * Create a pre-signed URL that will be used to upload a single chunk of a large file (see: <a * href="${POST.createChunkedFileUploadToken}">POST /createChunkedFileUploadToken</a>). This * method will return the URL in the body of the HttpServletResponse with a content type of * 'text/plain'. * * @param userId * @param cpr - Includes the {@link ChunkedFileToken} and the chunk number. The chunk number * indicates this chunks position in the larger file. If there are 'n' chunks then the first * chunk is '1' and the last chunk is 'n'. * @param response * @throws DatastoreException * @throws NotFoundException * @throws IOException */ @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/createChunkedFileUploadChunkURL", method = RequestMethod.POST) public void createChunkedPresignedUrl( @RequestParam(value = AuthorizationConstants.USER_ID_PARAM) String userId, @RequestBody ChunkRequest cpr, HttpServletResponse response) throws DatastoreException, NotFoundException, IOException { URL url = fileService.createChunkedFileUploadPartURL(userId, cpr); // Return the redirect url instead of redirecting. response.setStatus(HttpStatus.CREATED.value()); response.setContentType("text/plain"); response.getWriter().write(url.toString()); response.getWriter().flush(); }
@Test public void shouldCreateRecord() throws Exception { RecordPayload recordPayload = RecordPayload.instanceOf(7); when(mockService.create(argThat(isRecord(null, 7)))).thenReturn(TEST_ID); when(mockUriInfo.getAbsolutePathBuilder()) .thenReturn(UriBuilder.fromPath("http://localhost:8080/services/webapi/myresource")); Response response = recordResource.createRecord(recordPayload); assertThat( response.getLocation().toString(), is("http://localhost:8080/services/webapi/myresource/a02")); assertThat(response.getStatus(), is(HttpStatus.CREATED.value())); }
@RequestMapping( value = "/editmemocontent", method = RequestMethod.POST, headers = "Accept=application/json") public ResponseEntity<Map<String, Object>> updateMemoContent(@RequestBody Memo memo) { Map<String, Object> map = new HashMap<String, Object>(); if (memoDao.updateMemoContent(memo) == true) { map.put("MESSAGE", "MEMO HAS BEEN UPDATED."); map.put("STATUS", HttpStatus.CREATED.value()); return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK); } else { map.put("MESSAGE", "MEMO HAS NOT BEEN UPDATED."); map.put("STATUS", true); return new ResponseEntity<Map<String, Object>>(map, HttpStatus.NOT_ACCEPTABLE); } }
@RequestMapping( value = {"/company/{companyId}/graph/{graphId}"}, method = {RequestMethod.PUT}) @ResponseBody public Graph updateGraph( @PathVariable("companyId") int companyId, @PathVariable("graphId") int graphId, @RequestBody Graph graph, HttpServletResponse httpResponse_p, WebRequest request_p) throws Exception { Graph returnVal = graphService.updateGraph(companyId, graphId, graph); httpResponse_p.setStatus(HttpStatus.CREATED.value()); httpResponse_p.setHeader("Location", request_p.getContextPath() + "/graph/" + graphId); return returnVal; }
@RequestMapping( value = "/savememo", method = RequestMethod.POST, headers = "Accept=application/json") public ResponseEntity<Map<String, Object>> addMemo(@RequestBody Memo memo) { Map<String, Object> map = new HashMap<String, Object>(); if (memoDao.getMemoByUrl(memo.getDomain(), memo.getUrl(), memo.getUserid()) == null) { memoDao.insertMemo(memo); map.put("MESSAGE", "MEMO HAS BEEN CREATED."); map.put("STATUS", HttpStatus.CREATED.value()); return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK); } else { map.put("MESSAGE", "MEMO HAS NOT BEEN CREATED."); map.put("STATUS", HttpStatus.NOT_FOUND.value()); return new ResponseEntity<Map<String, Object>>(map, HttpStatus.NOT_ACCEPTABLE); } }
@RequestMapping( value = "/plugingetmemo", method = RequestMethod.POST, headers = "Accept=application/json") public ResponseEntity<Map<String, Object>> getMemo(@RequestBody Memo memo) { Map<String, Object> map = new HashMap<String, Object>(); List<Memo> memos = new ArrayList<Memo>(); memos = memoDao.pluginGetMemo(memo.getUserid(), memo.getUrl()); if (!memos.isEmpty()) { map.put("MESSAGE", "MEMO HAS BEEN FOUND."); map.put("STATUS", HttpStatus.CREATED.value()); map.put("DATA", memos); return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK); } else { map.put("MESSAGE", "MEMO NOT FOUND."); map.put("STATUS", HttpStatus.NOT_FOUND.value()); return new ResponseEntity<Map<String, Object>>(map, HttpStatus.NOT_FOUND); } }
/** * Upload files as a multi-part upload, and create file handles for each. * * @param request * @param response * @param headers * @throws FileUploadException * @throws IOException * @throws NotFoundException * @throws DatastoreException * @throws ServiceUnavailableException * @throws JSONObjectAdapterException */ @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/fileHandle", method = RequestMethod.POST) void uploadFiles( HttpServletRequest request, HttpServletResponse response, @RequestHeader HttpHeaders headers) throws FileUploadException, IOException, DatastoreException, NotFoundException, ServiceUnavailableException, JSONObjectAdapterException { // Get the user ID String userId = request.getParameter(AuthorizationConstants.USER_ID_PARAM); if (userId == null) throw new UnauthorizedException("The user must be authenticated"); LogUtils.logRequest(log, request); // Maker sure this is a multipart if (!ServletFileUpload.isMultipartContent(request)) { throw new IllegalArgumentException( "This service only supports: content-type = multipart/form-data"); } // Pass it along. FileHandleResults results = fileService.uploadFiles(userId, new ServletFileUpload().getItemIterator(request)); response.setContentType("application/json"); response.setStatus(HttpStatus.CREATED.value()); response.getOutputStream().print(EntityFactory.createJSONStringForEntity(results)); // Not flushing causes the stream to be empty for the GWT use case. response.getOutputStream().flush(); }