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:be.usgictprofessionals.usgfinancewebapp.restresources.RESTDataResources.java

/**
 *
 * @param data//from www  .  ja  v  a2 s .c om
 * @param response
 * 409 error code will be send if there hasn't been any input
 * send in the data from the input fields for the WCM savings page
 * get the calculated data to fill in the non-init non-input fields
 * @param id
 * @return 
 */
@POST
@Path("/wcm/{id}/{year}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public WCMData enterWCMData(WCMData data, @Context final HttpServletResponse response,
        @PathParam("id") String id, @PathParam("year") String year) {
    if (!DataDAO.getInstance().inputHasBeenReceived()) {
        response.setStatus(HttpServletResponse.SC_CONFLICT);
    }
    return DataDAO.getInstance().getCalcDataWCM(data, Integer.parseInt(id), Integer.parseInt(year));
}

From source file:org.apache.hadoop.hbase.rest.Status.java

public void setExists(boolean error) {
    this.statusCode = HttpServletResponse.SC_CONFLICT;
    this.message = new StatusMessage(statusCode, error, "table already exists");
}

From source file:com.enjoyxstudy.selenium.autoexec.CommandHandler.java

/**
 * run command./*from   ww w  .ja va2  s  .  c om*/
 *
 * @param type
 * @param response
 * @throws Exception
 */
private void commandRun(String type, HttpResponse response) throws Exception {

    if (autoExecServer.getStatus() == AutoExecServer.STATUS_IDLE) {
        // idle
        MultiHTMLSuiteRunner runner = autoExecServer.process();

        String responseText;
        if (type.equals(TYPE_TEXT)) {
            // text
            StringBuilder stringBuilder = new StringBuilder();

            addResultString(stringBuilder, runner, false);
            responseText = stringBuilder.toString();
        } else {
            // json
            JSONObject json = new JSONObject();

            addResultJSON(json, runner, false);
            responseText = json.toString();
        }
        toResponse(response, responseText, type);
    } else {
        // running
        response.setStatus(HttpServletResponse.SC_CONFLICT);
        resultToResponse(response, DUPLICATE, type);
    }

}

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

private static XCAPResult conflictDelete() {
    XCAPResult result = new XCAPResult();
    result.setStatusCode(HttpServletResponse.SC_CONFLICT);
    StringBuilder content = new StringBuilder(ERROR_DOCUMENT_PREFIX);
    content.append("<" + XDMSConstants.CANNOT_DELETE + "/>");
    content.append(ERROR_DOCUMENT_SUFFIX);
    result.setBody(content.toString());//from  w ww . ja va2 s .  c o  m
    result.setMimeType(XDMSConstants.MIME_TYPE_CONFLICT);
    return result;
}

From source file:org.ebayopensource.turmeric.policy.adminui.server.PlcImportServlet.java

@SuppressWarnings("unchecked")
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    String result = (String) request.getAttribute("RESULT");
    Boolean error = (Boolean) request.getAttribute("ERROR");

    if (result == null && error == null) {

        String tmp = request.getRequestURI();

        if (request.getQueryString() == null) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid or empty url");
        } else {/*from   w  w  w  .  ja  va 2  s .c  om*/
            tmp += "?";
        }

        // eg: admin&admin
        String[] params = request.getQueryString().split("&");
        if (params.length < 2) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid url: " + request.getQueryString());
        }

        final ByteArrayOutputStream importData = parseInputStream(request, response);

        try {

            final BasePolicyServiceConsumer consumer = new BasePolicyServiceConsumer();
            consumer.getService().getInvokerOptions().setTransportName("HTTP11");
            consumer.getService().setSessionTransportHeader(SECURITY_TOKEN_HEADER, SECURITY_TOKEN);

            if (importData != null) {

                if (tmp.startsWith(impPolicyPrefix)) {

                    String partialURL = getPartialUrl("createPolicy", RequestFormat.JSON, params);

                    URL url = new URL(
                            policyServiceURL + tmp.substring(impPolicyPrefix.length()).toString() + partialURL);

                    consumer.getService().setServiceLocation(url);

                    PolicySet policySet = unmarshalXmlPolicyData(importData);
                    StringBuffer policiesNotStored = new StringBuffer();

                    if (policySet.getPolicy().isEmpty()) {
                        response.sendError(HttpServletResponse.SC_NOT_FOUND, "No policies to import");
                    }

                    CreatePolicyResponse createPolicyResponse;

                    for (Policy policy : policySet.getPolicy()) {
                        policy.setPolicyId(null);

                        if ("RL".equalsIgnoreCase(policy.getPolicyType())) {
                            List<Rule> rules = policy.getRule();
                            for (Rule rule : rules) {
                                rule.setRuleName(policy.getPolicyName());
                            }
                        }
                        CreatePolicyRequest createPolicyRequest = new CreatePolicyRequest();
                        createPolicyRequest.setPolicy(policy);
                        createPolicyResponse = (CreatePolicyResponse) consumer.getService()
                                .createDispatch("createPolicy").invoke(createPolicyRequest);

                        if (createPolicyResponse.getErrorMessage() != null) {
                            policiesNotStored.append(policy.getPolicyName() + ": ");
                            for (CommonErrorData error2 : createPolicyResponse.getErrorMessage().getError()) {
                                policiesNotStored.append(error2.getMessage() + "\n");
                            }
                        }
                    }

                    if (policiesNotStored.length() > 0) {
                        response.sendError(HttpServletResponse.SC_CONFLICT,
                                "The following policies have not been stored: \n"
                                        + policiesNotStored.toString());
                    }

                } else if (tmp.startsWith(impSGPrefix)) {

                    String partialURL = getPartialUrl("createSubjectGroups", RequestFormat.JSON, params);

                    URL url = new URL(
                            policyServiceURL + tmp.substring(impSGPrefix.length()).toString() + partialURL);

                    consumer.getService().setServiceLocation(url);

                    List<SubjectGroup> subjectGroups = unmarshalXmlSGData(importData);
                    StringBuffer sgNotStored = new StringBuffer();

                    if (subjectGroups.isEmpty()) {
                        response.sendError(HttpServletResponse.SC_NOT_FOUND, "No Subject Group to import");
                    }

                    CreateSubjectGroupsResponse createSGResponse;
                    for (SubjectGroup subjectGroup : subjectGroups) {
                        subjectGroup.setSubjectMatch(null);

                        CreateSubjectGroupsRequest createSGRequest = new CreateSubjectGroupsRequest();
                        createSGRequest.getSubjectGroups().add(subjectGroup);
                        createSGResponse = consumer.createSubjectGroups(createSGRequest);

                        if (createSGResponse.getErrorMessage() != null) {
                            sgNotStored.append(subjectGroup.getSubjectGroupName() + ": ");
                            for (CommonErrorData error2 : createSGResponse.getErrorMessage().getError()) {
                                sgNotStored.append(error2.getMessage() + "\n");
                            }
                        }
                    }

                    if (sgNotStored.length() > 0) {
                        response.sendError(HttpServletResponse.SC_CONFLICT,
                                "The following Subject Groups have not been stored: \n"
                                        + sgNotStored.toString());
                    }

                } else {
                    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid url for download: " + tmp);
                    return;
                }

                return;
            }
        } catch (JAXBException e) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to parse imported file");

        } catch (ServiceException e1) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to invoke PolicyService");

        }
    }

    if (error != null) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }

}

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

