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:org.finra.dm.service.helper.DmErrorInformationExceptionHandler.java
/** * Gets a new error information based on the specified message. * * @param httpStatus the status of the error. * @param exception the exception whose message will be used. * * @return the error information./*from w w w. j a v a 2 s . co m*/ */ private ErrorInformation getErrorInformation(HttpStatus httpStatus, Throwable exception) { ErrorInformation errorInformation = new ErrorInformation(); errorInformation.setStatusCode(httpStatus.value()); errorInformation.setStatusDescription(httpStatus.getReasonPhrase()); String errorMessage = exception.getMessage(); if (StringUtils.isEmpty(errorMessage)) { errorMessage = exception.getClass().getName(); } errorInformation.setMessage(errorMessage); List<String> messageDetails = new ArrayList<>(); Throwable causeException = exception.getCause(); while (causeException != null) { messageDetails.add(causeException.getMessage()); causeException = causeException.getCause(); } errorInformation.setMessageDetails(messageDetails); return errorInformation; }
From source file:org.infoscoop.api.oauth2.provider.ISOAuth2ExceptionRenderer.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void writeWithMessageConverters(Object returnValue, HttpInputMessage inputMessage, HttpOutputMessage outputMessage, HttpStatus status, HttpServletRequest request) throws IOException, HttpMediaTypeNotAcceptableException { log.info(request.getRemoteAddr() + " " + returnValue + " " + status.value()); Class<?> returnValueType = returnValue.getClass(); List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>(); String fileType = request.getPathInfo(); MediaType acceptedMediaType = MediaType.APPLICATION_JSON; if (fileType.substring(fileType.lastIndexOf(".") + 1).equals("xml")) acceptedMediaType = MediaType.APPLICATION_XML; for (HttpMessageConverter messageConverter : messageConverters) { if (messageConverter.canWrite(returnValueType, acceptedMediaType)) { messageConverter.write(returnValue, acceptedMediaType, outputMessage); if (log.isDebugEnabled()) { MediaType contentType = outputMessage.getHeaders().getContentType(); if (contentType == null) { contentType = acceptedMediaType; }/*w w w.j a v a2s .c o m*/ log.debug("Written [" + returnValue + "] as \"" + contentType + "\" using [" + messageConverter + "]"); } return; } } for (HttpMessageConverter messageConverter : messageConverters) { allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes()); } throw new HttpMediaTypeNotAcceptableException(allSupportedMediaTypes); }
From source file:org.springframework.cloud.dataflow.shell.command.HttpCommands.java
private void outputError(HttpStatus status, StringBuilder buffer) { buffer.append("> ").append(status.value()).append(" ").append(status.name()).append(OsUtils.LINE_SEPARATOR); }
From source file:org.springframework.http.server.reactive.AbstractServerHttpResponse.java
@Override public boolean setStatusCode(@Nullable HttpStatus statusCode) { if (this.state.get() == State.COMMITTED) { if (logger.isTraceEnabled()) { logger.trace("HTTP response already committed. " + "Status not set to " + (statusCode != null ? statusCode.toString() : "null")); }/*from w ww.j ava 2s. c o m*/ return false; } else { this.statusCode = (statusCode != null ? statusCode.value() : null); return true; } }
From source file:org.springframework.http.server.reactive.ServletServerHttpResponse.java
@Override public void setStatusCode(HttpStatus status) { getServletResponse().setStatus(status.value()); }
From source file:org.springframework.social.twitter.api.impl.upload.UploadTemplateTest.java
@Test public void uploadChunkedAppend_test() throws IOException { final String command = ChunkCommandType.APPEND.name(); final Resource resource = dataResource("small.mp4"); final InputStream is = resource.getInputStream(); final byte[] data = bufferObj(is); mockServer.expect(requestTo("https://upload.twitter.com/1.1/media/upload.json")).andExpect(method(POST)) .andExpect(content().string(containsString("Content-Disposition: form-data; name=\"command\""))) .andExpect(content().string(containsString("Content-Disposition: form-data; name=\"media_id\""))) .andExpect(/* w w w . j av a 2 s. com*/ content().string(containsString("Content-Disposition: form-data; name=\"segment_index\""))) .andExpect(content().string(containsString("Content-Disposition: form-data; name=\"media\""))) .andExpect(content().string(containsString(command))) .andExpect(content().string(containsString(MEDIA_ID))).andRespond(withNoContent()); HttpStatus status = twitter.uploadOperations().uploadChunkedAppend(MEDIA_ID, data, 0); assertEquals(204, status.value()); }