Example usage for org.springframework.http HttpMethod POST

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

Introduction

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

Prototype

HttpMethod POST

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

Click Source Link

Usage

From source file:com.teradata.benchto.driver.DriverAppIntegrationTest.java

private void verifyExecutionFinished(String uniqueBenchmarkName, int executionNumber,
        List<String> measurementNames) {
    restServiceServer/*ww w  . ja  v  a  2s .c o m*/
            .expect(matchAll(
                    requestTo("http://benchmark-service:8080/v1/benchmark/" + uniqueBenchmarkName
                            + "/BEN_SEQ_ID/execution/" + executionNumber + "/finish"),
                    method(HttpMethod.POST), jsonPath("$.status", ENDED_STATUS_MATCHER),
                    jsonPath("$.measurements.[*].name", containsInAnyOrder(measurementNames.toArray()))))
            .andRespond(withSuccess());
}

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

@Test
// CFID-372//from w w  w . jav a 2  s .  c om
public void testCreateExistingClientFails() throws Exception {
    BaseClientDetails client = createClient("client_credentials");

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> attempt = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/oauth/clients"), HttpMethod.POST,
            new HttpEntity<BaseClientDetails>(client, headers), Map.class);
    assertEquals(HttpStatus.CONFLICT, attempt.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, String> map = attempt.getBody();
    assertEquals("invalid_client", map.get("error"));
}

From source file:fr.treeptik.cloudunit.cli.rest.RestUtils.java

/**
 * sendPostCommand/*from  w ww.  j av  a2  s .c  o  m*/
 *
 * @param url
 * @param parameters
 * @return
 * @throws ClientProtocolException
 */
public Map<String, Object> sendPostForUpload(String url, Map<String, Object> parameters) {
    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
    mc.add(new MappingJacksonHttpMessageConverter());
    restTemplate.setMessageConverters(mc);
    MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<String, Object>();
    postParams.setAll(parameters);
    Map<String, Object> response = new HashMap<String, Object>();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type", "multipart/form-data");
    headers.set("Accept", "application/json");
    headers.add("Cookie", "JSESSIONID=" + localContext.getCookieStore().getCookies().get(0).getValue());
    org.springframework.http.HttpEntity<Object> request = new org.springframework.http.HttpEntity<Object>(
            postParams, headers);
    ResponseEntity<?> result = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
    String body = result.getBody().toString();
    MediaType contentType = result.getHeaders().getContentType();
    HttpStatus statusCode = result.getStatusCode();
    response.put("content-type", contentType);
    response.put("statusCode", statusCode);
    response.put("body", body);

    return response;

}

From source file:jp.go.aist.six.util.core.web.spring.SpringHttpClientImpl.java

/**
 * HTTP POST: Reads the contents from the specified stream and sends them to the URL.
 *
 * @return/*from w w  w.ja va 2 s .co m*/
 *  the location, as an URI, where the resource is created.
 * @throws  HttpException
 *  when an exceptional condition occurred during the HTTP method execution.
 */
public String postByRead(final String url, final InputStream input, final String media_type) {
    InputStreamRequestCallback callback = new InputStreamRequestCallback(input, MediaType.valueOf(media_type));
    String location = _execute(url, HttpMethod.POST, callback, new LocationHeaderResponseExtractor());

    return location;
}

From source file:org.cloudfoundry.identity.uaa.login.feature.OpenIdTokenGrantsIT.java

@Test
public void testPasswordGrant() throws Exception {
    String basicDigestHeaderValue = "Basic " + new String(Base64.encodeBase64(("cf:").getBytes()));

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.set("Authorization", basicDigestHeaderValue);

    LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>();
    postBody.add("client_id", "cf");
    postBody.add("redirect_uri", "https://uaa.cloudfoundry.com/redirect/cf");
    postBody.add("response_type", "token id_token");
    postBody.add("grant_type", "password");
    postBody.add("username", user.getUserName());
    postBody.add("password", "secret");

    ResponseEntity<Map> responseEntity = restOperations.exchange(loginUrl + "/oauth/token", HttpMethod.POST,
            new HttpEntity<>(postBody, headers), Map.class);

    Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());

    Map<String, Object> params = responseEntity.getBody();

    Assert.assertTrue(params.get("jti") != null);
    Assert.assertEquals("bearer", params.get("token_type"));
    Assert.assertThat((Integer) params.get("expires_in"), Matchers.greaterThan(40000));

    String[] scopes = UriUtils.decode((String) params.get("scope"), "UTF-8").split(" ");
    Assert.assertThat(Arrays.asList(scopes), containsInAnyOrder("scim.userids", "password.write",
            "cloud_controller.write", "openid", "cloud_controller.read"));

    validateToken("access_token", params, scopes);
    validateToken("id_token", params, scopes);
}

