List of usage examples for org.springframework.http HttpHeaders HttpHeaders
public HttpHeaders()
From source file:edu.infsci2560.services.LocationsService.java
@RequestMapping(method = RequestMethod.GET, produces = "application/json") public ResponseEntity<Iterable<Location>> list() { HttpHeaders headers = new HttpHeaders(); return new ResponseEntity<>(repository.findAll(), headers, HttpStatus.OK); }
From source file:org.jnrain.mobile.accounts.kbs.KBSCheckIDRequest.java
@Override public KBSRegisterResult loadDataFromNetwork() throws Exception { MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); params.set("id", _uid); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<MultiValueMap<String, String>> req = new HttpEntity<MultiValueMap<String, String>>(params, headers);/* ww w .j a va 2 s . c o m*/ return getRestTemplate().postForObject("http://bbs.jnrain.com/rainstyle/apicheckid.php", req, KBSRegisterResult.class); }
From source file:com.recursivechaos.clearent.controller.SaleController.java
private HttpHeaders createHeaders(Sale newSale) { final URI location = responseService.getLocationUri(newSale); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(location);// ww w .ja va2 s . c om return headers; }
From source file:ca.qhrtech.services.implementations.StrawPollServiceImpl.java
@Override public long generatePollId(List<Game> games, BGLTable table) { StrawPoll poll = generateRequestBodyPoll(games, generatePollName(table)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<StrawPoll> request = new HttpEntity<>(poll, headers); HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); RestTemplate template = new RestTemplate(factory); ResponseEntity<StrawPoll> generatedPoll; generatedPoll = template.postForEntity(STRAW_POLL_URL, request, StrawPoll.class); return generatedPoll.getBody().getId(); }
From source file:org.cloudfoundry.identity.batch.integration.BatchEndpointIntegrationTests.java
/** * tests a happy-day flow of the <code>/batch</code> endpoint */// w w w .jav a 2 s .c om @Test public void testHappyDay() throws Exception { String credentials = String.format("%s:%s", "batch", "batchsecret"); String auth = String.format("Basic %s", new String(Base64.encode(credentials.getBytes()))); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", auth); ResponseEntity<String> response = serverRunning.getForString("/batch/", headers); assertEquals(HttpStatus.OK, response.getStatusCode()); String map = response.getBody(); assertTrue(map.contains("jobs")); }
From source file:cz.muni.fi.mushroomhunter.restclient.AllLocationSwingWorker.java
@Override protected List<LocationDto> doInBackground() throws Exception { 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 restTemplate = new RestTemplate(); ResponseEntity<LocationDto[]> responseEntity = restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/location/", HttpMethod.GET, request, LocationDto[].class); LocationDto[] locationDtoArray = responseEntity.getBody(); List<LocationDto> locationDtoList = new ArrayList<>(); locationDtoList.addAll(Arrays.asList(locationDtoArray)); return locationDtoList; }
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 w ww . j a v a 2 s . com 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:org.cloudfoundry.identity.uaa.integration.PasswordCheckEndpointIntegrationTests.java
@Test public void passwordPostSucceeds() throws Exception { MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("password", "password1"); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap("/password/score", formData, headers); assertEquals(HttpStatus.OK, response.getStatusCode()); assertTrue(response.getBody().containsKey("score")); assertTrue(response.getBody().containsKey("requiredScore")); assertEquals(0, response.getBody().get("score")); }
From source file:com.fabionoth.rest.RobotRest.java
/** * * @param command/*w w w. j av a 2s .c om*/ * @return */ @RequestMapping(value = { "rest/mars/", "/rest/mars/{command}" }, method = { RequestMethod.GET, RequestMethod.POST }) public ResponseEntity<String> sendCommand(@PathVariable Optional<String> command) { Robot robot; robot = new Robot(new Long(1), 0, 0, CardinalPoints.N); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentType(MediaType.TEXT_HTML); if (command.isPresent()) { try { robot = new RobotController(robot, command.get()).getRobot(); } catch (Exception ex) { Logger.getLogger(RobotRest.class.getName()).log(Level.SEVERE, null, ex); return new ResponseEntity<>("Erro", responseHeaders, HttpStatus.BAD_REQUEST); } } String response = "(" + robot.getX() + ", " + robot.getY() + ", " + robot.getC().toString() + ")"; return new ResponseEntity<>(response, responseHeaders, HttpStatus.OK); }
From source file:net.orpiske.tcs.service.rest.functional.DomainCreateTest.java
private HttpHeaders getHeaders(String auth) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); byte[] encodedAuthorisation = Base64.encodeBase64(auth.getBytes()); headers.add("Authorization", "Basic " + new String(encodedAuthorisation)); return headers; }