Example usage for org.springframework.boot.web.client RestTemplateBuilder RestTemplateBuilder

List of usage examples for org.springframework.boot.web.client RestTemplateBuilder RestTemplateBuilder

Introduction

In this page you can find the example usage for org.springframework.boot.web.client RestTemplateBuilder RestTemplateBuilder.

Prototype

RestTemplateBuilder

Source Link

Usage

From source file:io.spring.initializr.actuate.stat.ProjectGenerationStatPublisher.java

public ProjectGenerationStatPublisher(ProjectRequestDocumentFactory documentFactory,
        StatsProperties statsProperties, RetryTemplate retryTemplate) {
    this.documentFactory = documentFactory;
    this.statsProperties = statsProperties;
    this.objectMapper = createObjectMapper();
    this.restTemplate = new RestTemplateBuilder().basicAuthorization(statsProperties.getElastic().getUsername(),
            statsProperties.getElastic().getPassword()).build();
    this.retryTemplate = retryTemplate;
}

From source file:io.spring.initializr.actuate.stat.ProjectGenerationStatPublisherTests.java

@Before
public void setUp() {
    StatsProperties properties = createProperties();
    ProjectRequestDocumentFactory documentFactory = new ProjectRequestDocumentFactory(
            createProvider(getMetadata()));
    this.retryTemplate = new RetryTemplate();
    this.statPublisher = new ProjectGenerationStatPublisher(documentFactory, properties,
            new RestTemplateBuilder(), this.retryTemplate);
    this.mockServer = MockRestServiceServer.createServer(this.statPublisher.getRestTemplate());
}

From source file:org.opendatakit.api.admin.UserAdminServiceTest.java

@PostConstruct
public void setup() {
    testUser1 = new UserEntity("username:manu", "Manu Bentez", "capiat", "ROLE_USER");
    testUser2 = new UserEntity("username:antonio", "Antonio Ruz", "capiat", "ROLE_DATA_VIEWER",
            "ROLE_USER");
    testUser3 = new UserEntity("username:javier", "Javier Cceres", "capiat", "ROLE_SYNCHRONIZE_TABLES",
            "ROLE_DATA_VIEWER", "ROLE_USER");
    testUserList = new ArrayList<UserEntity>();
    testUserList.add(testUser1);/*from   w  ww.  ja v  a 2 s. c om*/
    testUserList.add(testUser2);
    testUserList.add(testUser3);

    RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder();
    restTemplate = restTemplateBuilder
            .basicAuthorization(ConstantsUtils.TEST_ADMIN_USERNAME, ConstantsUtils.TEST_ADMIN_PASSWORD).build();

    RegionalOffice testOffice = new RegionalOffice("Capiat, Central", "capiat");
    TestUtils.putOffice(restTemplate, server, testOffice);
}

From source file:org.opendatakit.api.admin.UserAdminServiceTest.java

@Test
public void testChangePlaintextPassword() {
    TestUtils.putGetOneUser(restTemplate, server, testUser3);
    String username = testUser3.getUserId().substring(SecurityConsts.USERNAME_COLON.length());
    String password = "mypass";

    String changePasswordUrl = ConstantsUtils.url(server) + "/admin/users/" + testUser3.getUserId()
            + "/password";

    logger.info("Updating password for " + username + " using " + changePasswordUrl);

    MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
    headers.add("Content-Type", "application/json");
    HttpEntity<?> request = new HttpEntity<>(password, headers);
    ResponseEntity<String> postResponse = restTemplate.postForEntity(changePasswordUrl, request, String.class);
    assertThat(postResponse.getStatusCode(), is(HttpStatus.OK));

    logger.info("Retrieving data using " + username + "'s new password");

    RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder();
    RestTemplate userRestTemplate = restTemplateBuilder.basicAuthorization(username, password).build();
    String getUserUrl = ConstantsUtils.url(server) + "/admin/users/" + testUser3.getUserId();
    ResponseEntity<UserEntity> getResponse = userRestTemplate.exchange(getUserUrl, HttpMethod.GET, null,
            UserEntity.class);
    UserEntity body = getResponse.getBody();
    assertThat(getResponse.getStatusCode(), is(HttpStatus.OK));
    assertThat(body.getUserId(), equalTo(testUser3.getUserId()));

    logger.info("Cleanup: deleting " + username);
    TestUtils.deleteGetOneUser(restTemplate, server, testUser3);
}