List of usage examples for org.springframework.http HttpHeaders setContentType
public void setContentType(@Nullable MediaType mediaType)
From source file:org.makersoft.mvc.unit.FormatHandlerMethodReturnValueHandlerTests.java
@Test public void testIncludes() throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); mockMvc.perform(get("/account/user/includes/1").accept(MediaType.APPLICATION_JSON).headers(httpHeaders)) .andDo(print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(content().encoding("UTF-8")) .andExpect(jsonPath("$.id").value(1)).andExpect(jsonPath("$.password").doesNotExist()) .andExpect(jsonPath("$.dept").doesNotExist()).andExpect(jsonPath("$.roles").doesNotExist()); }
From source file:cz.cvut.jirutjak.fastimport.droid.oauth2.DefaultAccessTokenProvider.java
protected HttpEntity<MultiValueMap<String, String>> createAccessTokenRequestEntity( MultiValueMap<String, String> formData) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); return new HttpEntity<MultiValueMap<String, String>>(formData, headers); }
From source file:org.dineth.shooter.app.view.ImageController.java
@RequestMapping(value = "/get/{name}.{ext}") public ResponseEntity<byte[]> getImage(@PathVariable("name") String name, @PathVariable("ext") String ext) { Resource resource = context.getResource("file:/home/dewmal/files/" + name + "." + ext); System.out.println(resource.getFilename()); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); try {/*from ww w . j a va2s . c o m*/ return new ResponseEntity<>(IOUtils.toByteArray(resource.getInputStream()), headers, HttpStatus.CREATED); } catch (IOException ex) { Logger.getLogger(ImageController.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:org.openbaton.nfvo.api.exceptions.GlobalExceptionHandler.java
@ExceptionHandler({ BadRequestException.class, BadFormatException.class, NetworkServiceIntegrityException.class, WrongStatusException.class, UnrecognizedPropertyException.class, VimException.class, CyclicDependenciesException.class, WrongAction.class, PasswordWeakException.class }) @ResponseStatus(value = HttpStatus.BAD_REQUEST) protected ResponseEntity<Object> handleInvalidRequest(Exception e, WebRequest request) { if (log.isDebugEnabled()) { log.error("Exception was thrown -> Return message: " + e.getMessage(), e); } else {//www .jav a2 s .com log.error("Exception was thrown -> Return message: " + e.getMessage()); } ExceptionResource exc = new ExceptionResource("Bad Request", e.getMessage()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(e, exc, headers, HttpStatus.UNPROCESSABLE_ENTITY, request); }
From source file:org.intermine.app.net.request.post.CreateGenesList.java
@Override public HttpHeaders getHeaders() { HttpHeaders headers = super.getHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); return headers; }
From source file:com.github.carlomicieli.nerdmovies.controllers.ImageController.java
private ResponseEntity<byte[]> render(String movieId, ImageType t) throws IOException { ObjectId id = new ObjectId(movieId); Movie m = mongoTemplate.findById(id, Movie.class); byte[] aob = null; if (t == ImageType.POSTER) aob = m.getPoster();//www . j av a2 s . c om else if (t == ImageType.THUMB) aob = m.getThumb(); if (aob == null) return null; InputStream in = new ByteArrayInputStream(aob); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<byte[]>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED); }
From source file:cz.muni.fi.mushroomhunter.restclient.LocationCreateSwingWorker.java
@Override protected Void doInBackground() throws Exception { LocationDto locationDto = new LocationDto(); locationDto.setName(restClient.getTfLocationName().getText()); locationDto.setDescription(restClient.getTfLocationDescription().getText()); locationDto.setNearCity(restClient.getTfLocationNearCity().getText()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); List<MediaType> mediaTypeList = new ArrayList<>(); mediaTypeList.add(MediaType.ALL);//from www. j ava 2s . c om headers.setAccept(mediaTypeList); ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(locationDto); RestTemplate restTemplate = new RestTemplate(); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); headers.add("Authorization", "Basic " + base64Creds); HttpEntity request = new HttpEntity(json, headers); Long[] result = restTemplate.postForObject(RestClient.SERVER_URL + "pa165/rest/location", request, Long[].class); RestClient.getLocationIDs().add(result[0]); return null; }
From source file:bibibi.controllers.CitationsController.java
@RequestMapping(value = "/export", method = RequestMethod.GET) public HttpEntity<FileSystemResource> getFile() throws IOException { BibWriter bw = new BibWriter("export", this.citationRepository.findAll()); bw.writeFile();//from w w w. jav a2 s . c o m HttpHeaders header = new HttpHeaders(); header.setContentType(MediaType.APPLICATION_OCTET_STREAM); header.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + bw.getFile().getName()); header.setContentLength(bw.getFile().length()); return new HttpEntity<>(new FileSystemResource(bw.getFile()), header); }
From source file:eu.impress.rest.api.BedAvailabilityController.java
@RequestMapping(value = "/bedavailability/hospital/{hospitalName}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity<String> sendAvailableBeds(@PathVariable("hospitalName") String hospitalName) throws DatatypeConfigurationException { String bedavailability;//from www .j a va 2s . co m String bedavailabilityDEEnvelope; String bedavailabilityDE; String bedavailabilityJSON; //get HAVE String bedavailability = b.getBedAvailablityHAVE(hospitalName); //get DE String bedavailabilityDEEnvelope = b.createBedAvailabilityDE(); //encapsulate in DE bedavailabilityDE = b.getBedAvailabilityEDXLDE(bedavailabilityDEEnvelope, bedavailability); //produce json message bedavailabilityJSON = b.forwardBedAvailability(bedavailabilityDE); log.info("Json message: " + bedavailabilityJSON); //push message to EMCR RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(bedavailabilityJSON, headers); String answer = restTemplate.postForObject(EMCRUrl, entity, String.class); log.info("EMCR response: " + answer); return new ResponseEntity<String>(answer, HttpStatus.OK); }
From source file:za.co.dwarfsun.jcmanager.test.restapi.JcUserRestControllerTest.java
private HttpHeaders getContentType() { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(MediaType.TEXT_PLAIN); return requestHeaders; }