List of usage examples for org.springframework.http HttpHeaders setContentType
public void setContentType(@Nullable MediaType mediaType)
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { IllegalArgumentException.class }) protected ResponseEntity<Object> handleIllegalArgumentException(Exception ex, WebRequest request) { ex.printStackTrace();/*ww w . ja v a 2s .c o m*/ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer(ex.getMessage()), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { NullPointerException.class }) protected ResponseEntity<Object> handleNullPointerException(Exception ex, WebRequest request) { ex.printStackTrace();//from ww w. ja v a 2 s .co m HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer("An unkown error has occured! Server response : NullPointerException"), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { OutOfMemoryError.class }) protected ResponseEntity<Object> handleOutOfMemoryError(Exception ex, WebRequest request) { ex.printStackTrace();/*from ww w . j a v a 2s .c o m*/ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer("An unkown error has occured! Server response : OutOfMemoryError"), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { ClassCastException.class }) protected ResponseEntity<Object> handleClassCastException(Exception ex, WebRequest request) { ex.printStackTrace();// w ww. j a v a 2 s .com HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer("An unkown error has occured! Server response : ClassCastException"), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { IllegalStateException.class }) protected ResponseEntity<Object> handleIllegalStateException(Exception ex, WebRequest request) { ex.printStackTrace();/*from w w w .j a v a 2s . c om*/ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer("An unkown error has occured! Server response : IllegalStateException"), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { NoSuchElementException.class }) protected ResponseEntity<Object> handleNoSuchElementException(Exception ex, WebRequest request) { ex.printStackTrace();/*from w w w. j av a2 s.com*/ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer("An unkown error has occured! Server response : NoSuchElementException"), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { ArithmeticException.class }) protected ResponseEntity<Object> handleArithmeticException(Exception ex, WebRequest request) { ex.printStackTrace();// w w w . j av a 2 s . c o m HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer("An unkown error has occured! Server response : ArithmeticException"), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:cn.org.once.cstack.config.RestHandlerException.java
@ExceptionHandler(value = { IndexOutOfBoundsException.class }) protected ResponseEntity<Object> handleIndexOutOfBoundsException(Exception ex, WebRequest request) { ex.printStackTrace();/*w ww . jav a 2s . c o m*/ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(ex, new HttpErrorServer("An unkown error has occured! Server response : IndexOutOfBoundsException"), headers, HttpStatus.INTERNAL_SERVER_ERROR, request); }
From source file:org.callistasoftware.netcare.core.spi.impl.PushNotificationServiceImpl.java
void sendApnsNotification(final String registrationId, final String message) { getLog().info("Preparing to send APNS message: {}", apnsCount); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); params.add("token", registrationId); params.add("message", message); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(params, headers);// www. ja va2s . c o m String result = new RestTemplate().postForObject(apnsServiceUrl, request, String.class); if (result.equals("success")) { getLog().debug("Push notification " + apnsCount + " sent. Result: " + result); apnsCount++; } else { getLog().error("Push notification could not be sent. Server result:\n" + result); } }
From source file:apiserver.services.images.controllers.ImageController.java
/** * get basic info about image.//from w ww. ja va 2 s . c o m * @param documentId cache id * @return height,width, pixel size, transparency * , @RequestPart("meta-data") Object metadata * , @RequestParam MultipartFile file */ @ApiOperation(value = "Get the height and width for the image", responseClass = "java.util.Map") @RequestMapping(value = "/info/{documentId}/size", method = { RequestMethod.GET }) public WebAsyncTask<ResponseEntity<Map>> imageInfoByImageAsync( @ApiParam(name = "documentId", required = true, defaultValue = "8D981024-A297-4169-8603-E503CC38EEDA") @PathVariable(value = "documentId") String documentId) throws ExecutionException, TimeoutException, InterruptedException { final String _documentId = documentId; Callable<ResponseEntity<Map>> callable = new Callable<ResponseEntity<Map>>() { @Override public ResponseEntity<Map> call() throws Exception { FileInfoJob args = new FileInfoJob(); args.setDocumentId(_documentId); Future<Map> imageFuture = gateway.imageSize(args); Map payload = imageFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); ResponseEntity<Map> result = new ResponseEntity<Map>(payload, headers, HttpStatus.OK); return result; } }; return new WebAsyncTask<ResponseEntity<Map>>(defaultTimeout, callable); }