List of usage examples for org.springframework.http HttpHeaders HttpHeaders
public HttpHeaders()
From source file:com.salatigacode.dao.ProductControllerTests.java
@Test public void testDelete() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<Object> entity = new HttpEntity<>(headers); ResponseEntity<String> responseEntity = restTemplate.exchange(BASE_URL + "abc123", HttpMethod.DELETE, entity, String.class); Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode().OK); }
From source file:org.cloudfoundry.identity.uaa.integration.VarzEndpointIntegrationTests.java
/** * tests a unauthorized flow of the <code>/varz</code> endpoint *//*from w ww . j a v a 2s. c om*/ @Test public void testUnauthorized() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Basic %s", new String(Base64.encode("varz:bogus".getBytes())))); ResponseEntity<String> response = serverRunning.getForString("/varz", headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); String map = response.getBody(); // System.err.println(map); assertTrue(map.contains("{\"error\"")); }
From source file:com.aspose.showcase.qrcodegen.web.api.controller.RestResponseEntityExceptionHandler.java
protected <T> ResponseEntity<T> response(T body, HttpStatus status) { return new ResponseEntity<T>(body, new HttpHeaders(), status); }
From source file:org.projecthdata.social.api.impl.RootTemplate.java
public RootTemplate(HData hData, RestTemplate restTemplate, boolean isAuthorizedForUser) { super(isAuthorizedForUser); this.restTemplate = restTemplate; this.hData = hData; this.ehrUri = URI.create(hData.getEhrUrl()); // setup the correct accept headers for processing an atom feed List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>(); acceptableMediaTypes.add(MediaType.APPLICATION_ATOM_XML); acceptableMediaTypes.add(MediaType.APPLICATION_XML); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAccept(acceptableMediaTypes); this.atomFeedRequestEntity = new HttpEntity<Object>(requestHeaders); }
From source file:io.spring.initializr.web.project.LegacyStsControllerIntegrationTests.java
@Override protected String htmlHome() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.TEXT_HTML)); return getRestTemplate() .exchange(createUrl("/sts"), HttpMethod.GET, new HttpEntity<Void>(headers), String.class).getBody(); }
From source file:cn.aozhi.songify.rest.RestExceptionHandler.java
/** * ?JSR311 Validation.//from ww w. java2s. c om */ @ExceptionHandler(value = { ConstraintViolationException.class }) public final ResponseEntity<?> handleException(ConstraintViolationException ex, WebRequest request) { Map<String, String> errors = BeanValidators.extractPropertyAndMessage(ex.getConstraintViolations()); String body = jsonMapper.toJson(errors); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType(MediaTypes.TEXT_PLAIN_UTF_8)); return handleExceptionInternal(ex, body, headers, HttpStatus.BAD_REQUEST, request); }
From source file:org.jasig.portlet.notice.service.ssp.SSPApiRequest.java
public SSPApiRequest setHeaders(final HttpHeaders headers) { this.headers = (headers == null) ? new HttpHeaders() : headers; return this; }
From source file:org.awesomeagile.webapp.security.google.GoogleConfigurableOAuth2Template.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<String, String> parameters) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( parameters, headers);//from w ww. j a v a 2 s .com ResponseEntity<Map> responseEntity = getRestTemplate().exchange(accessTokenUrl, HttpMethod.POST, requestEntity, Map.class); Map<String, Object> responseMap = responseEntity.getBody(); return extractAccessGrant(responseMap); }
From source file:com.opensearchserver.hadse.index.IndexTest.java
@Test public void t02_createDefaultIndex() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); RestTemplate template = new RestTemplate(); ResponseEntity<String> entity = template.exchange("http://localhost:8080/my_index", HttpMethod.PUT, null, String.class); assertEquals(HttpStatus.CREATED, entity.getStatusCode()); }
From source file:com.bailen.radioOnline.recursos.REJA.java
public Incidencia ratings(String apiKey, String rating, String idCancion, String fav) { MultiValueMap<String, String> params1 = new LinkedMultiValueMap<>(); params1.add("rating", (rating)); params1.add("idCancion", (idCancion)); params1.add("fav", (fav)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.add("Authorization", apiKey); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params1, headers); String result = new RestTemplate().postForObject("http://ceatic.ujaen.es:8075/radioapi/v2/ratings", request, String.class); try {/*from ww w. j a va 2 s . c om*/ ObjectMapper a = new ObjectMapper(); Incidencia listilla = a.readValue(result, Incidencia.class); return listilla; } catch (Exception e) { return null; } }