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:core.sfdc.SalesforceService.java

public List<LicenseResponse> syncNIPRLicenses(List<LicenseInternal> licenses) throws Exception {
    List<LicenseResponse> licenseResponses = new ArrayList<LicenseResponse>();

    if (licenses.size() == 0) {
        return licenseResponses;
    }//from  w w  w  . j  ava  2 s  .  c om

    ObjectMapper objectMapper = new ObjectMapper();
    String requestBody = objectMapper.writeValueAsString(licenses);
    LicenseResponse[] responses = this.restClient.apexRest(NIPR_LICENSE_SYNC, HttpMethod.POST, requestBody,
            LicenseResponse[].class);
    licenseResponses = Arrays.asList(responses);

    return licenseResponses;
}

From source file:com.mycompany.CPUTAuction.restapi.BidRestControllerTest.java

@Test
public void tesBidUpdate() {
    // LEFT AS AN EXERCISE FOR YOU
    // GET THE CLUB and THEN CHANGE AND MAKE A COPY
    //THEN SEND TO THE SERVER USING A PUT OR POST
    // THEN READ BACK TO SEE IF YOUR CHANGE HAS HAPPENED
    //Bid club = new Bid.Builder("Hackers").build();
    Bid bid = new Bid.Builder(1001).amount(300).build();

    HttpEntity<Bid> requestEntity = new HttpEntity<>(bid, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/bid/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:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRecordCreatingStepTest.java

@Test
public void createAppRecord_callToCfApiOccured() throws Exception {
    // given//  www.ja  v a  2  s .com
    AppRecordCreatingStep step = new AppRecordCreatingStep(testCfApi, restTemplateMock);

    // when
    when(responseMock.getBody()).thenReturn(validResponseMock);
    step.createAppRecord(spaceGuid, appName);

    // then
    verify(restTemplateMock).exchange(eq(cfAppsEndpoint), same(HttpMethod.POST),
            eq(HttpCommunication.postRequest(expectedRequestBody)), eq(String.class));
}

From source file:com.marklogic.samplestack.security.ApplicationSecurity.java

@Override
/**// w w  w .ja v a2 s  .com
 * Standard practice in Spring Security is to provide
 * this implementation method for building security.  This method
 * configures the endpoints' security characteristics.
 * @param http  Security object projided by the framework.
 */
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();
    http.exceptionHandling().authenticationEntryPoint(entryPoint)
            .accessDeniedHandler(samplestackAccessDeniedHandler);

}

From source file:com.jiwhiz.rest.user.PostCommentRestControllerTest.java

@Test
public void postComment_ShouldAddNewComment() throws Exception {
    final String NEW_COMMENT_TXT = "New comment test.";
    UserAccount user = getTestLoggedInUserWithAuthorRole();
    BlogPost blog = getTestSinglePublishedBlogPost();
    CommentPost comment = new CommentPost(user, blog, NEW_COMMENT_TXT);
    comment.setId("newCommId");

    when(userAccountServiceMock.getCurrentUser()).thenReturn(user);
    when(blogPostRepositoryMock.findOne(eq(BLOG_ID))).thenReturn(blog);
    when(commentPostServiceMock.postComment(eq(user), eq(blog), anyString())).thenReturn(comment);

    CommentForm newComment = new CommentForm();
    mockMvc.perform(request(HttpMethod.POST, API_ROOT + URL_USER_BLOGS_BLOG_COMMENTS, BLOG_ID)
            .contentType(MediaType.APPLICATION_JSON).content(TestUtils.convertObjectToJsonBytes(newComment)))
            .andExpect(status().isCreated())
            .andExpect(header().string("Location", endsWith(API_ROOT + URL_USER_COMMENTS + "/newCommId")))
            .andExpect(content().string(""));
}

From source file:org.openlmis.fulfillment.service.referencedata.UserReferenceDataServiceTest.java

@Test
public void shouldFindUserByName() {
    // given/*w  w  w  . j  ava 2  s .  c  om*/
    String name = "userName";

    UserDto userDto = generateInstance();
    userDto.setUsername(name);

    Map<String, Object> payload = new HashMap<>();
    payload.put("username", name);

    ResponseEntity response = mock(ResponseEntity.class);

    // when
    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.POST), any(HttpEntity.class),
            any(ParameterizedTypeReference.class))).thenReturn(response);

    PageDto<UserDto> page = new PageDto<>(new PageImpl<>(ImmutableList.of(userDto)));

    when(response.getBody()).thenReturn(page);

    UserDto user = service.findUser(name);

    // then
    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.POST), entityCaptor.capture(),
            any(ParameterizedTypeReference.class));

    URI uri = uriCaptor.getValue();
    String url = service.getServiceUrl() + service.getUrl() + "search";

    assertThat(uri.toString(), is(equalTo(url)));
    assertThat(user.getUsername(), is(equalTo(name)));

    assertAuthHeader(entityCaptor.getValue());
    assertThat(entityCaptor.getValue().getBody(), is(payload));
}

From source file:org.awesomeagile.integrations.hackpad.HackpadClientTest.java

@Test
public void testCreateHackpad() {
    mockServer.expect(requestTo("http://test/api/1.0/pad/create")).andExpect(method(HttpMethod.POST))
            .andExpect(header(HTTP.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE))
            .andExpect(content().string("The Title"))
            .andRespond(withSuccess("{\"padId\":\"C0E68BD495E9\"}", MediaType.APPLICATION_JSON));

    PadIdentity id = client.createHackpad("The Title");
    assertEquals("C0E68BD495E9", id.getPadId());
}

From source file:com.citrix.g2w.webdriver.dependencies.AuthServiceImpl.java

/**
 * Method to get auth token from auth service
 *
 * @param userId/*from   www .  ja va 2s. c om*/
 *            (user id)
 * @param password
 *            (user password)
 */
@Override
public String getAuthToken(final String userId, final String password) {
    HttpEntity httpEntity = new HttpEntity(
            "{\"username\":\"" + userId + "\",\"password\":\"" + password + "\"}", authSvcHeaders);
    String result = this.restTemplate
            .exchange(this.authSvcUrl + "/tokens", HttpMethod.POST, httpEntity, String.class).getBody();
    try {
        JSONObject json = new JSONObject(result);
        Thread.sleep(2000);
        return json.getString("token");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:simple.flow.Application.java

@Bean
public HttpRequestHandlingMessagingGateway httpGate2() {
    HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
    RequestMapping mapping = new RequestMapping();
    mapping.setMethods(HttpMethod.POST);
    mapping.setPathPatterns("/requestChannel2");
    gateway.setRequestMapping(mapping);/*w w w  .  j  av a 2 s  .  c  o  m*/
    gateway.setRequestChannel(requestChannel2());
    gateway.setRequestPayloadType(String.class);
    return gateway;
}