Example usage for org.springframework.http HttpMethod PUT

List of usage examples for org.springframework.http HttpMethod PUT

Introduction

In this page you can find the example usage for org.springframework.http HttpMethod PUT.

Prototype

HttpMethod PUT

To view the source code for org.springframework.http HttpMethod PUT.

Click Source Link

Usage

From source file:org.cloudfoundry.identity.uaa.integration.PasswordChangeEndpointIntegrationTests.java

@Test
@OAuth2ContextConfiguration(OAuth2ContextConfiguration.ClientCredentials.class)
public void testChangePasswordSucceeds() throws Exception {
    PasswordChangeRequest change = new PasswordChangeRequest();
    change.setPassword("newpassword");

    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<Void> result = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}/password",
            HttpMethod.PUT, new HttpEntity<PasswordChangeRequest>(change, headers), null, joe.getId());
    assertEquals(HttpStatus.OK, result.getStatusCode());

}

From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java

@Override
public URI triggerDataLoad(final InstanceConfig config, final String dataId) throws ResponseStatusException {
    Preconditions.checkArgument(config != null);
    Preconditions.checkArgument(StringUtils.isNotBlank(dataId));

    final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(),
            config.getUsername(), config.getPassword());

    final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(),
            TRIGGER_PATH, Collections.emptyList());

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);
    final HttpEntity<String> httpEntity = new HttpEntity<>(dataId, headers);

    final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity,
            String.class);
    final HttpStatus status = response.getStatusCode();
    if (status.equals(HttpStatus.CREATED)) {
        return response.getHeaders().getLocation();
    } else {//from  w  w  w. j  a  v a 2  s.  co m
        throw new ResponseStatusException(
                "HttpStatus " + status.toString() + " response received. Load trigger creation failed.");
    }
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRouteCreatingStepTest.java

@Test
public void createAppRoute_allCloudFoundryCallsOccured() throws Exception {
    // given// w w  w.j av a 2  s  .c om
    AppRouteCreatingStep step = new AppRouteCreatingStep(restTemplateMock, testCfApi, testAppGuid);

    // when
    when(domainsResponseMock.getBody()).thenReturn(validDomainsResponse);
    when(routesResponseMock.getBody()).thenReturn(oneRouteResponse);

    step.createAppRoute(testSpaceGuid, testSubdomain);

    // then
    verify(restTemplateMock).exchange(eq(testCfDomainsEndpoint), same(HttpMethod.GET),
            eq(HttpCommunication.simpleJsonRequest()), same(String.class));
    verify(restTemplateMock).exchange(eq(testCfGetRoutesEndpoint), same(HttpMethod.GET),
            eq(HttpCommunication.simpleJsonRequest()), same(String.class), eq(testSubdomain),
            eq(testDomainGuid));
    verify(restTemplateMock).exchange(eq(testCfBindRouteEndpoint), same(HttpMethod.PUT),
            eq(HttpCommunication.simpleJsonRequest()), same(String.class), eq(testAppGuid), eq(testRouteGuid));

}

From source file:com.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java

@Test
public void restUnsupportedOperationErrorTest() throws IOException {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
    GraphQLServerRequest qlQuery = new GraphQLServerRequest("{viewer{ id }}");
    HttpEntity<GraphQLServerRequest> httpEntity = new HttpEntity<>(qlQuery, headers);

    ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + "/graphql", HttpMethod.PUT, httpEntity, GraphQLServerResult.class);

    GraphQLServerResult result = responseEntity.getBody();
    Assert.assertFalse(CollectionUtils.isEmpty(result.getErrors()));
    LOGGER.info(objectMapper.writeValueAsString(result));
}

From source file:io.bosh.client.jobs.SpringJobs.java

private Observable<Task> changeJobState(String deploymentName, Consumer<UriComponentsBuilder> builderCallback) {
    HttpHeaders headers = new HttpHeaders();
    headers.put("content-type", Arrays.asList("text/yaml"));

    return deployments.get(deploymentName)
            .flatMap(deployment -> exchangeForEntity(deployment.getRawManifest(), Void.class, headers,
                    HttpMethod.PUT, builder -> builderCallback.accept(builder)))
            .flatMap(response -> tasks.trackToCompletion(getTaskId(response)));
}

From source file:org.cloudfoundry.caldecott.client.HttpTunnel.java

private void sendBytes(byte[] bytes, long page) {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Auth-Token", auth);
    requestHeaders.set("Content-Length", bytes.length + "");
    String dataUrl = url + this.tunnelInfo.get("path_in") + "/" + page;
    HttpEntity<byte[]> requestEntity = new HttpEntity<byte[]>(bytes, requestHeaders);
    if (logger.isTraceEnabled()) {
        logger.trace("SENDING: " + printBytes(bytes));
    }/* w  w w  .  j  a  v a 2s  . c o  m*/
    ResponseEntity<?> response = restOperations.exchange(dataUrl, HttpMethod.PUT, requestEntity, null);
    if (logger.isDebugEnabled()) {
        logger.debug(
                "[" + bytes.length + " bytes] PUT to " + dataUrl + " resulted in: " + response.getStatusCode());
    }
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRouteCreatingStep.java

private void bindRouteToApp(String routeGuid, String appGuid) {
    String cfBindRouteToAppUrl = cfApiUrl + BIND_ROUTE_TO_APP_ENDPOINT_TEMPLATE;
    cfRestTemplate.exchange(cfBindRouteToAppUrl, HttpMethod.PUT, HttpCommunication.simpleJsonRequest(),
            String.class, appGuid, routeGuid);
}

From source file:com.appglu.impl.UserTemplate.java

/**
 * {@inheritDoc}//from   w w  w .  ja  v a  2 s. c om
 */
public void writeData(Map<String, Object> data) throws AppGluRestClientException {
    try {
        this.restOperations.exchange(DATA_URL, HttpMethod.PUT, new HttpEntity<Map<String, Object>>(data),
                Void.class);
    } catch (AppGluHttpUserUnauthorizedException e) {
        this.userSessionPersistence.logout();
        throw e;
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:org.zalando.boot.etcd.EtcdClientTest.java

@Test
public void putWithUnsetTtl() throws EtcdException {
    server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl="))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT))
            .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED))
            .andExpect(MockRestRequestMatchers.content().string("value=Hello+world"))
            .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_set.json"),
                    MediaType.APPLICATION_JSON));

    EtcdResponse response = client.put("sample", "Hello world", -1);
    Assert.assertNotNull("response", response);

    server.verify();/* ww  w .  ja v  a  2 s  . c o m*/
}