本文整理汇总了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());
}