List of usage examples for org.springframework.http HttpStatus UNSUPPORTED_MEDIA_TYPE
HttpStatus UNSUPPORTED_MEDIA_TYPE
To view the source code for org.springframework.http HttpStatus UNSUPPORTED_MEDIA_TYPE.
Click Source Link
From source file:apiserver.services.images.controllers.filters.BoxBlurController.java
/** * A filter which performs a box blur on an uploaded image. The horizontal and vertical blurs can be specified separately and a number of iterations can be given which allows an approximation to Gaussian blur. * * @param documentId/*from w w w . j av a2s .c o m*/ * @param hRadius * @param vRadius * @param iterations * @param preMultiplyAlpha * @param format * @return * @throws java.util.concurrent.TimeoutException * @throws java.util.concurrent.ExecutionException * @throws InterruptedException * @throws java.io.IOException */ @ApiOperation(value = "A filter which performs a box blur on an image. The horizontal and vertical blurs can be specified separately and a number of iterations can be given which allows an approximation to Gaussian blur.") @RequestMapping(value = "/filter/{documentId}/boxblur.{format}", method = { RequestMethod.GET }) @ResponseBody public ResponseEntity<byte[]> imageBoxBlurByFile( @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId, @ApiParam(name = "format", required = true, defaultValue = "jpg") @PathVariable(value = "format") String format, @ApiParam(name = "hRadius", required = false, defaultValue = "2", value = "the horizontal radius of blur") @RequestParam(value = "hRadius", defaultValue = "2") int hRadius, @ApiParam(name = "vRadius", required = false, defaultValue = "2", value = "the vertical radius of blur") @RequestParam(value = "vRadius", defaultValue = "2") int vRadius, @ApiParam(name = "iterations", required = false, defaultValue = "1", value = "the number of time to iterate the blur") @RequestParam(value = "iterations", defaultValue = "1") int iterations, @ApiParam(name = "preMultiplyAlpha", required = false, defaultValue = "true", allowableValues = "true,false", value = "pre multiply the alpha channel") @RequestParam(value = "preMultiplyAlpha", defaultValue = "true") boolean preMultiplyAlpha ) throws TimeoutException, ExecutionException, InterruptedException, IOException { String _contentType = MimeType.getMimeType(format).contentType; if (!MimeType.getMimeType(format).isSupportedImage()) { return new ResponseEntity<byte[]>(HttpStatus.UNSUPPORTED_MEDIA_TYPE); } BoxBlurJob args = new BoxBlurJob(); args.setDocumentId(documentId); args.setHRadius(hRadius); args.setVRadius(vRadius); args.setIterations(iterations); args.setPreMultiplyAlpha(preMultiplyAlpha); Future<Map> imageFuture = imageFilterBoxBlurGateway.imageBoxBlurFilter(args); ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(), _contentType, false); return result; }
From source file:be.bittich.quote.controller.impl.DefaultExceptionHandler.java
@RequestMapping(produces = APPLICATION_JSON) @ExceptionHandler(HttpMediaTypeNotSupportedException.class) @ResponseStatus(value = HttpStatus.UNSUPPORTED_MEDIA_TYPE) public @ResponseBody Map<String, Object> handleUnsupportedMediaTypeException( HttpMediaTypeNotSupportedException ex) throws IOException { Map<String, Object> map = newHashMap(); map.put("error", "Unsupported Media Type"); map.put("cause", ex.getLocalizedMessage()); map.put("supported", ex.getSupportedMediaTypes()); return map;// ww w. j a v a 2 s.co m }
From source file:apiserver.services.images.controllers.filters.MotionBlurController.java
/** * This filter replaces each pixel by the median of the input pixel and its eight neighbours. Each of the RGB channels is considered separately. * @param documentId//from w ww .ja va 2s . com * @param angle * @param distance * @param rotation * @param wrapEdges * @param zoom * @param format * @return * @throws java.util.concurrent.TimeoutException * @throws java.util.concurrent.ExecutionException * @throws InterruptedException * @throws java.io.IOException */ @ApiOperation(value = "This filter simulates motion blur on an image. You specify a combination of angle/distance for linear motion blur, a rotaiton angle for spin blur or a zoom factor for zoom blur. You can combine these in any proportions you want to get effects like spiral blurs.") @RequestMapping(value = "/filter/{documentId}/motionblur.{format}", method = { RequestMethod.GET }) @ResponseBody public ResponseEntity<byte[]> imageMotionBlurByFile( @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId, @ApiParam(name = "angle", required = true, defaultValue = "0") @RequestParam(value = "angle", required = false, defaultValue = "0") float angle, @ApiParam(name = "distance", required = true, defaultValue = "1") @RequestParam(value = "distance", required = false, defaultValue = "0") float distance, @ApiParam(name = "rotation", required = true, defaultValue = "0") @RequestParam(value = "rotation", required = false, defaultValue = "0") float rotation, @ApiParam(name = "wrapEdges", required = true, defaultValue = "false") @RequestParam(value = "wrapEdges", required = false, defaultValue = "false") boolean wrapEdges, @ApiParam(name = "zoom", required = true, defaultValue = "0") @RequestParam(value = "zoom", required = false, defaultValue = "0") float zoom, @ApiParam(name = "format", required = true, defaultValue = "jpg") @PathVariable(value = "format") String format ) throws TimeoutException, ExecutionException, InterruptedException, IOException { String _contentType = MimeType.getMimeType(format).contentType; if (!MimeType.getMimeType(format).isSupportedImage()) { return new ResponseEntity<byte[]>(HttpStatus.UNSUPPORTED_MEDIA_TYPE); } MotionBlurJob args = new MotionBlurJob(); args.setDocumentId(documentId); args.setAngle(angle); args.setDistance(distance); args.setRotation(rotation); args.setWrapEdges(wrapEdges); args.setZoom(zoom); Future<Map> imageFuture = imageFilterMotionBlurGateway.imageMotionBlurFilter(args); ImageDocumentJob payload = (ImageDocumentJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); ResponseEntity<byte[]> result = ResponseEntityHelper.processImage(payload.getBufferedImage(), _contentType, false); return result; }
From source file:com.novation.eligibility.rest.spring.web.servlet.handler.DefaultRestErrorResolver.java
protected final Map<String, String> createDefaultExceptionMappingDefinitions() { Map<String, String> m = new LinkedHashMap<String, String>(); // 400//from ww w. java2 s . c o m applyDef(m, HttpMessageNotReadableException.class, HttpStatus.BAD_REQUEST); applyDef(m, MissingServletRequestParameterException.class, HttpStatus.BAD_REQUEST); applyDef(m, TypeMismatchException.class, HttpStatus.BAD_REQUEST); applyDef(m, "javax.validation.ValidationException", HttpStatus.BAD_REQUEST); // 404 applyDef(m, NoSuchRequestHandlingMethodException.class, HttpStatus.NOT_FOUND); applyDef(m, "org.hibernate.ObjectNotFoundException", HttpStatus.NOT_FOUND); // 405 applyDef(m, HttpRequestMethodNotSupportedException.class, HttpStatus.METHOD_NOT_ALLOWED); // 406 applyDef(m, HttpMediaTypeNotAcceptableException.class, HttpStatus.NOT_ACCEPTABLE); // 409 //can't use the class directly here as it may not be an available dependency: applyDef(m, "org.springframework.dao.DataIntegrityViolationException", HttpStatus.CONFLICT); // 415 applyDef(m, HttpMediaTypeNotSupportedException.class, HttpStatus.UNSUPPORTED_MEDIA_TYPE); return m; }
From source file:com.oolong.platform.web.error.DefaultRestErrorResolver.java
protected final Map<String, String> createDefaultExceptionMappingDefinitions() { Map<String, String> m = new LinkedHashMap<String, String>(); // 400/*from ww w .j a v a 2s . c o m*/ applyDef(m, HttpMessageNotReadableException.class, HttpStatus.BAD_REQUEST); applyDef(m, MissingServletRequestParameterException.class, HttpStatus.BAD_REQUEST); applyDef(m, TypeMismatchException.class, HttpStatus.BAD_REQUEST); applyDef(m, "javax.validation.ValidationException", HttpStatus.BAD_REQUEST); // 404 applyDef(m, NoSuchRequestHandlingMethodException.class, HttpStatus.NOT_FOUND); applyDef(m, "org.hibernate.ObjectNotFoundException", HttpStatus.NOT_FOUND); // 405 applyDef(m, HttpRequestMethodNotSupportedException.class, HttpStatus.METHOD_NOT_ALLOWED); // 406 applyDef(m, HttpMediaTypeNotAcceptableException.class, HttpStatus.NOT_ACCEPTABLE); // 409 // can't use the class directly here as it may not be an available // dependency: applyDef(m, "org.springframework.dao.DataIntegrityViolationException", HttpStatus.CONFLICT); // 415 applyDef(m, HttpMediaTypeNotSupportedException.class, HttpStatus.UNSUPPORTED_MEDIA_TYPE); return m; }
From source file:apiserver.services.images.controllers.info.SizeController.java
/** * get basic info about image.//from w w w . ja va 2 s . com * * @param file * @return * @throws java.util.concurrent.ExecutionException * @throws java.util.concurrent.TimeoutException * @throws InterruptedException */ @ApiOperation(value = "Get the height and width for the image") @RequestMapping(value = "/info/size", method = { RequestMethod.POST }) public ResponseEntity<Map> imageInfoByImageAsync(HttpServletRequest request, HttpServletResponse response, @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file) throws ExecutionException, TimeoutException, InterruptedException, IOException { Document _file = null; MimeType _fileMimeType = null; MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request); _file = new Document(_mFile); _fileMimeType = _file.getContentType(); if (!_fileMimeType.isSupportedImage()) { return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE); } FileInfoJob job = new FileInfoJob(); job.setDocumentId(null); job.setDocument(_file); Future<Map> imageFuture = gateway.imageSize(job); Map payload = imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); ResponseEntity<Map> result = new ResponseEntity(payload, HttpStatus.OK); return result; }
From source file:com.yang.oa.commons.exception.DefaultRestErrorResolver.java
protected final Map<String, String> createDefaultExceptionMappingDefinitions() { Map<String, String> m = new LinkedHashMap<String, String>(); // 400//from w w w . j ava 2 s . c om applyDef(m, HttpMessageNotReadableException.class, HttpStatus.BAD_REQUEST); applyDef(m, MissingServletRequestParameterException.class, HttpStatus.BAD_REQUEST); applyDef(m, TypeMismatchException.class, HttpStatus.BAD_REQUEST); applyDef(m, "javax.validation.ValidationException", HttpStatus.BAD_REQUEST); applyDef(m, JlException.class, HttpStatus.BAD_REQUEST); //401 applyDef(m, org.apache.shiro.authz.UnauthorizedException.class, HttpStatus.UNAUTHORIZED); applyDef(m, org.apache.shiro.authz.UnauthenticatedException.class, HttpStatus.UNAUTHORIZED); // 404 applyDef(m, NoSuchRequestHandlingMethodException.class, HttpStatus.NOT_FOUND); applyDef(m, "org.hibernate.ObjectNotFoundException", HttpStatus.NOT_FOUND); // 405 applyDef(m, HttpRequestMethodNotSupportedException.class, HttpStatus.METHOD_NOT_ALLOWED); // 406 applyDef(m, HttpMediaTypeNotAcceptableException.class, HttpStatus.NOT_ACCEPTABLE); // 409 //can't use the class directly here as it may not be an available dependency: applyDef(m, "org.springframework.dao.DataIntegrityViolationException", HttpStatus.CONFLICT); // 415 applyDef(m, HttpMediaTypeNotSupportedException.class, HttpStatus.UNSUPPORTED_MEDIA_TYPE); return m; }
From source file:org.openinfobutton.responder.controller.OpenInfobuttonResponderController.java
/** * Handles HttpMediaTypeNotSupportedException via Spring's exception handler * annotation strategy/*from ww w .j a v a2s. c om*/ */ @ResponseStatus(value = HttpStatus.UNSUPPORTED_MEDIA_TYPE, reason = "Requested knowedgeResourceType not supported.") @ExceptionHandler(HttpMediaTypeNotSupportedException.class) public void handleHttpMediaTypeNotSupportedException() { // logic handled by annotations }
From source file:apiserver.services.images.controllers.manipulations.BorderController.java
/** * Draw a border around an image//from w w w . j a va2s . c o m * * @param file * @param color * @param thickness * @param format * @return * @throws InterruptedException * @throws java.util.concurrent.ExecutionException * @throws java.util.concurrent.TimeoutException * @throws java.io.IOException */ @RequestMapping(value = "/modify/border", method = { RequestMethod.POST }) public ResponseEntity<byte[]> drawBorderByImage(HttpServletRequest request, HttpServletResponse response, @ApiParam(name = "file", required = false) @RequestParam(value = "file", required = false) MultipartFile file, @ApiParam(name = "color", required = true) @RequestParam(required = true) String color, @ApiParam(name = "thickness", required = true) @RequestParam(required = true) Integer thickness, @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format ) throws InterruptedException, ExecutionException, TimeoutException, IOException { Document _file = null; MimeType _outputMimeType = null; String _outputContentType = null; MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request); _file = new Document(_mFile); _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType()); _outputContentType = _outputMimeType.contentType; if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) { return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE); } FileBorderJob job = new FileBorderJob(); job.setDocumentId(null); job.setDocument(_file); job.setColor(color); job.setThickness(thickness); job.setFormat(format); Future<Map> imageFuture = imageDrawBorderGateway.imageDrawBorderFilter(job); FileBorderJob payload = (FileBorderJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); //pass CF Response back to the client return payload.getHttpResponse(); }
From source file:apiserver.services.images.controllers.manipulations.RotateController.java
/** * rotate an image//from w w w .jav a2s. c om * * @param file * @param angle * @return */ @ApiOperation(value = "Rotate an uploaded image") @RequestMapping(value = "/modify/rotate", method = { RequestMethod.POST }) @ResponseBody public ResponseEntity<byte[]> rotateImageByImage(HttpServletRequest request, HttpServletResponse response, @ApiParam(name = "file", required = true) @RequestParam(value = "file", required = false) MultipartFile file, @ApiParam(name = "angle", required = true, defaultValue = "90") @RequestParam(required = true, defaultValue = "90") Integer angle, @ApiParam(name = "format", required = false) @RequestParam(value = "format", required = false) String format ) throws IOException, InterruptedException, ExecutionException, TimeoutException { Document _file = null; MimeType _outputMimeType = null; String _outputContentType = null; MultipartFile _mFile = fileUploadHelper.getFileFromRequest(file, request); _file = new Document(_mFile); _outputMimeType = fileUploadHelper.getOutputFileFormat(format, _file.getContentType()); _outputContentType = _outputMimeType.contentType; if (!_file.getContentType().isSupportedImage() || !_outputMimeType.isSupportedImage()) { return new ResponseEntity<>(HttpStatus.UNSUPPORTED_MEDIA_TYPE); } FileRotateJob job = new FileRotateJob(); job.setDocumentId(null); job.setDocument(_file); //job.getDocument().setContentType( MimeType.getMimeType(file.getContentType()) ); //job.getDocument().setFileName(file.getOriginalFilename()); job.setAngle(angle); job.setFormat(format); Future<Map> imageFuture = imageRotateGateway.rotateImage(job); FileRotateJob payload = (FileRotateJob) imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); //pass CF Response back to the client return payload.getHttpResponse(); }