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:org.cloudfoundry.identity.uaa.scim.remote.RemoteScimUserProvisioning.java

@Override
public ScimUser delete(String id, int version) throws ScimResourceNotFoundException {
    HttpHeaders headers = new HttpHeaders();
    headers.set("If-Match", String.format("%d", version));
    return restTemplate.exchange(baseUrl + "/User/{id}", HttpMethod.DELETE, new HttpEntity<Void>(headers),
            ScimUser.class, id).getBody();
}

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

@Cacheable(cacheName = "earningStatement", exceptionCacheName = "cypressUnknownExceptionCache")
@Override//from   w w  w  .  j  a  va  2 s .co  m
public EarningStatements getEarningStatements(String emplid) {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("HRID", emplid);

    final XmlEarningStatements xmlEarningStatements = this.restOperations.getForObject(this.statementsUrl,
            XmlEarningStatements.class, httpHeaders, emplid);

    return this.mapEarningStatements(xmlEarningStatements);
}

From source file:org.cloudfoundry.identity.api.web.CloudfoundryApiIntegrationTests.java

@Test
public void testClientAccessesProtectedResource() throws Exception {
    OAuth2AccessToken accessToken = context.getAccessToken();
    // add an approval for the scope requested
    HttpHeaders approvalHeaders = new HttpHeaders();
    approvalHeaders.set("Authorization", "bearer " + accessToken.getValue());
    Date oneMinuteAgo = new Date(System.currentTimeMillis() - 60000);
    Date expiresAt = new Date(System.currentTimeMillis() + 60000);
    ResponseEntity<Approval[]> approvals = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/uaa/approvals"), HttpMethod.PUT,
            new HttpEntity<Approval[]>((new Approval[] {
                    new Approval(testAccounts.getUserName(), "app", "cloud_controller.read", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo),
                    new Approval(testAccounts.getUserName(), "app", "openid", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo),
                    new Approval(testAccounts.getUserName(), "app", "password.write", expiresAt,
                            ApprovalStatus.APPROVED, oneMinuteAgo) }),
                    approvalHeaders),//from   w  w w . ja  va2s  .c o m
            Approval[].class);
    assertEquals(HttpStatus.OK, approvals.getStatusCode());

    // System.err.println(accessToken);
    // The client doesn't know how to use an OAuth bearer token
    CloudFoundryClient client = new CloudFoundryClient("Bearer " + accessToken.getValue(),
            testAccounts.getCloudControllerUrl());
    CloudInfo info = client.getCloudInfo();
    assertNotNull("Wrong cloud info: " + info.getDescription(), info.getUser());
}

From source file:me.j360.boot.standard.test.SessionRedisApplicationTests.java

@Test
public void sessionExpiry() throws Exception {

    String port = null;//from w  w  w  . ja v  a2  s. co m

    try {
        ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(J360Configuration.class)
                .properties("server.port:0").initializers(new ServerPortInfoApplicationContextInitializer())
                .run();
        port = context.getEnvironment().getProperty("local.server.port");
    } catch (RuntimeException ex) {
        if (!redisServerRunning(ex)) {
            return;
        }
    }

    URI uri = URI.create("http://localhost:" + port + "/");
    RestTemplate restTemplate = new RestTemplate();

    ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class);
    String uuid1 = response.getBody();
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Cookie", response.getHeaders().getFirst("Set-Cookie"));

    RequestEntity<Void> request = new RequestEntity<Void>(requestHeaders, HttpMethod.GET, uri);

    String uuid2 = restTemplate.exchange(request, String.class).getBody();
    assertThat(uuid1, is(equalTo(uuid2)));

    Thread.sleep(5000);

    String uuid3 = restTemplate.exchange(request, String.class).getBody();
    assertThat(uuid2, is(not(equalTo(uuid3))));
}

From source file:org.cloudfoundry.identity.uaa.scim.RemoteScimUserProvisioningTests.java

@Test
public void testRemoveUser() {
    HttpHeaders headers = new HttpHeaders();
    headers.set("If-Match", "123456789");
    Mockito.when(restTemplate.exchange(Mockito.eq("http://base/User/{id}"), Mockito.eq(HttpMethod.DELETE),
            Mockito.argThat(new HttpHeadersMatcher()), Mockito.eq(ScimUser.class), Mockito.eq("1234")))
            .thenReturn(new ResponseEntity<ScimUser>(user, HttpStatus.OK));
    service.removeUser("1234", 123456789);
}

From source file:sample.RestTests.java

@Test
public void authenticateWithBasicWorks() {
    String auth = getAuth("user", "password");
    HttpHeaders headers = getHttpHeaders();
    headers.set(AUTHORIZATION, BASIC + auth);
    ResponseEntity<User> entity = getForUser(this.baseUrl + "/", headers, User.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(entity.getHeaders().containsKey(X_AUTH_TOKEN)).isTrue();
    assertThat(entity.getBody().getUsername()).isEqualTo("user");
}

From source file:com.example.ProxyAuthorizationServerTokenServices.java

private HttpHeaders createHeaders() {
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "Basic " + Base64Utils.encodeToString("cf:".getBytes()));
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    return headers;
}

From source file:org.cloudfoundry.identity.uaa.scim.remote.RemoteScimUserProvisioningTests.java

@Test
public void testRemoveUser() {
    HttpHeaders headers = new HttpHeaders();
    headers.set("If-Match", "123456789");
    Mockito.when(restTemplate.exchange(Mockito.eq("http://base/User/{id}"), Mockito.eq(HttpMethod.DELETE),
            Mockito.argThat(new HttpHeadersMatcher()), Mockito.eq(ScimUser.class), Mockito.eq("1234")))
            .thenReturn(new ResponseEntity<ScimUser>(user, HttpStatus.OK));
    service.delete("1234", 123456789);
}

From source file:sample.RestTests.java

@Test
public void logout() {
    String auth = getAuth("user", "password");
    HttpHeaders headers = getHttpHeaders();
    headers.set(AUTHORIZATION, BASIC + auth);
    ResponseEntity<User> entity = getForUser(this.baseUrl + "/", headers, User.class);

    String token = entity.getHeaders().getFirst(X_AUTH_TOKEN);

    HttpHeaders logoutHeader = getHttpHeaders();
    logoutHeader.set(X_AUTH_TOKEN, token);
    ResponseEntity<User> logoutResponse = getForUser(this.baseUrl + "/logout", logoutHeader, User.class);
    assertThat(logoutResponse.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
}

From source file:com.art4ul.jcoon.handlers.CookiesAnnotationBeforeHandler.java

@Override
public void doHandle(Context context, Annotation annotation, Object paramValue) {
    if (paramValue != null) {
        Object paramObject = WrapperUtil.getWreppedObject(paramValue);
        HttpHeaders httpHeaders = context.getHttpHeaders();
        if (paramObject instanceof String) {
            httpHeaders.set("Cookie", paramObject.toString());
        } else if (paramObject instanceof List) {
            String resultString = Joiner.on(";").join((List) paramObject);
            httpHeaders.set("Cookie", resultString);
        }//  w  w  w .j a v  a  2s .  com
    }
}