本文整理匯總了Java中org.springframework.http.HttpStatus.UNSUPPORTED_MEDIA_TYPE屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus.UNSUPPORTED_MEDIA_TYPE屬性的具體用法?Java HttpStatus.UNSUPPORTED_MEDIA_TYPE怎麽用?Java HttpStatus.UNSUPPORTED_MEDIA_TYPE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.springframework.http.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.UNSUPPORTED_MEDIA_TYPE屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: uploadImages
/**
* Upload an array of images to the server. Currently, the frontend can only handle an image at a time,
* but this method should only require a little modification if we wanted to make possible multiple uploads
* at the same time.
*
* @param files An array of files to upload.
* @return HTTP response of a body containing a JSON object with the generated path,
* using the appropriate status code.
*/
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<UploadImagesDTO> uploadImages(@RequestParam("files") MultipartFile[] files) {
String path;
UploadImagesDTO uploadFailed = new UploadImagesDTO("", false);
// Generate a random hex string that doesn't already exist
do {
path = getRandomHexString(16);
} while (dao.pathExists(path));
for (MultipartFile file : files) {
String name = file.getOriginalFilename();
try {
InputStream is = new BufferedInputStream(file.getInputStream());
String mimeType = URLConnection.guessContentTypeFromStream(is);
// Return if the image is not the right file type (or if it isn't even an image)
if (!ACCEPTED_FILE_TYPES.contains(mimeType)) {
dao.deleteAllImages(path);
return new ResponseEntity<>(uploadFailed, HttpStatus.UNSUPPORTED_MEDIA_TYPE);
}
if (!dao.saveImage(name, file, path, mimeType)) {
// If saving an image fails for some reason, delete all previously uploaded images and
// return 500
dao.deleteAllImages(path);
return new ResponseEntity<>(uploadFailed, HttpStatus.INTERNAL_SERVER_ERROR);
}
} catch (IOException e) {
e.printStackTrace();
dao.deleteAllImages(path);
return new ResponseEntity<>(uploadFailed, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
return new ResponseEntity<>(new UploadImagesDTO(path, true), HttpStatus.OK);
}
示例2: handleHttpMediaTypeNotSupportedException
/**
* 415 - Unsupported Media Type
*/
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public ResponseEntity handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e) {
LOGGER.error("不支持當前媒體類型", e);
return ResponseEntity.badRequest().body("content_type_not_supported");
}
示例3: handleHttpMediaTypeNotSupportedException
@ResponseStatus(value = HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public BasicResult handleHttpMediaTypeNotSupportedException(
HttpMediaTypeNotSupportedException e) {
logError("httpMediaTypeNotSupportedException", e.getMessage(), e);
return BasicResult
.fail(BasicResultCode.UNSUPPORTED_MEDIA_TYPE_ERROR.getCode(),
BasicResultCode.UNSUPPORTED_MEDIA_TYPE_ERROR.getMsg(),
String.format("媒體類型%s錯誤", e.getContentType()));
}
示例4: handleNotSupported
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
// 415
@ExceptionHandler(FlowableContentNotSupportedException.class)
@ResponseBody
public ErrorInfo handleNotSupported(FlowableContentNotSupportedException e) {
LOGGER.error("Content is not supported", e);
return new ErrorInfo("Content is not supported", e);
}
示例5: handleHttpMediaTypeNotSupported
@Override
protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(final HttpMediaTypeNotSupportedException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final StringBuilder builder = new StringBuilder();
builder.append(ex.getContentType());
builder.append(" media type is not supported. Supported media types are ");
ex.getSupportedMediaTypes().forEach(t -> builder.append(t + " "));
final ApiError apiError = new ApiError(HttpStatus.UNSUPPORTED_MEDIA_TYPE, ex.getLocalizedMessage(), builder.substring(0, builder.length() - 2));
return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
示例6: handleHttpMediaTypeNotSupportedException
@Loggable
@ResponseStatus(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public ErrorDto handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException ex) {
return ErrorDto.builder()
.errorCode(ErrorCodes.HTTP_MEDIA_TYPE_NOT_SUPPORTED)
.errors(Collections.singleton(HttpMediaTypeErrorDto.builder()
.mediaType(ex.getContentType().toString())
.build()))
.message(ex.getLocalizedMessage())
.build();
}
示例7: handleHttpMediaTypeNotSupportedException
/**
* 415 - Unsupported Media Type
*/
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public Response handleHttpMediaTypeNotSupportedException(Exception e) {
logger.error("不支持當前媒體類型", e);
return new Response().failure(ReturnStatus.UNSUPPORTED_MEDIA_TYPE);
}
示例8: handleHttpMediaTypeNotSupported
@Override
protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(final HttpMediaTypeNotSupportedException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.info(ex.getClass().getName());ex.printStackTrace();
//
final StringBuilder builder = new StringBuilder();
builder.append(ex.getContentType());
builder.append(" media type is not supported. Supported media types are ");
for (final MediaType type : ex.getSupportedMediaTypes()) {
builder.append(type + " ");
}
final AitException AitException = new AitException(HttpStatus.UNSUPPORTED_MEDIA_TYPE, ex.getLocalizedMessage(), builder.substring(0, builder.length() - 2));
return handleExceptionInternal(ex, AitException, headers, AitException.getStatus(), request);
}
示例9: handleHttpMediaTypeNotSupportedException
/**
* 415 - Unsupported Media Type
*/
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public Response handleHttpMediaTypeNotSupportedException(Exception e) {
log.error("不支持當前媒體類型: {}", e);
return new Response().failure("content_type_not_supported");
}
示例10: handleHttpMediaTypeNotSupportedException
/**
* 415 - Unsupported Media Type
* @param e
* @return
*/
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
public ReturnPureNotifyApi handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e) {
return new ReturnPureNotifyApi(ApiStatus.UNSUPPORTED_MEDIA_TYPE);
}
示例11: handleMediaTypeNotAcceptableException
@ResponseStatus(value = HttpStatus.UNSUPPORTED_MEDIA_TYPE, reason = "Mediatype is not acceptable")
@ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
public void handleMediaTypeNotAcceptableException(HttpMediaTypeNotAcceptableException ex) {
log.warn("Requested media type is not acceptable");
}
示例12: handleException
@ExceptionHandler(HttpMediaTypeNotSupportedException.class)
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
@ResponseBody
public RestApiErrorResponse handleException(final HttpMediaTypeNotSupportedException e) {
return super.handleException(e, HttpStatus.UNSUPPORTED_MEDIA_TYPE.getReasonPhrase());
}