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.zalando.boot.etcd.EtcdClient.java

/**
 * Atomically updates a key-value pair in etcd.
 * //ww w.  j  a  v a  2s . c  o m
 * @param key
 *            the key
 * @param value
 *            the value
 * @param ttl
 *            the time-to-live
 * @param prevIndex
 *            the modified index of the key
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse compareAndSwap(String key, String value, int ttl, int prevIndex) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("ttl", ttl == -1 ? "" : ttl);
    builder.queryParam("prevIndex", prevIndex);

    MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1);
    payload.set("value", value);

    return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class);
}

From source file:org.cbioportal.session_service.SessionServiceTest.java

@Test
public void updateSessionInvalidData() throws Exception {
    String data = "\"portal-session\":{\"arg1\":\"first argument\"}";
    ResponseEntity<String> response = addData("msk_portal", "main_session", data);

    // get id/*from  ww w . j av a  2  s  .c o m*/
    List<String> ids = parseIds(response.getBody());
    assertThat(ids.size(), equalTo(1));
    String id = ids.get(0);

    HttpEntity<String> entity = prepareData("\"portal-session\":blah blah blah");
    response = template.exchange(base.toString() + "msk_portal/main_session/" + id, HttpMethod.PUT, entity,
            String.class);
    assertThat(response.getBody(),
            containsString("org.cbioportal.session_service.service.exception.SessionInvalidException"));
    assertThat(response.getStatusCode(), equalTo(HttpStatus.BAD_REQUEST));
}

From source file:org.trustedanalytics.servicebroker.gearpump.service.CloudFoundryService.java

private void restartUIApp(String uiAppGuid) throws IOException {
    LOGGER.info("Stopping ui app");
    execute(UPDATE_APP_URL, HttpMethod.PUT, STATUS_STOPPED_BODY, cfApiEndpoint, uiAppGuid);
    LOGGER.info("Starting ui app");
    execute(UPDATE_APP_URL, HttpMethod.PUT, STATUS_STARTED_BODY, cfApiEndpoint, uiAppGuid);
    LOGGER.info("Waiting ui to start");

    String status = "";
    int statusCheckNr = 0;
    ResponseEntity<String> response;
    while (!status.equals(UI_OK_STATUS) && statusCheckNr < UI_MAX_STATUS_CHECK) {
        response = execute(GET_STATUS_APP_URL, HttpMethod.GET, null, cfApiEndpoint, uiAppGuid);
        status = cfCaller.getValueFromJson(response.getBody(), APP_STATUS);
        LOGGER.debug("UI app status check nr {}: {}", statusCheckNr, status);
        statusCheckNr++;/*from w w w .  jav  a  2s.  c  o  m*/
    }
}

From source file:com.all.ultrapeer.services.UserProfileService.java

@MessageMethod(UPDATE_USER_QUOTE_TYPE)
public void processUpdateQuoteMessage(AllMessage<String> message) {
    log.info("Processing a quote update request from " + message.getProperty(SENDER_ID));
    String[] urlVars = BackendProxy.urlVars(message.getProperty(SENDER_ID));
    String[][] headers = BackendProxy.headers(
            BackendProxy.header(MessEngineConstants.PUSH_TO, message.getProperty(MessEngineConstants.PUSH_TO)));
    userBackend.send("updateQuoteUrl", HttpMethod.PUT, message.getBody(), urlVars, headers);

}

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

@Test
public void compareAndSwapWithPrevValueAndUnsetTtl() throws EtcdException {
    server.expect(MockRestRequestMatchers
            .requestTo("http://localhost:2379/v2/keys/sample?ttl=&prevValue=Hello%20etcd"))
            .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_delete.json"),
                            MediaType.APPLICATION_JSON));

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

    server.verify();/*from   w w  w.  j  a  va2  s . c  o m*/
}

From source file:org.cbioportal.session_service.SessionServiceTest.java

@Test
public void updateSessionInvalidId() throws Exception {
    HttpEntity<String> entity = prepareData("\"portal-session\":\"my session information\"");
    ResponseEntity<String> response = template.exchange(base.toString() + "msk_portal/main_session/id",
            HttpMethod.PUT, entity, String.class);
    assertThat(response.getBody(),// w w w .  ja  v a 2s . co  m
            containsString("org.cbioportal.session_service.service.exception.SessionNotFoundException"));
    assertThat(response.getStatusCode(), equalTo(HttpStatus.NOT_FOUND));
}

