List of usage examples for javax.servlet.http HttpServletResponse SC_CREATED
int SC_CREATED
To view the source code for javax.servlet.http HttpServletResponse SC_CREATED.
Click Source Link
From source file:com.homesnap.webserver.HouseRestAPITest.java
@Test public void test4GetHouse() { postRequestJSONObject(urn + "/labels/ch1", createLabelCh1(), HttpServletResponse.SC_CREATED); postRequestJSONObject(urn + "/groups/6", createGroup6(), HttpServletResponse.SC_CREATED); postRequestJSONObject(urn + "/labels/ch2", createLabelCh2(), HttpServletResponse.SC_CREATED); postRequestJSONObject(urn + "/groups/2", createGroup2(), HttpServletResponse.SC_CREATED); // Test to get a house with some group and label JSONObject jo = getRequestJSONObject(urn); // Test labels JSONArray labels = jo.getJSONArray(House.JSON_LABELS); testLabelCh1(labels.getJSONObject(0)); testLabelCh2(labels.getJSONObject(1)); // Test Groups JSONArray groups = jo.getJSONArray(House.JSON_GROUPS); testGroup6(groups.getJSONObject(0)); testGroup2(groups.getJSONObject(1)); }
From source file:com.thinkberg.moxo.dav.CopyMoveBase.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean overwrite = getOverwrite(request); FileObject object = getResourceManager().getFileObject(request.getPathInfo()); FileObject targetObject = getDestination(request); try {//w w w .j ava2s . c o m // check that we can write the target LockManager.getInstance().checkCondition(targetObject, getIf(request)); // if we move, check that we can actually write on the source if ("MOVE".equals(request.getMethod())) { LockManager.getInstance().checkCondition(object, getIf(request)); } } catch (LockException e) { if (e.getLocks() != null) { response.sendError(SC_LOCKED); } else { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); } return; } if (null == targetObject) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } if (object.equals(targetObject)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } if (targetObject.exists()) { if (!overwrite) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } response.setStatus(HttpServletResponse.SC_NO_CONTENT); } else { FileObject targetParent = targetObject.getParent(); if (!targetParent.exists() || !FileType.FOLDER.equals(targetParent.getType())) { response.sendError(HttpServletResponse.SC_CONFLICT); } response.setStatus(HttpServletResponse.SC_CREATED); } copyOrMove(object, targetObject, getDepth(request)); }
From source file:org.fcrepo.server.management.UploadServlet.java
/** * The servlet entry point. http://host:port/fedora/management/upload *///from ww w . j a v a 2s. c o m @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Context context = ReadOnlyContext.getContext(Constants.HTTP_REQUEST.REST.uri, request); try { // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(); // Parse the request, looking for "file" InputStream in = null; FileItemIterator iter = upload.getItemIterator(request); while (in == null && iter.hasNext()) { FileItemStream item = iter.next(); logger.info( "Got next item: isFormField=" + item.isFormField() + " fieldName=" + item.getFieldName()); if (!item.isFormField() && item.getFieldName().equals("file")) { in = item.openStream(); } } if (in == null) { sendResponse(HttpServletResponse.SC_BAD_REQUEST, "No data sent.", response); } else { sendResponse(HttpServletResponse.SC_CREATED, m_management.putTempStream(context, in), response); } } catch (AuthzException ae) { throw RootException.getServletException(ae, request, "Upload", new String[0]); } catch (Exception e) { e.printStackTrace(); sendResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getClass().getName() + ": " + e.getMessage(), response); } }
From source file:org.apache.roller.weblogger.webservices.adminprotocol.AdminServlet.java
/** * Handles an Atom POST by calling handler to identify URI, reading/parsing * data, calling handler and writing results to response. *//*w w w .jav a2s. c o m*/ protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try { Handler handler = Handler.getHandler(req); String userName = handler.getUserName(); EntrySet c = handler.processPost(new InputStreamReader(req.getInputStream())); res.setStatus(HttpServletResponse.SC_CREATED); res.setContentType("application/xml; charset=utf-8"); String s = c.toString(); Writer writer = res.getWriter(); writer.write(s); writer.close(); } catch (HandlerException he) { res.sendError(he.getStatus(), he.getMessage()); he.printStackTrace(res.getWriter()); logger.error(he); } }
From source file:com.thinkberg.webdav.PutHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = VFSBackend.resolveFile(request.getPathInfo()); try {//from w ww .j a v a2s . com if (!LockManager.getInstance().evaluateCondition(object, getIf(request)).result) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } } catch (LockException e) { response.sendError(SC_LOCKED); return; } catch (ParseException e) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } // it is forbidden to write data on a folder if (object.exists() && FileType.FOLDER.equals(object.getType())) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } FileObject parent = object.getParent(); if (!parent.exists()) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } if (!FileType.FOLDER.equals(parent.getType())) { response.sendError(HttpServletResponse.SC_CONFLICT); return; } InputStream is = request.getInputStream(); OutputStream os = object.getContent().getOutputStream(); long bytesCopied = Util.copyStream(is, os); String contentLengthHeader = request.getHeader("Content-length"); LOG.debug(String.format("sent %d/%s bytes", bytesCopied, contentLengthHeader == null ? "unknown" : contentLengthHeader)); os.flush(); object.close(); response.setStatus(HttpServletResponse.SC_CREATED); }
From source file:org.syncope.core.rest.controller.RoleController.java
@PreAuthorize("hasRole('ROLE_CREATE')") @RequestMapping(method = RequestMethod.POST, value = "/create") public RoleTO create(final HttpServletResponse response, final @RequestBody RoleTO roleTO) throws SyncopeClientCompositeErrorException, UnauthorizedRoleException { LOG.debug("Role create called with parameters {}", roleTO); Set<Long> allowedRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames()); if (roleTO.getParent() != 0 && !allowedRoleIds.contains(roleTO.getParent())) { throw new UnauthorizedRoleException(roleTO.getParent()); }//from w w w . jav a2 s . com SyncopeRole role; try { role = roleDataBinder.create(roleTO); } catch (SyncopeClientCompositeErrorException e) { LOG.error("Could not create for " + roleTO, e); throw e; } role = roleDAO.save(role); response.setStatus(HttpServletResponse.SC_CREATED); return roleDataBinder.getRoleTO(role); }
From source file:fedora.server.management.UploadServlet.java
/** * The servlet entry point. http://host:port/fedora/management/upload *//* w w w. ja va 2 s . com*/ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Context context = ReadOnlyContext.getContext(Constants.HTTP_REQUEST.REST.uri, request); try { // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(); // Parse the request, looking for "file" InputStream in = null; FileItemIterator iter = upload.getItemIterator(request); while (in == null && iter.hasNext()) { FileItemStream item = iter.next(); LOG.info("Got next item: isFormField=" + item.isFormField() + " fieldName=" + item.getFieldName()); if (!item.isFormField() && item.getFieldName().equals("file")) { in = item.openStream(); } } if (in == null) { sendResponse(HttpServletResponse.SC_BAD_REQUEST, "No data sent.", response); } else { sendResponse(HttpServletResponse.SC_CREATED, s_management.putTempStream(context, in), response); } } catch (AuthzException ae) { throw RootException.getServletException(ae, request, "Upload", new String[0]); } catch (Exception e) { e.printStackTrace(); sendResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getClass().getName() + ": " + e.getMessage(), response); } }
From source file:net.dstc.mkts.rest.MktSurveyService.java
@POST @Protected//from w w w . ja v a 2s .co m @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Register new survey", code = 201, authorizations = { @Authorization(value = "oauth2") }) public void insert(SurveyDTO survey, @Context HttpServletResponse response) throws NotAuthException, OAuthSystemException { service.insert(survey); response.setStatus(HttpServletResponse.SC_CREATED); try { response.getOutputStream().close(); } catch (Exception ex) { } }
From source file:com.lohika.alp.reporter.fe.controller.LogController.java
@RequestMapping(method = RequestMethod.POST, value = "/results/test-method/{testMethodId}/log") void saveLog(@PathVariable("testMethodId") long id, @ModelAttribute("uploadItem") UploadItem uploadItem, HttpServletResponse response) throws IOException { CommonsMultipartFile fileData = uploadItem.getFileData(); // TODO Handle unexpected form data String name = fileData.getOriginalFilename(); InputStream is = fileData.getInputStream(); // If file extension is '.xml' or none save it as 'index.xml' if (name.toLowerCase().endsWith(".xml") || !name.matches(".*\\.\\w{1,3}$")) { logStorage.saveLog(id, "index.xml", is); // TODO TestMethod database creation should be performed with Spring // and REST web services, not from test listeners directly TestMethod testMethod = testMethodDAO.getTestMethod(id); // Set into DB that TestMethod has index log file testMethod.setHasLog(true);/*from w w w . j a va 2s . co m*/ testMethodDAO.saveTestMethod(testMethod); } else { // Else save it with its original name logStorage.saveLog(id, name, is); } response.setStatus(HttpServletResponse.SC_CREATED); // TODO add log URL to response according REST principles }
From source file:org.efaps.webdav4vfs.handler.PutHandler.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = VFSBackend.resolveFile(request.getPathInfo()); try {/*from w w w .j av a 2 s . co m*/ if (!LockManager.getInstance().evaluateCondition(object, getIf(request)).result) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } } catch (LockException e) { response.sendError(SC_LOCKED); return; } catch (ParseException e) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } // it is forbidden to write data on a folder if (object.exists() && FileType.FOLDER.equals(object.getType())) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } FileObject parent = object.getParent(); if (!parent.exists()) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } if (!FileType.FOLDER.equals(parent.getType())) { response.sendError(HttpServletResponse.SC_CONFLICT); return; } InputStream is = request.getInputStream(); OutputStream os = object.getContent().getOutputStream(); long bytesCopied = IOUtils.copyLarge(is, os); String contentLengthHeader = request.getHeader("Content-length"); LOG.debug(String.format("sent %d/%s bytes", bytesCopied, contentLengthHeader == null ? "unknown" : contentLengthHeader)); os.flush(); object.close(); response.setStatus(HttpServletResponse.SC_CREATED); }