List of usage examples for javax.servlet.http HttpServletResponse SC_CONFLICT
int SC_CONFLICT
To view the source code for javax.servlet.http HttpServletResponse SC_CONFLICT.
Click Source Link
From source file:de.tub.av.pe.xcapsrv.XCAPResultFactory.java
private static XCAPResult conflictNoParent() { XCAPResult result = new XCAPResult(); result.setStatusCode(HttpServletResponse.SC_CONFLICT); StringBuilder content = new StringBuilder(ERROR_DOCUMENT_PREFIX); content.append("<" + XDMSConstants.NO_PARENT + "/>"); content.append(ERROR_DOCUMENT_SUFFIX); result.setBody(content.toString());/*from w w w . j a v a2 s .c o m*/ result.setMimeType(XDMSConstants.MIME_TYPE_CONFLICT); return result; //To change body of created methods use File | Settings | File Templates. }
From source file:be.usgictprofessionals.usgfinancewebapp.restresources.RESTDataResources.java
/** * * @param response//from w ww . ja v a 2 s. c om * @param id * @return XmlRootElement class which will automatically be translated into * JSON. 409 error code will be send if there hasn't been any input * get the data required for the coverage ratio overview page */ @GET @Path("/coverage/{id}") @Produces(MediaType.APPLICATION_JSON) public ArrayList<CoverageRatioData> getCoverage(@Context final HttpServletResponse response, @PathParam("id") String id) { if (!DataDAO.getInstance().inputHasBeenReceived()) { response.setStatus(HttpServletResponse.SC_CONFLICT); } return DataDAO.getInstance().getCoverage(Integer.parseInt(id)); }
From source file:oscar.oscarLab.ca.all.pageUtil.LabUploadAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {/*w w w .ja v a2 s. c o m*/ LabUploadForm frm = (LabUploadForm) form; FormFile importFile = frm.getImportFile(); String signature = request.getParameter("signature"); String key = request.getParameter("key"); String service = request.getParameter("service"); String outcome = ""; String audit = ""; Integer httpCode = 200; ArrayList<Object> clientInfo = getClientInfo(service); PublicKey clientKey = (PublicKey) clientInfo.get(0); String type = (String) clientInfo.get(1); try { InputStream is = decryptMessage(importFile.getInputStream(), key, clientKey); String fileName = importFile.getFileName(); String filePath = Utilities.saveFile(is, fileName); importFile.getInputStream().close(); File file = new File(filePath); if (validateSignature(clientKey, signature, file)) { logger.debug("Validated Successfully"); MessageHandler msgHandler = HandlerClassFactory.getHandler(type); if (type.equals("HHSEMR") && OscarProperties.getInstance() .getProperty("lab.hhsemr.filter_ordering_provider", "false").equals("true")) { logger.info("Applying filter to HHS EMR lab"); String hl7Data = FileUtils.readFileToString(file, "UTF-8"); HHSEmrDownloadHandler filterHandler = new HHSEmrDownloadHandler(); filterHandler.init(hl7Data); OtherId providerOtherId = OtherIdManager.searchTable(OtherIdManager.PROVIDER, "STAR", filterHandler.getClientRef()); if (providerOtherId == null) { logger.info("Filtering out this message, as we don't have client ref " + filterHandler.getClientRef() + " in our database (" + file + ")"); outcome = "uploaded"; request.setAttribute("outcome", outcome); return mapping.findForward("success"); } } is = new FileInputStream(file); try { int check = FileUploadCheck.addFile(file.getName(), is, "0"); if (check != FileUploadCheck.UNSUCCESSFUL_SAVE) { if ((audit = msgHandler.parse(service, filePath, check)) != null) { outcome = "uploaded"; httpCode = HttpServletResponse.SC_OK; } else { outcome = "upload failed"; httpCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } else { outcome = "uploaded previously"; httpCode = HttpServletResponse.SC_CONFLICT; } } finally { is.close(); } } else { logger.info("failed to validate"); outcome = "validation failed"; httpCode = HttpServletResponse.SC_NOT_ACCEPTABLE; } } catch (Exception e) { MiscUtils.getLogger().error("Error", e); outcome = "exception"; httpCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } request.setAttribute("outcome", outcome); request.setAttribute("audit", audit); if (request.getParameter("use_http_response_code") != null) { try { response.sendError(httpCode, outcome); } catch (IOException e) { logger.error("Error", e); } return (null); } else return mapping.findForward("success"); }
From source file:cf.spring.servicebroker.ServiceBrokerHandler.java
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!authenticator.authenticate(request, response)) { return;/* w w w . ja va2 s . com*/ } ApiVersionValidator.validateApiVersion(request); try { response.setContentType(Constants.JSON_CONTENT_TYPE); final Matcher matcher = URI_PATTERN.matcher(request.getRequestURI()); if (!matcher.matches()) { throw new NotFoundException("Resource not found"); } final String instanceId = matcher.group(1); final String bindingId = matcher.group(3); if ("put".equalsIgnoreCase(request.getMethod())) { if (bindingId == null) { final ProvisionBody provisionBody = mapper.readValue(request.getInputStream(), ProvisionBody.class); final String serviceId = provisionBody.getServiceId(); final BrokerServiceAccessor accessor = getServiceAccessor(serviceId); final ProvisionRequest provisionRequest = new ProvisionRequest(UUID.fromString(instanceId), provisionBody.getPlanId(), provisionBody.getOrganizationGuid(), provisionBody.getSpaceGuid()); final ProvisionResponse provisionResponse = accessor.provision(provisionRequest); if (provisionResponse.isCreated()) { response.setStatus(HttpServletResponse.SC_CREATED); } mapper.writeValue(response.getOutputStream(), provisionResponse); } else { final BindBody bindBody = mapper.readValue(request.getInputStream(), BindBody.class); final String serviceId = bindBody.getServiceId(); final BrokerServiceAccessor accessor = getServiceAccessor(serviceId); final BindRequest bindRequest = new BindRequest(UUID.fromString(instanceId), UUID.fromString(bindingId), bindBody.applicationGuid, bindBody.getPlanId()); final BindResponse bindResponse = accessor.bind(bindRequest); if (bindResponse.isCreated()) { response.setStatus(HttpServletResponse.SC_CREATED); } mapper.writeValue(response.getOutputStream(), bindResponse); } } else if ("delete".equalsIgnoreCase(request.getMethod())) { final String serviceId = request.getParameter(SERVICE_ID_PARAM); final String planId = request.getParameter(PLAN_ID_PARAM); final BrokerServiceAccessor accessor = getServiceAccessor(serviceId); try { if (bindingId == null) { // Deprovision final DeprovisionRequest deprovisionRequest = new DeprovisionRequest( UUID.fromString(instanceId), planId); accessor.deprovision(deprovisionRequest); } else { // Unbind final UnbindRequest unbindRequest = new UnbindRequest(UUID.fromString(bindingId), UUID.fromString(instanceId), planId); accessor.unbind(unbindRequest); } } catch (MissingResourceException e) { response.setStatus(HttpServletResponse.SC_GONE); } response.getWriter().write("{}"); } else { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } } catch (ConflictException e) { response.setStatus(HttpServletResponse.SC_CONFLICT); response.getWriter().write("{}"); } catch (ServiceBrokerException e) { LOGGER.warn("An error occurred processing a service broker request", e); response.setStatus(e.getHttpResponseCode()); mapper.writeValue(response.getOutputStream(), new ErrorBody(e.getMessage())); } catch (Throwable e) { LOGGER.error(e.getMessage(), e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); mapper.writeValue(response.getOutputStream(), new ErrorBody(e.getMessage())); } }
From source file:de.tub.av.pe.xcapsrv.XCAPResultFactory.java
private static XCAPResult conflictConstraintFailure() { XCAPResult result = new XCAPResult(); result.setStatusCode(HttpServletResponse.SC_CONFLICT); StringBuilder content = new StringBuilder(ERROR_DOCUMENT_PREFIX); content.append("<" + XDMSConstants.CONSTRAINT_FAILURE + "/>"); content.append(ERROR_DOCUMENT_SUFFIX); result.setBody(content.toString());/*from w w w . ja v a 2 s . c o m*/ result.setMimeType(XDMSConstants.MIME_TYPE_CONFLICT); return result; }
From source file:org.sakaiproject.sdata.tool.functions.JCRCopyFunction.java
public void call(Handler handler, HttpServletRequest request, HttpServletResponse response, Node target, ResourceDefinition rp) throws SDataException { try {//from w ww .j a v a 2s . co m SDataFunctionUtil.checkMethod(request.getMethod(), "POST"); String targetPath = request.getParameter(TO); if (targetPath == null || targetPath.trim().length() == 0) { throw new SDataException(HttpServletResponse.SC_BAD_REQUEST, "No Target folder for the copy specified "); } String repositoryTargetPath = targetPath; String repositorySourcePath = rp.getRepositoryPath(); LOG.info("Copying " + repositorySourcePath + " to " + repositoryTargetPath + " specified by " + targetPath); Session session = jcrService.getSession(); // create the parent if it doesnt exist. String targetParent = PathUtils.getParentReference(targetPath); Node targetNode = null; try { targetNode = jcrNodeFactoryService.getNode(targetPath); } catch (JCRNodeFactoryServiceException e) { if (debug) LOG.debug("Node Does not exist "); } if (targetNode == null) { targetNode = jcrNodeFactoryService.createFolder(targetParent); // the node *must* be saved to make it available to the move. targetNode.getParent().save(); } Workspace workspace = session.getWorkspace(); workspace.copy(repositorySourcePath, repositoryTargetPath); Node n = jcrNodeFactoryService.getNode(repositoryTargetPath); response.setStatus(HttpServletResponse.SC_OK); JCRNodeMap nm = new JCRNodeMap(n, rp.getDepth(), rp); try { handler.sendMap(request, response, nm); } catch (IOException e) { throw new SDataException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "IO Error " + e.getMessage()); } } catch (AccessDeniedException e) { throw new SDataAccessException(HttpServletResponse.SC_FORBIDDEN, e.getMessage()); } catch (ItemExistsException e) { throw new SDataAccessException(HttpServletResponse.SC_CONFLICT, e.getMessage()); } catch (PathNotFoundException e) { throw new SDataAccessException(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); } catch (VersionException e) { throw new SDataAccessException(HttpServletResponse.SC_CONFLICT, e.getMessage()); } catch (ConstraintViolationException e) { throw new SDataAccessException(HttpServletResponse.SC_CONFLICT, e.getMessage()); } catch (LockException e) { throw new SDataAccessException(HttpServletResponse.SC_CONFLICT, e.getMessage()); } catch (RepositoryException e) { throw new SDataAccessException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } catch (JCRNodeFactoryServiceException e) { throw new SDataAccessException(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); } }
From source file:org.sakaiproject.sdata.tool.functions.JCRMoveFunction.java
public void call(Handler handler, HttpServletRequest request, HttpServletResponse response, Node target, ResourceDefinition rp) throws SDataException { try {//from ww w.j a v a 2s. c o m SDataFunctionUtil.checkMethod(request.getMethod(), "POST"); String targetPath = request.getParameter(TO); if (targetPath == null || targetPath.trim().length() == 0) { throw new SDataException(HttpServletResponse.SC_BAD_REQUEST, "No Target folder for the move specified "); } String repositoryTargetPath = targetPath; String repositorySourcePath = rp.getRepositoryPath(); LOG.info("Moving " + repositorySourcePath + " to " + repositoryTargetPath + " specified by " + targetPath); Session session = jcrService.getSession(); // create the parent if it doesnt exist. String targetParent = PathUtils.getParentReference(targetPath); Node targetNode = null; try { targetNode = jcrNodeFactoryService.getNode(targetPath); } catch (JCRNodeFactoryServiceException e) { if (debug) LOG.debug("Node Does not exist "); } if (targetNode == null) { targetNode = jcrNodeFactoryService.createFolder(targetParent); // the node *must* be saved to make it available to the move. targetNode.getParent().save(); } Workspace workspace = session.getWorkspace(); workspace.move(repositorySourcePath, repositoryTargetPath); Node n = jcrNodeFactoryService.getNode(repositoryTargetPath); response.setStatus(HttpServletResponse.SC_OK); JCRNodeMap nm = new JCRNodeMap(n, rp.getDepth(), rp); try { handler.sendMap(request, response, nm); } catch (IOException e) { throw new SDataException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "IO Error " + e.getMessage()); } } catch (AccessDeniedException e) { e.printStackTrace(); throw new SDataAccessException(HttpServletResponse.SC_FORBIDDEN, e.getMessage()); } catch (ItemExistsException e) { e.printStackTrace(); throw new SDataAccessException(HttpServletResponse.SC_CONFLICT, e.getMessage()); } catch (PathNotFoundException e) { e.printStackTrace(); throw new SDataAccessException(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); } catch (VersionException e) { e.printStackTrace(); throw new SDataAccessException(HttpServletResponse.SC_CONFLICT, e.getMessage()); } catch (ConstraintViolationException e) { e.printStackTrace(); throw new SDataAccessException(HttpServletResponse.SC_CONFLICT, e.getMessage()); } catch (LockException e) { e.printStackTrace(); throw new SDataAccessException(HttpServletResponse.SC_CONFLICT, e.getMessage()); } catch (RepositoryException e) { e.printStackTrace(); throw new SDataAccessException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } catch (JCRNodeFactoryServiceException e) { e.printStackTrace(); throw new SDataAccessException(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); } }
From source file:com.axway.ats.testexplorer.pages.testcase.attachments.AttachmentsServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Object checkContextAttribute = request.getSession().getServletContext() .getAttribute(ContextListener.getAttachedFilesDir()); // check if ats-attached-files property is set if (checkContextAttribute == null) { LOG.error(/*from www .j a v a 2 s . c o m*/ "No attached files could be attached. \nPossible reason could be Tomcat 'CATALINA_HOME' or 'CATALINA_BASE' is not set."); } else { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // Check that we have a file upload request if (!ServletFileUpload.isMultipartContent(request)) { out.println("<html>"); out.println("<head>"); out.println("<title>Servlet upload</title>"); out.println("</head>"); out.println("<body>"); out.println("<p>No file uploaded</p>"); out.println("</body>"); out.println("</html>"); return; } repoFilesDir = checkContextAttribute.toString(); DiskFileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // fileitem containing information about the attached file FileItem fileItem = null; FileItem currentElement = null; String dbName = ""; String attachedFile = ""; int runId = 0; int suiteId = 0; int testcaseId = 0; try { // Parse the request to get file items. List<?> fileItems = upload.parseRequest(request); // Process the uploaded file items Iterator<?> i = fileItems.iterator(); while (i.hasNext()) { currentElement = (FileItem) i.next(); // check if this is the attached file if ("upfile".equals(currentElement.getFieldName())) { fileItem = currentElement; attachedFile = getFileSimpleName(fileItem.getName()); if (attachedFile == null) { break; } } else if ("dbName".equals(currentElement.getFieldName())) { if (!StringUtils.isNullOrEmpty(currentElement.getString())) dbName = currentElement.getString(); } else if ("runId".equals(currentElement.getFieldName())) { runId = getIntValue(currentElement.getString()); } else if ("suiteId".equals(currentElement.getFieldName())) { suiteId = getIntValue(currentElement.getString()); } else if ("testcaseId".equals(currentElement.getFieldName())) { testcaseId = getIntValue(currentElement.getString()); } } // check if all values are valid if (!StringUtils.isNullOrEmpty(attachedFile) && !StringUtils.isNullOrEmpty(dbName) && runId > 0 && suiteId > 0 && testcaseId > 0) { // copy the attached file to the corresponding directory File file = createAttachedFileDir(attachedFile, dbName, runId, suiteId, testcaseId); fileItem.write(file); out.println("File uploaded to testcase " + testcaseId); } else { StringBuilder sb = new StringBuilder(); if (StringUtils.isNullOrEmpty(attachedFile)) { sb.append("Attached file name is null or empty!"); out.println(sb.toString()); } if (StringUtils.isNullOrEmpty(dbName)) { sb.append("Database name is null of empty!"); out.println(sb.toString()); } if (runId <= 0) { sb.append("RunId \"" + runId + "\" is not valid!"); out.println(sb.toString()); } if (suiteId <= 0) { sb.append("SuiteId \"" + suiteId + "\" is not valid!"); out.println(sb.toString()); } if (testcaseId <= 0) { sb.append("TestcaseId \"" + testcaseId + "\" is not valid!"); out.println(sb.toString()); } response.sendError(HttpServletResponse.SC_CONFLICT, sb.toString()); LOG.error("The file could not be attached to the test!"); } } catch (Exception ex) { String errMsg = ex.getMessage(); if (errMsg == null) { errMsg = ex.getClass().getSimpleName(); } response.sendError(HttpServletResponse.SC_CONFLICT, ExceptionUtils.getExceptionMsg(ex)); LOG.error("The file was unable to be attached to the testcase! ", ex); } finally { out.close(); } } }
From source file:org.piraso.server.spring.web.PirasoServlet.java
private void stopService(HttpServletResponse response, User user) throws IOException { ResponseLoggerService service = getRegistry().getLogger(user); if (service == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, String.format("Service for user '%s' not found.", user.toString())); return;// w w w .ja va 2s . c o m } if (!service.isAlive()) { response.sendError(HttpServletResponse.SC_CONFLICT, String.format("Service for user '%s' not active.", user.toString())); getRegistry().removeUser(user); return; } try { // gracefully stop the service service.stopAndWait(stopTimeout); if (service.isAlive()) { response.sendError(HttpServletResponse.SC_REQUEST_TIMEOUT, String.format("Service for user '%s' stop timeout.", user.toString())); } } catch (InterruptedException ignored) { } }
From source file:de.tub.av.pe.xcapsrv.XCAPResultFactory.java
private static XCAPResult conflictInsert() { XCAPResult result = new XCAPResult(); result.setStatusCode(HttpServletResponse.SC_CONFLICT); StringBuilder content = new StringBuilder(ERROR_DOCUMENT_PREFIX); content.append("<" + XDMSConstants.CANNOT_INSERT + "/>"); content.append(ERROR_DOCUMENT_SUFFIX); result.setBody(content.toString());//from www.j a va2s. c o m result.setMimeType(XDMSConstants.MIME_TYPE_CONFLICT); return result; }