Example usage for org.springframework.http HttpHeaders set

List of usage examples for org.springframework.http HttpHeaders set

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders set.

Prototype

@Override
public void set(String headerName, @Nullable String headerValue) 

Source Link

Document

Set the given, single header value under the given name.

Usage

From source file:sample.undertow.SampleUndertowApplicationTests.java

@Test
public void testCompression() throws Exception {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Accept-Encoding", "gzip");
    HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
    RestTemplate restTemplate = new TestRestTemplate();
    ResponseEntity<byte[]> entity = restTemplate.exchange("http://localhost:" + this.port, HttpMethod.GET,
            requestEntity, byte[].class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()));
    try {// ww w  .j  a va  2 s . c  o m
        assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))).isEqualTo("Hello World");
    } finally {
        inflater.close();
    }
}

From source file:org.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.BasicAuthEndPointsDisabledPredefinedTests.java

@Test
public void basicAuthenticationServiceTest() throws Exception {
    int port = context.getEmbeddedServletContainer().getPort();

    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization",
            "Basic " + new String(Base64.encode((getUsername() + ":" + getPassword()).getBytes("UTF-8"))));
    HttpEntity<String> entity = new HttpEntity<String>("headers", headers);

    ResponseEntity<AuthorizationData> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + baseApiPath + basicAuthenticationEndpointPath, HttpMethod.POST, entity,
            AuthorizationData.class);
    // When an enpoint is disabled, "405 - METHOD NOT ALLOWED" is returned
    assertEquals(HttpStatus.METHOD_NOT_ALLOWED, responseEntity.getStatusCode());
}

From source file:edu.wisc.cypress.dao.taxstmt.RestTaxStatementDao.java

@Override
public void getTaxStatement(String emplid, String docId, ProxyResponse proxyResponse) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);
    this.restOperations.proxyRequest(proxyResponse, this.statementUrl, HttpMethod.GET, httpHeaders, docId);
}

From source file:edu.wisc.cypress.dao.advrpt.RestAdvisorReportDao.java

@Override
public void getAdvisorReport(String pvi, String docId, ProxyResponse proxyResponse) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("PVI", pvi);

    this.restOperations.proxyRequest(proxyResponse, this.statementUrl, HttpMethod.GET, httpHeaders, docId);
}

From source file:edu.wisc.cypress.dao.sabstmt.RestSabbaticalStatementDao.java

@Override
public void getSabbaticalReport(String emplid, String docId, ProxyResponse proxyResponse) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);
    this.restOperations.proxyRequest(proxyResponse, this.statementUrl, HttpMethod.GET, httpHeaders, docId);
}

From source file:edu.wisc.cypress.dao.ernstmt.RestEarningStatementDao.java

@Override
public void getEarningStatement(String emplid, String docId, ProxyResponse proxyResponse) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);
    this.restOperations.proxyRequest(proxyResponse, this.statementUrl, HttpMethod.GET, httpHeaders, docId);
}

From source file:nl.flotsam.calendar.core.CalendarClient.java

public String getCalendarAsType(String key, String contentType) {
    String address = UriBuilder.fromUri(baseURI).path("calendars").build().toASCIIString() + "/{key}";
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("key", key);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", contentType);
    HttpEntity<?> request = new HttpEntity(headers);
    HttpEntity<String> response = template.exchange(address, HttpMethod.GET, request, String.class, params);
    return response.getBody();
}

From source file:edu.wisc.cypress.dao.taxstmt.RestTaxStatementDao.java

@Cacheable(cacheName = "taxStatement", exceptionCacheName = "cypressUnknownExceptionCache")
@Override/*from  www  .j a va 2 s .  co m*/
public TaxStatements getTaxStatements(String emplid) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);
    final XmlTaxStatements xmlTaxStatements = this.restOperations.getForObject(this.statementsUrl,
            XmlTaxStatements.class, httpHeaders, emplid);
    return mapTaxStatements(xmlTaxStatements);
}

From source file:edu.wisc.cypress.dao.sabstmt.RestSabbaticalStatementDao.java

@Cacheable(cacheName = "sabbaticalReports", exceptionCacheName = "cypressUnknownExceptionCache")
@Override//from   ww  w .j a  va2s.  co  m
public SabbaticalReports getSabbaticalReports(String emplid) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);
    final XmlSabbaticalReports xmlSabbaticalReports = this.restOperations.getForObject(this.statementsUrl,
            XmlSabbaticalReports.class, httpHeaders, emplid);
    return mapSabbaticalReports(xmlSabbaticalReports);
}

From source file:edu.wisc.cypress.dao.advrpt.RestAdvisorReportDao.java

@Cacheable(cacheName = "advisorReports", exceptionCacheName = "cypressUnknownExceptionCache")
@Override//from w  w  w  .ja va 2s  .  co  m
public AdvisorReports getAdvisorReports(String pvi) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("PVI", pvi);

    final XmlAdvisorReports xmlAdvisorReports = this.restOperations.getForObject(this.statementsUrl,
            XmlAdvisorReports.class, httpHeaders, pvi);

    return this.mapAdvisorReports(xmlAdvisorReports);
}