Example usage for javax.servlet.http HttpServletResponse SC_CONFLICT

List of usage examples for javax.servlet.http HttpServletResponse SC_CONFLICT

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_CONFLICT.

Prototype

int SC_CONFLICT

To view the source code for javax.servlet.http HttpServletResponse SC_CONFLICT.

Click Source Link

Document

Status code (409) indicating that the request could not be completed due to a conflict with the current state of the resource.

Usage

From source file:de.tub.av.pe.xcapsrv.XCAPResultFactory.java

private static XCAPResult conflictSchemaValidation(String reason) {
    XCAPResult result = new XCAPResult();
    result.setStatusCode(HttpServletResponse.SC_CONFLICT);
    StringBuilder content = new StringBuilder(ERROR_DOCUMENT_PREFIX);
    content.append("<" + XDMSConstants.SCHEMA_VALIDATION_ERROR + ">");
    content.append(reason);/*from  w  w w .  j  a  va 2  s .  c o m*/
    content.append("</" + XDMSConstants.SCHEMA_VALIDATION_ERROR + ">");
    content.append(ERROR_DOCUMENT_SUFFIX);
    result.setBody(content.toString());
    result.setMimeType(XDMSConstants.MIME_TYPE_CONFLICT);
    return result;
}

From source file:com.surevine.alfresco.audit.integration.CreateWikiPageTest.java

/**
 * Test to ensure that when the user attempts to create a wiki page with the same name as another wiki page that the
 * attempt is audited as unsuccessful.//from   ww  w  .  j a  va  2  s.  c o  m
 */
