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:com.zuoxiaolong.blog.web.controller.WebUserController.java

@RequestMapping(value = "/CheckUsername", method = RequestMethod.GET)
public void checkUsername(String username) throws IOException {
    JsonResponse jsonResponse = invokeApi(Api.WebUser_CheckUsername,
            CollectionUtils.newMap("username", username));
    if (jsonResponse.success() && (boolean) jsonResponse.getData()) {
        renderJson("success");
    } else {//from  w  w  w.j  a  v a 2 s . com
        getResponse().sendError(HttpServletResponse.SC_CONFLICT);
    }
}

From source file:com.thinkberg.moxo.dav.MkColHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (request.getReader().readLine() != null) {
        response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        return;/*from   w w  w . ja  v a 2s. c  o  m*/
    }

    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    try {
        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 (object.exists()) {
        response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }

    if (!object.getParent().exists() || !FileType.FOLDER.equals(object.getParent().getType())) {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        return;
    }

    try {
        object.createFolder();
        response.setStatus(HttpServletResponse.SC_CREATED);
    } catch (FileSystemException e) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
    }
}

From source file:com.thinkberg.moxo.dav.PutHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    try {// w  ww  . j  a  v a2s . co m
        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;
    }

    // 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();
    log("PUT sends " + request.getHeader("Content-length") + " bytes");
    log("PUT copied " + Util.copyStream(is, os) + " bytes");
    os.flush();
    object.close();

    response.setStatus(HttpServletResponse.SC_CREATED);
}

From source file:org.pixmob.freemobile.netstat.gae.web.v1.DeviceService.java

@Put
public Reply<?> register(Request req, @Named("id") String deviceId) {
    final DeviceReg devReg = req.read(DeviceReg.class).as(Json.class);
    devReg.brand = StringUtils.trimToNull(devReg.brand);
    devReg.model = StringUtils.trimToNull(devReg.model);

    logger.fine("Trying to register device: " + devReg);

    try {//from  www.j  av a2  s . c o m
        dr.create(deviceId, devReg.brand, devReg.model);
    } catch (DeviceException e) {
        logger.log(Level.WARNING, "Failed to register device " + deviceId, e);
        return Reply.with(e.getMessage()).status(HttpServletResponse.SC_CONFLICT);
    }

    logger.info("Device registered");

    return Reply.saying().status(HttpServletResponse.SC_CREATED);
}

From source file:net.sourceforge.vulcan.web.struts.actions.ManageLocksAction.java

public ActionForward lock(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    final MultipleProjectConfigForm configForm = (MultipleProjectConfigForm) form;

    if (configForm.getProjectNames() == null || configForm.getProjectNames().length == 0) {
        saveError(request, "projectNames", new ActionMessage("errors.required"));
        return mapping.getInputForward();
    }/*from  ww  w  .j a  v a 2s. c o m*/

    try {
        if (buildManager.isBuildingOrInQueue(configForm.getProjectNames())) {
            request.setAttribute("restResponseCode", HttpServletResponse.SC_CONFLICT);
            saveError(request, ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.cannot.lock.project"));
            return mapping.findForward("failure");
        }

        String message = configForm.getMessage();
        if (StringUtils.isBlank(message)) {
            message = formatMessage("messages.project.locked.by.user", getUsername(request), new Date());
        }

        final long lockId = stateManager.lockProjects(message, configForm.getProjectNames());
        request.setAttribute("lockId", lockId);

        saveSuccessMessage(request);
        return mapping.findForward("success");
    } catch (NoSuchProjectException e) {
        saveError(request, "projectNames", new ActionMessage("errors.no.such.project", e.getMessage()));
        return mapping.getInputForward();
    }
}

From source file:com.thinkberg.webdav.MkColHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    BufferedReader bufferedReader = request.getReader();
    String line = bufferedReader.readLine();
    if (line != null) {
        response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        return;/*from ww  w  .j av a  2s .  c o m*/
    }

    FileObject object = VFSBackend.resolveFile(request.getPathInfo());

    try {
        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;
    }

    if (object.exists()) {
        response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }

    if (!object.getParent().exists() || !FileType.FOLDER.equals(object.getParent().getType())) {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        return;
    }

    try {
        object.createFolder();
        response.setStatus(HttpServletResponse.SC_CREATED);
    } catch (FileSystemException e) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
    }
}