/**
 *
 * @param response// w  w w. j  a v a2  s  . co 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 to fill in the non-input fields on the WCM
 * savings page
 */
@GET
@Path("/wcm/{id}/{year}")
@Produces(MediaType.APPLICATION_JSON)
public WCMData getWCMData(@Context final HttpServletResponse response, @PathParam("id") String id,
        @PathParam("year") String year) {
    if (!DataDAO.getInstance().inputHasBeenReceived()) {
        response.setStatus(HttpServletResponse.SC_CONFLICT);
    }
    return DataDAO.getInstance().getInitData(Integer.parseInt(id), Integer.parseInt(year));
}

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

private void logError(String snippetCode, HttpResponseException e) {
    if (e.getStatusCode() == HttpServletResponse.SC_GONE) {
        log.warn("Snippet with code {} wasn't found", snippetCode);
    } else if (e.getStatusCode() == HttpServletResponse.SC_CONFLICT) {
        log.warn("Snippet with id {} is broken and need to be recreated", snippetCode);
    } else {/*from  w w w .ja v a2 s.  c  o  m*/
        log.error("HttpResponseException", e);
    }
}

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

private static XCAPResult conflictNOTUTF8() {
    XCAPResult result = new XCAPResult();
    result.setStatusCode(HttpServletResponse.SC_CONFLICT);
    StringBuilder content = new StringBuilder(ERROR_DOCUMENT_PREFIX);
    content.append("<" + XDMSConstants.NOT_UTF_8 + "/>");
    content.append(ERROR_DOCUMENT_SUFFIX);
    result.setBody(content.toString());/*from  ww w . java  2 s  .  c  o  m*/
    result.setMimeType(XDMSConstants.MIME_TYPE_CONFLICT);
    return result;
}

From source file:org.apache.hadoop.hbase.rest.Status.java

public void setConflict(Object message) {
    this.statusCode = HttpServletResponse.SC_CONFLICT;
    this.message = new StatusMessage(statusCode, true, message);
}

From source file:com.enjoyxstudy.selenium.autoexec.CommandHandler.java

/**
 * run async command.//from   w  w  w .  j a va2s  . c o m
 *
 * @param type
 * @param response
 * @throws IOException
 */
private void commandRunAsync(String type, HttpResponse response) throws IOException {

    if (autoExecServer.getStatus() == AutoExecServer.STATUS_IDLE) {
        // idle
        new Thread(new Runnable() {
            public void run() {
                try {
                    autoExecServer.process();
                } catch (Exception e) {
                    log.error("Error exec process.", e);
                }
            }
        }).start();

        response.setStatus(HttpServletResponse.SC_ACCEPTED);
        resultToResponse(response, SUCCESS, type);

    } else {
        // running
        response.setStatus(HttpServletResponse.SC_CONFLICT);
        resultToResponse(response, DUPLICATE, type);
    }
}