@Test
public void testDuplicateDocumentCreationAttempt() {

    String pageName = "duplicate";
    String failureDetails = "Request could not be completed due to a conflict with the current state of the resource.";

    try {

        JSONObject request = new JSONObject();

        request.put(AlfrescoJSONKeys.PAGE, "wiki-page");
        request.put(AlfrescoJSONKeys.PAGETITLE, pageName);
        request.put(AlfrescoJSONKeys.PAGE_CONTENT, "<p>duplicate.</p>");

        JSONObject response = new JSONObject();
        JSONObject status = new JSONObject();
        status.put(AlfrescoJSONKeys.CODE, HttpServletResponse.SC_CONFLICT);
        status.put(AlfrescoJSONKeys.NAME, "Conflict");
        status.put(AlfrescoJSONKeys.DESCRIPTION, failureDetails);
        response.put("status", status);

        mockRequest.setRequestURI("/alfresco/s/slingshot/wiki/page/mytestsite/" + pageName);
        mockRequest.setMethod(cut.getMethod());
        mockRequest.setContent(request.toString().getBytes());
        mockResponse = new MockHttpServletResponse();

        mockChain = new ResponseModifiableMockFilterChain(response.toString(), HttpServletResponse.SC_CONFLICT);

        springAuditFilterBean.doFilter(mockRequest, mockResponse, mockChain);

        Auditable audited = getSingleAuditedEvent();

        assertEquals(false, audited.isSuccess());
        assertEquals(HttpStatus.CONFLICT.toString() + ": " + HttpStatus.CONFLICT.name(), audited.getDetails());

    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}

From source file:com.xpn.xwiki.web.ObjectRemoveAction.java

/**
 * {@inheritDoc}/*  w  w  w. j  av  a2  s .c o m*/
 * 
 * @see XWikiAction#render(XWikiContext)
 */
@Override
public String render(XWikiContext context) throws XWikiException {
    if (Utils.isAjaxRequest(context)) {
        XWikiResponse response = context.getResponse();
        response.setStatus(HttpServletResponse.SC_CONFLICT);
        response.setContentType("text/plain");
        try {
            response.getWriter().write("failed");
            response.setContentLength(6);
        } catch (IOException e) {
        }
        return null;
    } else {
        return "error";
    }
}

From source file:org.efaps.webdav4vfs.handler.AbstractCopyMoveBaseHandler.java

/**
 * Handle a COPY or MOVE request.//from w w w  .  ja v a  2  s  . c om
 *
 * @param _request      HTTP servlet request
 * @param _response     HTTP servlet response
 * @throws IOException if there is an error executing this request
 */
@Override
public void service(final HttpServletRequest _request, final HttpServletResponse _response) throws IOException {
    boolean overwrite = getOverwrite(_request);
    FileObject object = VFSBackend.resolveFile(_request.getPathInfo());
    FileObject targetObject = getDestination(_request);

    try {
        final LockManager lockManager = LockManager.getInstance();
        LockManager.EvaluationResult evaluation = lockManager.evaluateCondition(targetObject, getIf(_request));
        if (!evaluation.result) {
            _response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        }
        if ("MOVE".equals(_request.getMethod())) {
            evaluation = lockManager.evaluateCondition(object, getIf(_request));
            if (!evaluation.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;
    }

    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);
    }

    // delegate the actual execution to a sub class
    this.copyOrMove(object, targetObject, getDepth(_request));
}

From source file:aiai.ai.station.actors.DownloadResourceActor.java

public void fixedDelay() {
    if (globals.isUnitTesting) {
        return;/*from  ww w  . j  a  v  a  2 s.com*/
    }
    if (!globals.isStationEnabled) {
        return;
    }

    DownloadResourceTask task;
    while ((task = poll()) != null) {
        //            if (Boolean.TRUE.equals(preparedMap.get(task.getId()))) {
        //                continue;
        //            }
        AssetFile assetFile = StationResourceUtils.prepareResourceFile(task.targetDir, task.binaryDataType,
                task.id, null);
        if (assetFile.isError) {
            log.warn("Resource can't be downloaded. Asset file initialization was failed, {}", assetFile);
            continue;
        }
        if (assetFile.isContent) {
            log.info("Resource was already downloaded. Asset file: {}", assetFile.file.getPath());
            //                preparedMap.put(task.getId(), true);
            continue;
        }

        try {
            Request request = Request.Get(targetUrl + '/' + task.getBinaryDataType() + '/' + task.getId())
                    .connectTimeout(5000).socketTimeout(5000);

            Response response;
            if (globals.isSecureRestUrl) {
                response = executor.executor.execute(request);
            } else {
                response = request.execute();
            }
            response.saveContent(assetFile.file);

            //                preparedMap.put(task.getId(), true);
            log.info("Resource #{} was loaded", task.getId());
        } catch (HttpResponseException e) {
            if (e.getStatusCode() == HttpServletResponse.SC_GONE) {
                log.warn("Resource with id {} wasn't found", task.getId());
            } else if (e.getStatusCode() == HttpServletResponse.SC_CONFLICT) {
                log.warn("Resource with id {} is broken and need to be recreated", task.getId());
            } else {
                log.error("HttpResponseException.getStatusCode(): {}", e.getStatusCode());
                log.error("HttpResponseException", e);
            }
        } catch (SocketTimeoutException e) {
            log.error("SocketTimeoutException", e);
        } catch (IOException e) {
            log.error("IOException", e);
        }
    }
}

From source file:be.usgictprofessionals.usgfinancewebapp.restresources.RESTDataResources.java

/**
 *
 * @param response//ww w  . j a  va  2s . c  o m
 * @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 balans ratio oveview page.
 */
@GET
@Path("/balans/{id}")
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<BalansRatioData> getBalans(@Context final HttpServletResponse response,
        @PathParam("id") String id) {
    if (!DataDAO.getInstance().inputHasBeenReceived()) {
        response.setStatus(HttpServletResponse.SC_CONFLICT);
    }
    return DataDAO.getInstance().getBalans(Integer.parseInt(id));
}

From source file:org.mypackage.spring.controllers.EmailsSpringController.java

@RequestMapping(value = "/contacts/{id}/modify/new_email_submitted", method = RequestMethod.POST)
public ModelAndView postCreateNewEmail(@PathVariable String id, @RequestParam("address") String address,
        @RequestParam("category") String categoryValue, @RequestParam("contactId") String contactId) {
    ModelAndView modelAndView = new ModelAndView();
    try {/*w  w  w  .  ja va2 s.  c o  m*/
        int newEmailId = newEmailController.addNewEmail(address, categoryValue, id);
        modelAndView.addObject("emailId", newEmailId);
        modelAndView = contactsSpringController.getAContact(id);
        modelAndView.setViewName("redirect:/contacts/" + id + "/modify");
    } catch (DalException ex) {
        logger.error("An error occured while trying to add a new email for contact with ID = " + id
                + "Email object parameters: " + "/nAddress: " + address + "/nCategory value (enum): "
                + categoryValue + "/nfContactId: " + contactId, ex);
        modelAndView.addObject("errorCode", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        modelAndView.addObject("errorMessage", "An internal database error occured. Please try again.");
        modelAndView.setViewName("/errorPage.jsp");
    } catch (MalformedIdentifierException ex) {
        modelAndView.addObject("errorCode", HttpServletResponse.SC_BAD_REQUEST);
        modelAndView.addObject("errorMessage",
                "An error occured because of a malformed id." + id + " Please use only numeric values.");
        modelAndView.setViewName("/errorPage.jsp");
    } catch (MalformedCategoryException ex) {
        modelAndView.addObject("errorCode", HttpServletResponse.SC_CONFLICT);
        modelAndView.addObject("errorMessage",
                "An internal conflict concerning the category of the email occured. Please try again.");
        modelAndView.setViewName("/errorPage.jsp");
    } catch (DuplicateEmailException ex) {
        modelAndView = getCreateNewEmail(id);
        modelAndView.addObject("errorMessage", "This address already exists. Please enter a new one.");
    }
    return modelAndView;
}

From source file:de.tub.av.pe.xcapsrv.XCAPResultFactory.java

private static XCAPResult conflictNOTXmlFrag() {
    XCAPResult result = new XCAPResult();
    result.setStatusCode(HttpServletResponse.SC_CONFLICT);
    StringBuilder content = new StringBuilder(ERROR_DOCUMENT_PREFIX);
    content.append("<" + XDMSConstants.NOT_XML_FRAG + "/>");
    content.append(ERROR_DOCUMENT_SUFFIX);
    result.setBody(content.toString());/*www  .ja va2 s.  c  om*/
    result.setMimeType(XDMSConstants.MIME_TYPE_CONFLICT);
    return result;
}

From source file:org.piraso.server.spring.web.PirasoServletTest.java

@Test
public void testStopNotAliveService() throws Exception {
    request.addParameter("service", "stop");
    request.addParameter("preferences", mapper.writeValueAsString(new Preferences()));

    ResponseLoggerService service = mock(ResponseLoggerService.class);

    doReturn(false).when(service).isAlive();
    doReturn(service).when(registry).getLogger(Matchers.<User>any());

    servlet.handleRequest(request, response);

    assertEquals(HttpServletResponse.SC_CONFLICT, response.getStatus());

}

From source file:org.sakaiproject.sdata.tool.functions.JCRRevertFunction.java

/**
 * {@inheritDoc}// w ww .ja v  a  2 s  . co m
 *
 * @see org.sakaiproject.sdata.tool.api.SDataFunction#call(org.sakaiproject.sdata.tool.api.Handler,
 *      javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
 *      javax.jcr.Node, org.sakaiproject.sdata.tool.api.ResourceDefinition)
 */
public void call(Handler handler, HttpServletRequest request, HttpServletResponse response, Node target,
        ResourceDefinition rp) throws SDataException {
    try {
        SDataFunctionUtil.checkMethod(request.getMethod(), "POST");
        String revertVersion = request.getParameter(VERSION);
        if (StringUtils.isEmpty(revertVersion)) {
            throw new SDataException(HttpServletResponse.SC_BAD_REQUEST,
                    "You must provide a version to revert in the " + VERSION + " parameter");
        }

        if (target.isCheckedOut()) {
            try {
                target.restore(revertVersion, false);
                target.refresh(false);
            } catch (VersionException e) {
                throw new SDataException(HttpServletResponse.SC_CONFLICT,
                        "The requested version is not a previous version of this node, or the node is "
                                + "the root node, either way this operation is not possible. cause:"
                                + e.getMessage());

            } catch (UnsupportedRepositoryOperationException e) {
                throw new SDataException(HttpServletResponse.SC_CONFLICT,
                        "The resource cannot be versioned " + e.getMessage());

            }
            response.setStatus(HttpServletResponse.SC_OK);
            JCRNodeMap nm = new JCRNodeMap(target, rp.getDepth(), rp);
            try {
                handler.sendMap(request, response, nm);
            } catch (IOException e) {
                throw new SDataException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                        "IO Error " + e.getMessage());
            }
        } else {
            throw new SDataException(HttpServletResponse.SC_CONFLICT, "The resource is already checked in");

        }

    } 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());
    }

}