List of usage examples for org.springframework.http HttpStatus value
int value
To view the source code for org.springframework.http HttpStatus value.
Click Source Link
From source file:com.envision.envservice.rest.EvaluationResource.java
/** * ?/*w w w . j av a2s.c o m*/ * * */ @POST @Path("/addNullEvaluationForManager") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response addNullEvaluationForManager(EvaluationBo evaluationBo) throws Exception { HttpStatus status = HttpStatus.CREATED; String response = StringUtils.EMPTY; if (!checkParamForManager(evaluationBo.getRemark())) { status = HttpStatus.BAD_REQUEST; response = FailResult.toJson(Code.PARAM_ERROR, "?"); } else { response = evaluationService.addNullEvaluationForManager(evaluationBo.getRemark()).toJSONString(); } return Response.status(status.value()).entity(response).build(); }
From source file:com.envision.envservice.rest.PictureUploadResource.java
@POST @Consumes(MediaType.APPLICATION_JSON)// w w w. j a v a 2s .c o m @Produces(MediaType.APPLICATION_JSON) public Response addNew(ClgPictureBo clgPicture) throws Exception { HttpStatus status = HttpStatus.CREATED; String response = StringUtils.EMPTY; if (!checkParam(clgPicture)) { status = HttpStatus.BAD_REQUEST; response = FailResult.toJson(Code.PARAM_ERROR, "?"); } else { List<ClgPicture> list = ClgPictureService.addClgPicture(clgPicture); List<Map> maplist = new ArrayList<Map>(); for (int i = 0; i < list.size(); i++) { Map map = new HashMap(); map.put("id", list.get(i).getId().toString()); maplist.add(map); } response = JSONObject.toJSONString(maplist, JSONFilter.UNDERLINEFILTER); return Response.status(status.value()).entity(response).build(); } return null; }
From source file:com.grizzly.rest.GenericRestCall.java
/** * Process the response of the rest call. * @param response a valid response.//from w ww .j av a 2 s . com * @return true or false. */ private boolean processResponseWithouthData(ResponseEntity<X> response) { HttpStatus status = responseStatus = response.getStatusCode(); this.setResponseHeaders(response.getHeaders()); if (DefinitionsHttpMethods.getHttpStates().contains(status.value())) { return true; } return false; }
From source file:com.grizzly.rest.GenericRestCall.java
/** * Process the response of the rest call and assigns the body to the responseEntity. * @param response a valid response./* w ww . ja v a 2 s. co m*/ * @return true or false. */ private boolean processResponseWithData(ResponseEntity<X> response) { HttpStatus status = responseStatus = response.getStatusCode(); this.setResponseHeaders(response.getHeaders()); if (DefinitionsHttpMethods.getHttpStates().contains(status.value())) { if (!response.getBody().equals(null)) { jsonResponseEntity = response.getBody(); if (context != null) { createSolidCache(); } } return true; } return false; }
From source file:com.envision.envservice.rest.LeaveWordResource.java
@POST @Consumes(MediaType.APPLICATION_JSON)//from w ww .j a v a2s . c o m @Produces(MediaType.APPLICATION_JSON) public Response addNew(@Context HttpServletRequest request, LeaveWordBo leaveWord) throws Exception { HttpStatus status = HttpStatus.CREATED; String response = StringUtils.EMPTY; if (!checkParam(leaveWord)) { status = HttpStatus.BAD_REQUEST; response = FailResult.toJson(Code.PARAM_ERROR, "?"); } else if (!checkContentLength(leaveWord)) { status = HttpStatus.BAD_REQUEST; response = FailResult.toJson(Code.CONTENT_TOO_LONG, ""); } else { DBLogger logger = operationLog(request, leaveWord.getUserIdTarget()); String leaveWordId = leaveWordService.addLeaveWord(leaveWord); loggerService.setSuccess(logger.getId(), true, leaveWordId); } return Response.status(status.value()).entity(response).build(); }
From source file:nl.minbzk.dwr.zoeken.enricher.uploader.ElasticSearchResultUploader.java
/** * {@inheritDoc}// w w w . j a va 2 s .c o m */ @Override public void commit(final EnricherJob job) throws Exception { String flushUri = format("http://%s/%s/_flush", getElasticSearchUri(), job.getDatabaseName()); HttpStatus status = operations.execute(flushUri, HttpMethod.POST, null, new ResponseExtractor<HttpStatus>() { @Override public HttpStatus extractData(final ClientHttpResponse response) throws IOException { return response.getStatusCode(); } }, null); if (status.value() != HttpStatus.OK.value()) logger.error("Not all shards could be flushed / committed"); else { if (logger.isInfoEnabled()) logger.info("All shards were successfully flushed / committed"); } }
From source file:nl.minbzk.dwr.zoeken.enricher.uploader.ElasticSearchResultUploader.java
/** * {@inheritDoc}/*from w w w . j a va 2s .c om*/ */ @Override public void deleteByReference(final EnricherJob job, final String field, final String[] documents) throws Exception { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XContentBuilder builder = XContentFactory.jsonBuilder(outputStream); try { builder.startObject(); builder.startObject("bool"); builder.startArray("should"); for (String document : documents) { builder.startObject(); builder.startObject("match"); builder.field(field, document); builder.endObject(); builder.endObject(); } builder.endArray(); builder.endObject(); builder.endObject(); builder.flush(); // Then post the result String queryUri = format("http://%s/%s/%s/_query", getElasticSearchUri(), job.getDatabaseName(), job.getDatabaseType()); HttpStatus status = operations.execute(queryUri, HttpMethod.DELETE, new RequestCallback() { @Override public void doWithRequest(final ClientHttpRequest request) throws IOException { request.getBody().write(outputStream.toByteArray()); } }, new ResponseExtractor<HttpStatus>() { @Override public HttpStatus extractData(final ClientHttpResponse response) throws IOException { return response.getStatusCode(); } }, null); if (status.value() == HttpStatus.OK.value()) logger.info(format("Successfully removed document(s) from ElasticSearch")); else logger.error( format("Failed to delete document(s) from ElasticSearch %s", status.getReasonPhrase())); } finally { builder.close(); } }
From source file:test.phoenixnap.oss.plugin.naming.RamlStyleCheckerTest.java
@Test public void test_Get404Check_Fails() { RamlRoot published = RamlVerifier.loadRamlFromFile("test-style-missing-get404-fails.raml"); MultiValueMap<String, HttpStatus> statusChecks = new LinkedMultiValueMap<>(); HttpStatus status = HttpStatus.NOT_FOUND; statusChecks.add(HttpMethod.GET.name(), status); RamlVerifier verifier = new RamlVerifier(published, null, Collections.emptyList(), null, null, Collections.singletonList(new ResponseCodeDefinitionStyleChecker(statusChecks))); assertFalse("Check that raml passes rules", verifier.hasErrors()); assertTrue("Check that implementation matches rules", verifier.hasWarnings()); assertEquals("Check that implementation shuld have 1 warnings", 1, verifier.getWarnings().size()); TestHelper// www . j ava 2s . c om .verifyIssuesUnordered(verifier.getWarnings(), new Issue[] { new Issue(IssueSeverity.WARNING, IssueLocation.CONTRACT, IssueType.STYLE, String.format(ResponseCodeDefinitionStyleChecker.DESCRIPTION, "GET", status.name(), status.value()), "GET /base/endpointThatWillBoom") }); }
From source file:eu.freme.common.exception.ExceptionHandlerService.java
public ResponseEntity<String> handleError(HttpServletRequest req, Throwable exception) { logger.error("Request: " + req.getRequestURL() + " raised ", exception); HttpStatus statusCode = null; if (exception instanceof MissingServletRequestParameterException) { // create response for spring exceptions statusCode = HttpStatus.BAD_REQUEST; } else if (exception instanceof FREMEHttpException && ((FREMEHttpException) exception).getHttpStatusCode() != null) { // get response code from FREMEHttpException statusCode = ((FREMEHttpException) exception).getHttpStatusCode(); } else if (exception instanceof AccessDeniedException) { statusCode = HttpStatus.UNAUTHORIZED; } else if (exception instanceof HttpMessageNotReadableException) { statusCode = HttpStatus.BAD_REQUEST; } else {/*from ww w . j a v a 2s . c o m*/ // get status code from exception class annotation Annotation responseStatusAnnotation = exception.getClass().getAnnotation(ResponseStatus.class); if (responseStatusAnnotation instanceof ResponseStatus) { statusCode = ((ResponseStatus) responseStatusAnnotation).value(); } else { // set default status code 500 statusCode = HttpStatus.INTERNAL_SERVER_ERROR; } } JSONObject json = new JSONObject(); json.put("status", statusCode.value()); json.put("message", exception.getMessage()); json.put("error", statusCode.getReasonPhrase()); json.put("timestamp", new Date().getTime()); json.put("exception", exception.getClass().getName()); json.put("path", req.getRequestURI()); if (exception instanceof AdditionalFieldsException) { Map<String, JSONObject> additionalFields = ((AdditionalFieldsException) exception) .getAdditionalFields(); for (String key : additionalFields.keySet()) { json.put(key, additionalFields.get(key)); } } HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/json"); return new ResponseEntity<String>(json.toString(2), responseHeaders, statusCode); }
From source file:com.ephesoft.dcma.webservice.util.WebServiceHelper.java
/** * Extracting the xml structure for exception received. * /* w w w . ja va 2 s. com*/ * @param statusCode {@link HttpStatus} the status code for received exception. * @param cause {@link String} the cause description to the error. * @param customCode int the custom code maintained for this specific error cause. * @return {@link RootElement} the root object of xml structure returned. */ public RootElement getXMLStructureObjectForError(final HttpStatus statusCode, final String cause, final int customCode) { rootElement = new RootElement(); responseCodeElement = new ResponseCodeElement(); errorElement = new ErrorElement(); responseCodeElement.setHttpCode(statusCode.value()); responseCodeElement.setResult(WebServiceConstants.ERROR); rootElement.setResponseCode(responseCodeElement); errorElement.setCause(cause); errorElement.setCustomCode(customCode); errorElement.setInfoUrl(WebServiceConstants.DEFAULT_URL); rootElement.setError(errorElement); return rootElement; }