From source file:com.sitewhere.rest.service.SiteWhereClient.java

@Override
public DeviceEventBatchResponse addDeviceEventBatch(String hardwareId, DeviceEventBatch batch)
        throws SiteWhereException {
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("hardwareId", hardwareId);
    return sendRest(getBaseUrl() + "devices/{hardwareId}/batch", HttpMethod.POST, batch,
            DeviceEventBatchResponse.class, vars);
}

From source file:org.cloudfoundry.identity.uaa.login.feature.AutologinIT.java

@Test
public void testClientIdMustBeConsistent() throws Exception {
    webDriver.get(baseUrl + "/logout.do");

    HttpHeaders headers = getAppBasicAuthHttpHeaders();

    Map<String, String> requestBody = new HashMap<>();
    requestBody.put("username", testAccounts.getUserName());
    requestBody.put("password", testAccounts.getPassword());

    ResponseEntity<Map> autologinResponseEntity = restOperations.exchange(baseUrl + "/autologin",
            HttpMethod.POST, new HttpEntity<>(requestBody, headers), Map.class);
    String autologinCode = (String) autologinResponseEntity.getBody().get("code");

    String authorizeUrl = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/oauth/authorize")
            .queryParam("redirect_uri", appUrl).queryParam("response_type", "code")
            .queryParam("scope", "openid").queryParam("client_id", "stealer_of_codes")
            .queryParam("code", autologinCode).build().toUriString();

    try {/*from  w  w  w.j  a  va2 s.  co m*/
        restOperations.exchange(authorizeUrl, HttpMethod.GET, null, Void.class);
    } catch (HttpClientErrorException e) {
        assertEquals(HttpStatus.UNAUTHORIZED, e.getStatusCode());
    }
}

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

@Test
public void logoutUnauthorized() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/users/logout")).andExpect(method(HttpMethod.POST))
            .andExpect(header(UserSessionPersistence.X_APPGLU_SESSION_HEADER, "sessionId"))
            .andRespond(withStatus(HttpStatus.UNAUTHORIZED).body(compactedJson("data/user_unauthorized"))
                    .headers(responseHeaders));

    Assert.assertFalse(appGluTemplate.isUserAuthenticated());
    Assert.assertNull(appGluTemplate.getAuthenticatedUser());

    appGluTemplate.setUserSessionPersistence(new LoggedInUserSessionPersistence("sessionId", new User("test")));

    Assert.assertTrue(appGluTemplate.isUserAuthenticated());
    Assert.assertNotNull(appGluTemplate.getAuthenticatedUser());

    boolean succeed = userOperations.logout();
    Assert.assertFalse(succeed);/*from w w w .  j a v  a  2 s  .  c o  m*/

    Assert.assertFalse(appGluTemplate.isUserAuthenticated());
    Assert.assertNull(appGluTemplate.getAuthenticatedUser());

    mockServer.verify();
}

From source file:com.projectx.mvc.servicehandler.quickregister.QuickRegisterHandler.java

@Override
public Boolean reSetMobilePin(CustomerIdTypeMobileTypeDTO customerDTO) {

    HttpEntity<CustomerIdTypeMobileTypeDTO> entity = new HttpEntity<CustomerIdTypeMobileTypeDTO>(customerDTO);

    ResponseEntity<Boolean> detailsSentStatus = restTemplate.exchange(
            env.getProperty("rest.host") + "/customer/quickregister/resetMobilePin", HttpMethod.POST, entity,
            Boolean.class);

    if (detailsSentStatus.getStatusCode() == HttpStatus.OK)
        return detailsSentStatus.getBody();
    else//from  w ww. j a v  a2 s. c  om
        throw new ResourceNotFoundException();

}