From source file:org.nuxeo.ecm.automation.jaxrs.ExceptionHandler.java

public static int getStatus(Throwable cause, int depth) {
    if (depth == 0) {
        log.warn("Possible infinite loop! Check the exception wrapping.");
        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }//from  w w  w  .  ja va  2 s .com
    if ((cause instanceof DocumentSecurityException) || (cause instanceof SecurityException)
            || "javax.ejb.EJBAccessException".equals(cause.getClass().getName())) {
        return HttpServletResponse.SC_FORBIDDEN;
    } else if (cause instanceof NoSuchDocumentException) {
        return HttpServletResponse.SC_NOT_FOUND;
    } else if (cause instanceof OperationNotFoundException) {
        return HttpServletResponse.SC_NOT_FOUND;
    } else if (cause instanceof ConflictOperationException) {
        return HttpServletResponse.SC_CONFLICT;
    } else if (cause instanceof InvalidOperationException) {
        return HttpServletResponse.SC_BAD_REQUEST;
    }
    Throwable parent = cause.getCause();
    if (parent == cause) {
        log.warn("Infinite loop detected! Check the exception wrapping.");
        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }
    if (parent != null) {
        return getStatus(parent, depth - 1);
    }
    if (cause.getMessage() != null
            && cause.getMessage().contains("org.nuxeo.ecm.core.model.NoSuchDocumentException")) {
        log.warn("Badly wrapped exception: found a NoSuchDocumentException"
                + " message but no NoSuchDocumentException", cause);
        return HttpServletResponse.SC_NOT_FOUND;
    }
    return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
}

From source file:com.thinkberg.webdav.PutHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = VFSBackend.resolveFile(request.getPathInfo());

    try {// w  w w. ja  v a 2 s .  c o  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 = 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.nuxeo.ecm.automation.server.jaxrs.ExceptionHandler.java

public static int getStatus(Throwable cause, int depth) {
    if (depth == 0) {
        log.warn("Possible infinite loop! Check the exception wrapping.");
        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }/*from  w w w  .  j  ava  2 s .  c  o m*/
    if ((cause instanceof DocumentSecurityException) || (cause instanceof SecurityException)
            || "javax.ejb.EJBAccessException".equals(cause.getClass().getName())) {
        return HttpServletResponse.SC_FORBIDDEN;
    } else if (cause instanceof NoSuchDocumentException) {
        return HttpServletResponse.SC_NOT_FOUND;
    } else if (cause instanceof OperationNotFoundException) {
        return HttpServletResponse.SC_NOT_FOUND;
    } else if (cause instanceof ConflictOperationException) {
        return HttpServletResponse.SC_CONFLICT;
    } else if (cause instanceof InvalidOperationException) {
        return HttpServletResponse.SC_BAD_REQUEST;
    }
    Throwable parent = cause.getCause();
    if (parent == cause) {
        log.warn("Infinite loop detected! Check the exception wrapping.");
        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }
    if (parent != null) {
        return getStatus(parent, depth - 1);
    }
    if (cause.getMessage() != null
            && cause.getMessage().contains("org.nuxeo.ecm.core.model.NoSuchDocumentException")) {
        log.warn("Badly wrapped exception: found a NoSuchDocumentException"
                + " message but no NoSuchDocumentException", cause);
        return HttpServletResponse.SC_NOT_FOUND;
    }
    if (cause instanceof ClientException) {
        // Generic ClientException with no root cause
        return HttpServletResponse.SC_BAD_REQUEST;
    }
    return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
}

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

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    BufferedReader bufferedReader = request.getReader();
    String line = bufferedReader.readLine();
    if (line != null) {
        response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        return;/*  ww  w .  ja  v a  2s.  c  o  m*/
    }

    FileObject object = VFSBackend.resolveFile(request.getPathInfo());

    try {
        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;
    }

    if (object.exists()) {
        response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }

    if (!object.getParent().exists() || !FileType.FOLDER.equals(object.getParent().getType())) {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        return;
    }

    try {
        object.createFolder();
        response.setStatus(HttpServletResponse.SC_CREATED);
    } catch (FileSystemException e) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
    }
}