當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。