当前位置: 首页>>代码示例>>Java>>正文


Java HttpStatus.UNSUPPORTED_MEDIA_TYPE属性代码示例

本文整理汇总了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);
}
 
开发者ID:2DV603NordVisaProject,项目名称:nordvisa_calendar,代码行数:46,代码来源:ImageController.java

示例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");
}
 
开发者ID:helloworldtang,项目名称:spring-boot-jwt-jpa,代码行数:9,代码来源:GlobalHandler.java

示例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()));
}
 
开发者ID:lord-of-code,项目名称:loc-framework,代码行数:10,代码来源:LocAdviceErrorAutoConfiguration.java

示例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);
}
 
开发者ID:wengwh,项目名称:plumdo-work,代码行数:8,代码来源:ExceptionHandlerAdvice.java

示例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());
}
 
开发者ID:junneyang,项目名称:xxproject,代码行数:12,代码来源:CustomRestExceptionHandler.java

示例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();
}
 
开发者ID:rozidan,项目名称:project-template,代码行数:12,代码来源:GlobalErrorHandlers.java

示例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);
}
 
开发者ID:WinstonZheng,项目名称:wtem,代码行数:9,代码来源:ExceptionAdvice.java

示例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);
}
 
开发者ID:allianzit,项目名称:ait-platform,代码行数:15,代码来源:AitRestExceptionHandler.java

示例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");
}
 
开发者ID:finefuture,项目名称:data-migration,代码行数:9,代码来源:HttpExceptionAdvice.java

示例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);
}
 
开发者ID:MasonQAQ,项目名称:WeatherSystem,代码行数:10,代码来源:ExceptionAdvice.java

示例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");
}
 
开发者ID:graphium-project,项目名称:graphium,代码行数:5,代码来源:GlobalExceptionController.java

示例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());
}
 
开发者ID:eclipse,项目名称:keti,代码行数:6,代码来源:HttpMediaTypeNotSupportedExceptionHandler.java


注:本文中的org.springframework.http.HttpStatus.UNSUPPORTED_MEDIA_TYPE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。