List of usage examples for org.springframework.http HttpHeaders HttpHeaders
public HttpHeaders()
From source file:org.cloudfoundry.identity.app.integration.AuthenticationIntegrationTests.java
@Test public void formLoginSucceeds() throws Exception { ResponseEntity<Void> result; String location;/*from www. j ava2s . c o m*/ String cookie; HttpHeaders uaaHeaders = new HttpHeaders(); HttpHeaders appHeaders = new HttpHeaders(); uaaHeaders.setAccept(Arrays.asList(MediaType.TEXT_HTML)); appHeaders.setAccept(Arrays.asList(MediaType.TEXT_HTML)); // *** GET /app/id result = serverRunning.getForResponse("/id", appHeaders); assertEquals(HttpStatus.FOUND, result.getStatusCode()); location = result.getHeaders().getLocation().toString(); cookie = result.getHeaders().getFirst("Set-Cookie"); assertNotNull("Expected cookie in " + result.getHeaders(), cookie); appHeaders.set("Cookie", cookie); assertTrue("Wrong location: " + location, location.contains("/oauth/authorize")); // *** GET /uaa/oauth/authorize result = serverRunning.getForResponse(location, uaaHeaders); assertEquals(HttpStatus.FOUND, result.getStatusCode()); location = result.getHeaders().getLocation().toString(); cookie = result.getHeaders().getFirst("Set-Cookie"); assertNotNull("Expected cookie in " + result.getHeaders(), cookie); uaaHeaders.set("Cookie", cookie); assertTrue("Wrong location: " + location, location.contains("/login")); location = serverRunning.getAuthServerUrl("/login.do"); MultiValueMap<String, String> formData; formData = new LinkedMultiValueMap<String, String>(); formData.add("username", testAccounts.getUserName()); formData.add("password", testAccounts.getPassword()); // *** POST /uaa/login.do result = serverRunning.postForResponse(location, uaaHeaders, formData); cookie = result.getHeaders().getFirst("Set-Cookie"); assertNotNull("Expected cookie in " + result.getHeaders(), cookie); uaaHeaders.set("Cookie", cookie); assertEquals(HttpStatus.FOUND, result.getStatusCode()); location = result.getHeaders().getLocation().toString(); assertTrue("Wrong location: " + location, location.contains("/oauth/authorize")); // *** GET /uaa/oauth/authorize result = serverRunning.getForResponse(location, uaaHeaders); // If there is no token in place already for this client we get the approval page. // TODO: revoke the token so we always get the approval page if (result.getStatusCode() == HttpStatus.OK) { location = serverRunning.getAuthServerUrl("/oauth/authorize"); formData = new LinkedMultiValueMap<String, String>(); formData.add("user_oauth_approval", "true"); // *** POST /uaa/oauth/authorize result = serverRunning.postForResponse(location, uaaHeaders, formData); } location = result.getHeaders().getLocation().toString(); // SUCCESS assertTrue("Wrong location: " + location, location.contains("/id")); // *** GET /app/id result = serverRunning.getForResponse(location, appHeaders); // System.err.println(result.getHeaders()); assertEquals(HttpStatus.OK, result.getStatusCode()); }
From source file:guru.nidi.ramltester.spring.SpringMockRamlMessageTest.java
@RequestMapping(value = "path", produces = "text/dummy") @ResponseBody// ww w. j ava 2 s . c o m public ResponseEntity<String> test() { final HttpHeaders headers = new HttpHeaders(); headers.add("head", "resValue"); return new ResponseEntity<>("respons", headers, HttpStatus.ACCEPTED); }
From source file:edu.infsci2560.services.DvdsService.java
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public ResponseEntity<Dvd> create(@RequestBody Dvd dvd) { HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<>(repository.save(dvd), headers, HttpStatus.OK); }
From source file:com.cocktail.controller.CocktailController.java
@RequestMapping(value = "/cocktails/cocktail", method = RequestMethod.POST) public ResponseEntity<?> addCocktail(@RequestBody CocktailResource cocktailDTO, UriComponentsBuilder ucBuilder) { Cocktail cocktail = cocktailService.addCocktail(cocktailDTO); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/Cocktails/Cocktail/{id}").buildAndExpand(cocktail.getId()).toUri()); return new ResponseEntity<>(null, headers, HttpStatus.CREATED); }
From source file:edu.infsci2560.services.BookService.java
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public ResponseEntity<Book> create(@RequestBody Book book) { HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<>(repository.save(book), headers, HttpStatus.OK); }
From source file:org.sventon.web.ctrl.ConfigurationReloadController.java
@RequestMapping(method = GET) @ResponseBody//from w ww . j av a2 s. c o m public ResponseEntity<String> reloadConfigAndReinitializeApplication() { HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.TEXT_PLAIN); if (!application.isConfigurationReloadSupported()) { return new ResponseEntity<String>("Forbidden.", responseHeaders, FORBIDDEN); } try { application.reinit(); return new ResponseEntity<String>("Configuration reloaded.", responseHeaders, OK); } catch (Exception e) { logger.error("Failed to reload configuration files.", e); return new ResponseEntity<String>("Internal error.", responseHeaders, INTERNAL_SERVER_ERROR); } }
From source file:pw.spn.mptg.controller.ProjectTemplateController.java
@PostMapping(produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public ResponseEntity<byte[]> generate(@ModelAttribute PomTemplate pomTemplate) { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.CONTENT_DISPOSITION, String.format(CONTENT_DISPOSITION_VALUE, pomTemplate.getArtifactId())); ResponseEntity<byte[]> responseEntity = new ResponseEntity<byte[]>( projectService.generateProjectAndZip(pomTemplate), headers, HttpStatus.OK); return responseEntity; }
From source file:com.biz.report.controller.CustomerReportControler.java
@ResponseBody @RequestMapping(value = "customerreport/{year}/get", method = RequestMethod.POST, headers = { "Content-type=application/json" }) public ResponseEntity<ReportDataSet> readFTypes(@PathVariable("year") String year, @RequestBody Map data) { logger.info(year);/* w w w . j a va 2 s. c o m*/ logger.info(data); Assert.notNull(data, "Data is null."); Assert.notNull(year, "Year is null."); String items = data.get("customers").toString(); String months = data.get("months").toString(); ReportDataSet reportDataSet = customerService.getReports(items, months, year); HttpHeaders headers = new HttpHeaders(); headers.add("success", "Success"); return new ResponseEntity<ReportDataSet>(reportDataSet, headers, HttpStatus.OK); }
From source file:cz.muni.fi.mushroomhunter.restclient.MushroomDeleteSwingWorker.java
@Override protected Integer doInBackground() throws Exception { int selectedRow = restClient.getTblMushroom().getSelectedRow(); 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); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); HttpEntity<String> request = new HttpEntity<>(headers); restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory() { @Override/* w ww.j a v a 2 s. c o m*/ protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) { if (HttpMethod.DELETE == httpMethod) { return new HttpEntityEnclosingDeleteRequest(uri); } return super.createHttpUriRequest(httpMethod, uri); } }); restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/mushroom/" + RestClient.getMushroomIDs().get(selectedRow), HttpMethod.DELETE, request, MushroomDto.class); RestClient.getMushroomIDs().remove(selectedRow); return selectedRow; }
From source file:com.biz.report.controller.ItemDashBoardController.java
@ResponseBody @RequestMapping(value = "itemreport/{year}/get", method = RequestMethod.POST, headers = { "Content-type=application/json" }) public ResponseEntity<ReportDataSet> readFTypes(@PathVariable("year") String year, @RequestBody Map data) { logger.info(year);/* w w w. j ava2 s. c o m*/ logger.info(data); Assert.notNull(data, "Data is null."); Assert.notNull(year, "Year is null."); String items = data.get("items").toString(); String months = data.get("months").toString(); ReportDataSet reportDataSet = itemDashBoardService.getReports(items, months, year); HttpHeaders headers = new HttpHeaders(); headers.add("success", "Success"); return new ResponseEntity<ReportDataSet>(reportDataSet, headers, HttpStatus.OK); }