From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImplTest.java

@Test
public void testUpdatePageWithPaginationModeIndividual() {
    final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig();
    swaggerConfluenceConfig.setPaginationMode(PaginationMode.INDIVIDUAL_PAGES);

    final String xhtml = IOUtils.readFull(
            AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream("/swagger-petstore-xhtml-example.html"));

    final ResponseEntity<String> postResponseEntity = new ResponseEntity<>(POST_RESPONSE, HttpStatus.OK);

    final List<String> returnJson = new ArrayList<>();

    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class), eq(String.class)))
            .thenReturn(responseEntity);

    for (int i = 0; i < 34; i++) {
        if (i > 0) {
            returnJson.add(GET_RESPONSE_FOUND);
        }//from ww w  . java  2s  . c om

        if (CATEGORY_INDEXES.contains(i)) {
            returnJson.add(GET_CHILDREN);
        }
    }

    final String[] returnJsonArray = new String[returnJson.size()];
    returnJson.toArray(returnJsonArray);

    when(responseEntity.getBody()).thenReturn(GET_RESPONSE_FOUND, returnJsonArray);

    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.DELETE), any(RequestEntity.class),
            eq(String.class))).thenReturn(responseEntity);
    when(responseEntity.getStatusCode()).thenReturn(HttpStatus.NO_CONTENT);

    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.PUT), any(RequestEntity.class), eq(String.class)))
            .thenReturn(postResponseEntity);

    final ArgumentCaptor<HttpEntity> httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class);

    xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml);

    verify(restTemplate, times(38)).exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class),
            eq(String.class));
    verify(restTemplate, times(34)).exchange(any(URI.class), eq(HttpMethod.PUT), httpEntityCaptor.capture(),
            eq(String.class));

    final HttpEntity<String> capturedHttpEntity = httpEntityCaptor.getAllValues().get(30);

    final String expectedPostBody = IOUtils.readFull(AsciiDocToXHtmlServiceImplTest.class
            .getResourceAsStream("/swagger-confluence-update-json-body-user-example.json"));

    assertNotNull("Failed to Capture RequestEntity for POST", capturedHttpEntity);
    // We'll do a full check on the last page versus a resource; not doing all of them as it
    // would be a pain to maintain, but this should give us a nod of confidence.
    assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody());
}

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

/**
 * Atomically updates a key-value pair in etcd.
 * /*  w ww.  j av  a  2  s .c o m*/
 * @param key
 *            the key
 * @param value
 *            the value
 * @param prevValue
 *            the previous value of the key
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse compareAndSwap(String key, String value, String prevValue) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("prevValue", prevValue);

    MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1);
    payload.set("value", value);

    return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class);
}

From source file:org.cbioportal.session_service.SessionServiceTest.java

@Test
public void updateSessionNoData() throws Exception {
    String data = "\"portal-session\":\"my session information\"";
    ResponseEntity<String> response = addData("msk_portal", "main_session", data);

    // get id/*from  ww  w.ja  v a  2  s .  c  o  m*/
    List<String> ids = parseIds(response.getBody());
    assertThat(ids.size(), equalTo(1));
    String id = ids.get(0);

    HttpEntity<String> entity = prepareData(null);
    response = template.exchange(base.toString() + "msk_portal/main_session/" + id, HttpMethod.PUT, entity,
            String.class);

    assertThat(response.getBody(), containsString("Required request body is missing"));
    assertThat(response.getStatusCode(), equalTo(HttpStatus.BAD_REQUEST));
}

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

/**
 * Atomically updates a key-value pair in etcd.
 * //from   w w w.  j  a v  a 2s  .co  m
 * @param key
 *            the key
 * @param value
 *            the value
 * @param ttl
 *            the time-to-live
 * @param prevValue
 *            the previous value of the key
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse compareAndSwap(String key, String value, int ttl, String prevValue) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("ttl", ttl == -1 ? "" : ttl);
    builder.queryParam("prevValue", prevValue);

    MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1);
    payload.set("value", value);

    return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class);
}