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:org.cloudfoundry.identity.uaa.login.integration.AutologinContollerIntegrationTests.java

@Test
public void testGetCode() {
    AutologinRequest request = new AutologinRequest();
    request.setUsername(testAccounts.getUserName());
    request.setPassword(testAccounts.getPassword());
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = serverRunning.getRestTemplate().exchange(serverRunning.getUrl("/autologin"),
            HttpMethod.POST, new HttpEntity<AutologinRequest>(request, headers), Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> result = (Map<String, Object>) entity.getBody();
    assertNotNull(result.get("code"));
}

From source file:simple.flow.Application.java

@Bean
public HttpRequestHandlingMessagingGateway httpGate1() {
    HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
    RequestMapping mapping = new RequestMapping();
    mapping.setMethods(HttpMethod.POST);
    mapping.setPathPatterns("/requestChannel1");
    gateway.setRequestMapping(mapping);/*  w  w w  .  j a va  2s  .c  om*/
    gateway.setRequestChannel(requestChannel1());
    gateway.setRequestPayloadType(String.class);
    return gateway;
}

From source file:com.consol.citrus.admin.connector.WebSocketPushMessageListener.java

/**
 * Push message to citrus-admin connector via REST API.
 * @param processId/*from w ww  .j  av a  2  s  . co m*/
 * @param message
 * @param direction
 */
protected void push(String processId, Message message, String direction) {
    try {
        if (!disabled) {
            ResponseEntity<String> response = getRestTemplate()
                    .exchange(
                            String.format("http://%s:%s/connector/message/%s?processId=%s", host, port,
                                    direction, processId),
                            HttpMethod.POST, new HttpEntity(message.toString()), String.class);

            if (response.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
                disabled = true;
            }
        }
    } catch (RestClientException e) {
        log.error("Failed to push message to citrus-admin connector", e);
    }
}

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

private AuthenticationResult authenticate(String url, UserBody user) {
    try {/* www  .  j  av  a2  s .c om*/
        ResponseEntity<UserBody> response = this.restOperations.exchange(url, HttpMethod.POST,
                new HttpEntity<UserBody>(user), UserBody.class);
        this.saveSessionId(response);
        this.saveAuthenticatedUser(response);
        return new AuthenticationResult(true);
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:eu.cloudwave.wp5.feedbackhandler.metricsources.NewRelicClientTest.java

@Test
public void testSummarized() throws MetricSourceClientException, IOException {
    final String url = "https://api.newrelic.com/v2/applications/0/metrics/data.json";
    final String applicationId = "0";
    final String className = "my.Class";
    final String methodName = "myMethod";

    final String response = getResourceAsString(RESPONSE_STUB_PATH);
    mockServer.expect(requestTo(url)).andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess(response, MediaType.APPLICATION_JSON));

    final MethodInfoSummarized actualResponse = newRelicClient.summarized(applicationId, className, methodName);
    assertThat(actualResponse).isEqualTo(DtoStubs.METHOD_INFO_SUMARIZED);
}

From source file:com.nobu.dvdrentalweb.test.restapi.AccountRestControllerTest.java

@Test
public void tesAcountsUpdate() {

    Account account = new Account.Builder().accountName("Savings").accountType("Gold Card").build();
    HttpEntity<Account> requestEntity = new HttpEntity<>(account, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/account/create", HttpMethod.POST,
            requestEntity, String.class);
    System.out.println(" THE RESPONSE BODY " + responseEntity.getBody());
    System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode());
    System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders());
    Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK);

}

From source file:com.cemeterylistingswebtest.test.rest.SearchSurnameControllerTest.java

@Test(enabled = false)
public void testCreate() {
    System.out.println("PublishedDeceasedListing Testing");

    Long subID = new Long(17);
    List<PersonOtherNames> names = null;

    PublishedDeceasedListing newListing = new PublishedDeceasedListing.Builder().setFirstName("Hendrika")
            .setSurname("Fourie").setMaidenName("Gerber").setGender("Female").setDateOfBirth("08/06/1969")
            .setDateOfDeath("14/02/2005").setGraveInscription("Hippiest person eva").setGraveNumber("2456")
            .setImageOfBurialSite("/images/001.jpg").setLastKnownContactName("Berry")
            .setLastKnownContactNumber("0725576482").setSubscriberSubmitID(subID).setNames(names).build();

    HttpEntity<PublishedDeceasedListing> requestEntity = new HttpEntity<>(newListing, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/SearchSurname/create",
            HttpMethod.POST, requestEntity, String.class);
    System.out.println(" THE RESPONSE BODY " + responseEntity.getBody());
    System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode());
    System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders());

    Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK);
    id = newListing.getPublishedListingID();
}

From source file:com.marklogic.samplestack.mock.MockApplicationSecurity.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers(HttpMethod.GET, "/session", "/questions/**", "/tags/**").permitAll()
            .and().authorizeRequests().antMatchers(HttpMethod.POST, "/search").permitAll().and()
            .authorizeRequests().antMatchers("/questions/**", "/contributors/**").authenticated().and()
            .authorizeRequests().anyRequest().denyAll();
    http.formLogin().failureHandler(failureHandler).successHandler(successHandler).permitAll().and().logout()
            .logoutSuccessHandler(logoutSuccessHandler).permitAll();
    http.csrf().disable();/*from   w  w w  .j  a v a 2  s  . c  om*/
    http.exceptionHandling().authenticationEntryPoint(entryPoint)
            .accessDeniedHandler(samplestackAccessDeniedHandler);

}

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

@Test
public void runQuery() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/queries/queryName/run"))
            .andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", jsonMediaType.toString()))
            .andExpect(content().string(compactedJson("data/saved_queries_params"))).andRespond(
                    withSuccess().body(compactedJson("data/saved_queries_result")).headers(responseHeaders));

    QueryResult result = savedQueriesOperations.runQuery("queryName", queryParams());

    Assert.assertEquals(3, result.getRows().size());
    Assert.assertNull(result.getRowsAffected());

    assertRow(result.getRows().get(0));//from w  ww.  j a  v a  2s .  c om
    assertRow(result.getRows().get(1));
    assertRow(result.getRows().get(2));

    mockServer.verify();
}

From source file:org.cloudfoundry.identity.uaa.login.test.TestClient.java

public String getOAuthAccessToken(String username, String password, String grantType, String scope) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", getBasicAuthHeaderValue(username, password));

    MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>();
    postParameters.add("grant_type", grantType);
    postParameters.add("client_id", username);
    postParameters.add("scope", scope);

    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(
            postParameters, headers);/*from   ww  w. jav  a2 s. c  o  m*/

    ResponseEntity<Map> exchange = restTemplate.exchange(baseUrl + "/oauth/token", HttpMethod.POST,
            requestEntity, Map.class);

    return exchange.getBody().get("access_token").toString();
}