List of usage examples for org.springframework.http HttpHeaders setContentType
public void setContentType(@Nullable MediaType mediaType)
From source file:org.makersoft.mvc.unit.RESTfulMappingHanderMappingTests.java
@Test public void testShow() throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_HTML); mockMvc.perform(get("/account/dept/1").accept(MediaType.TEXT_HTML).headers(httpHeaders)).andDo(print()) .andExpect(status().isOk()).andExpect(view().name("account/dept/show")) .andExpect(forwardedUrl("/WEB-INF/views/account/dept/show.jsp")); }
From source file:org.makersoft.mvc.unit.RESTfulMappingHanderMappingTests.java
@Test public void testNew() throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_HTML); mockMvc.perform(get("/account/dept/new").accept(MediaType.TEXT_HTML).headers(httpHeaders)).andDo(print()) .andExpect(status().isOk()).andExpect(view().name("account/dept/_form")) .andExpect(forwardedUrl("/WEB-INF/views/account/dept/_form.jsp")); }
From source file:org.makersoft.mvc.unit.RESTfulMappingHanderMappingTests.java
@Test public void testEdit() throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.TEXT_HTML); mockMvc.perform(get("/account/dept/1/edit").accept(MediaType.TEXT_HTML).headers(httpHeaders)).andDo(print()) .andExpect(status().isOk()).andExpect(view().name("account/dept/_form")) .andExpect(forwardedUrl("/WEB-INF/views/account/dept/_form.jsp")); }
From source file:org.openbaton.marketplace.api.exceptions.GlobalExceptionHandler.java
@ExceptionHandler({ NotFoundException.class, ImageRepositoryNotEnabled.class }) @ResponseStatus(value = HttpStatus.NOT_FOUND) protected ResponseEntity<Object> handleNotFoundException(HttpServletRequest req, Exception e) { log.error("Exception with message " + e.getMessage() + " was thrown"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); Map body = new HashMap<>(); body.put("error", "Not Found"); body.put("exception", e.getClass().toString()); body.put("message", e.getMessage()); body.put("path", req.getRequestURI()); body.put("status", HttpStatus.NOT_FOUND.value()); body.put("timestamp", new Date().getTime()); ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.NOT_FOUND); return responseEntity; }
From source file:org.openbaton.marketplace.api.exceptions.GlobalExceptionHandler.java
@ExceptionHandler({ InterruptedException.class, IOException.class }) @ResponseStatus(value = HttpStatus.NOT_FOUND) protected ResponseEntity<Object> handleException(HttpServletRequest req, Exception e) { log.error("Exception with message " + e.getMessage() + " was thrown"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); Map body = new HashMap<>(); body.put("error", "Upload Error"); body.put("exception", e.getClass().toString()); body.put("message", e.getMessage()); body.put("path", req.getRequestURI()); body.put("status", HttpStatus.I_AM_A_TEAPOT.value()); body.put("timestamp", new Date().getTime()); ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.I_AM_A_TEAPOT); return responseEntity; }
From source file:org.ala.spatial.web.services.LayerDistancesWSController.java
@RequestMapping(value = "/layers/analysis/inter_layer_association_rawnames.csv", method = RequestMethod.GET) public ResponseEntity<String> CSVrawnames(HttpServletRequest req) { String csv = makeCSV("name"); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.parseMediaType("text/csv")); return new ResponseEntity<String>(csv, responseHeaders, HttpStatus.CREATED); }
From source file:org.ala.spatial.web.services.LayerDistancesWSController.java
@RequestMapping(value = "/layers/analysis/inter_layer_association.csv", method = RequestMethod.GET) public ResponseEntity<String> CSV(HttpServletRequest req) { String csv = makeCSV("displayname"); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.parseMediaType("text/csv")); return new ResponseEntity<String>(csv, responseHeaders, HttpStatus.CREATED); }
From source file:business.services.PaNumberService.java
public HttpEntity<InputStreamResource> writePaNumbers(List<PathologyItem> items, Integer labNumber, String labRequestCode) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(out, PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING); CSVWriter csvwriter = new CSVWriter(writer, ';', '"'); csvwriter.writeNext(FILE_HEADER);/*from w w w . j av a 2 s. c o m*/ for (PathologyItem item : items) { log.info(item.getPaNumber()); String[] toppings = { labNumber.toString(), item.getPaNumber(), "", "" }; csvwriter.writeNext(toppings); } String filename = "panumbers_" + labRequestCode + ".csv"; try { csvwriter.flush(); writer.flush(); out.flush(); InputStream in = new ByteArrayInputStream(out.toByteArray()); csvwriter.close(); writer.close(); out.close(); InputStreamResource resource = new InputStreamResource(in); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("text/csv;charset=" + PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING)); headers.set("Content-Disposition", "attachment; filename=\"" + filename + "\""); HttpEntity<InputStreamResource> response = new HttpEntity<InputStreamResource>(resource, headers); return response; } catch (IOException e) { throw new Exception(e); } }
From source file:org.openschedule.api.impl.EventTemplate.java
public void addEventComment(String shortName, Comment comment) { Log.v(TAG, "addEventComment : enter"); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(new MediaType("application", "json")); HttpEntity<Comment> requestEntity = new HttpEntity<Comment>(comment, requestHeaders); restTemplate.exchange("public/" + shortName + "/comments", HttpMethod.POST, requestEntity, String.class, shortName).getBody();/* www. java 2s . com*/ Log.v(TAG, "addEventComment : exit"); }
From source file:org.openbaton.marketplace.api.exceptions.GlobalExceptionHandler.java
@ExceptionHandler({ PackageIntegrityException.class }) @ResponseStatus(value = HttpStatus.BAD_REQUEST) protected @ResponseBody ResponseEntity<Object> handleInvalidRequest(Exception e, WebRequest request) { if (log.isDebugEnabled()) { log.error("Exception was thrown -> Return message: " + e.getMessage(), e); } else {/*from ww w .j a v a 2 s. c om*/ 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); Map body = new HashMap<>(); body.put("error", "Upload Error"); body.put("exception", e.getClass().toString()); body.put("message", e.getMessage()); body.put("path", request.getContextPath()); body.put("status", HttpStatus.BAD_REQUEST.value()); body.put("timestamp", new Date().getTime()); ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.BAD_REQUEST); return responseEntity; }