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.may.ple.parking.gateway.activity.GateOutActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
        if (resultCode == RESULT_OK) {
            String licenseNo = data.getStringExtra("result");

            VehicleCheckOutCriteriaReq req = new VehicleCheckOutCriteriaReq();
            req.licenseNo = licenseNo;//from  w w w .j a  va 2s  .co m
            req.reasonNoScan = reasonNoScan;
            req.deviceId = ApplicationScope.getInstance().deviceId;
            req.gateName = gateName;

            service.passedParam = req;
            service.send(1, req, VehicleCheckOutCriteriaResp.class, "/restAct/vehicle/checkOutVehicle",
                    HttpMethod.POST);
            spinner.show();
        }
    }
}

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

@Test
public void noSessions() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/analytics")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", jsonMediaType.toString()))
            .andExpect(content().string(compactedJson("data/analytics_no_sessions")))
            .andRespond(withStatus(HttpStatus.CREATED).body("").headers(responseHeaders));

    analyticsOperations.uploadSessions(new ArrayList<AnalyticsSession>());

    mockServer.verify();// w  ww  .  jav a2  s.  c  o  m
}

From source file:com.orange.ngsi.client.NgsiRestClientTest.java

@Test
public void testAppendContextElement_JSON() throws Exception {
    String responseBody = json(jsonConverter, createAppendContextElementResponseTemperature());

    mockServer.expect(requestTo(baseUrl + "/ngsi10/contextEntities/123")).andExpect(method(HttpMethod.POST))
            .andExpect(jsonPath("$.attributes").isArray())
            .andExpect(jsonPath("$.attributes[0].name").value("temp"))
            .andExpect(jsonPath("$.attributes[0].type").value("float"))
            .andExpect(jsonPath("$.attributes[0].value").value("15.5"))
            .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));

    AppendContextElementResponse response = ngsiRestClient
            .appendContextElement(baseUrl, null, "123", Util.createAppendContextElementTemperature()).get();

    this.mockServer.verify();

    assertNull(response.getErrorCode());
    assertNotNull(response.getContextAttributeResponses());
    assertEquals(1, response.getContextAttributeResponses().size());
    assertNotNull(response.getContextAttributeResponses().get(0).getContextAttributeList());
    assertEquals(1, response.getContextAttributeResponses().get(0).getContextAttributeList().size());
    assertNotNull(response.getContextAttributeResponses().get(0).getContextAttributeList().get(0));
    assertEquals("temp",
            response.getContextAttributeResponses().get(0).getContextAttributeList().get(0).getName());
    assertEquals("float",
            response.getContextAttributeResponses().get(0).getContextAttributeList().get(0).getType());
    assertEquals("15.5",
            response.getContextAttributeResponses().get(0).getContextAttributeList().get(0).getValue());
    assertEquals(CodeEnum.CODE_200.getLabel(),
            response.getContextAttributeResponses().get(0).getStatusCode().getCode());
}

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

@Test
public void testCreatePageWithPaginationModeSingleWithOrphanFailSafe() {
    final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig();
    swaggerConfluenceConfig.setAncestorId(null);

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

    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class), eq(String.class)))
            .thenReturn(responseEntity, responseEntity);
    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)))
            .thenReturn(responseEntity);
    when(responseEntity.getBody()).thenReturn(GET_RESPONSE_NOT_FOUND, GET_RESPONSE_FOUND, POST_RESPONSE);

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

    xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml);

    verify(restTemplate, times(2)).exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class),
            eq(String.class));
    verify(restTemplate).exchange(any(URI.class), eq(HttpMethod.POST), httpEntityCaptor.capture(),
            eq(String.class));

    final HttpEntity<String> capturedHttpEntity = httpEntityCaptor.getValue();

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

    assertNotNull("Failed to Capture RequestEntity for POST", capturedHttpEntity);
    assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody());
}

From source file:com.ginema.ApplicationTests.java

@Test
public void loginSucceeds() {
    ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + "/ginema-server/login",
            String.class);
    String csrf = getCsrf(response.getBody());
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", "user");
    form.set("password", "password");
    form.set("_csrf", csrf);
    HttpHeaders headers = new HttpHeaders();
    headers.put("COOKIE", response.getHeaders().get("Set-Cookie"));
    RequestEntity<MultiValueMap<String, String>> request = new RequestEntity<MultiValueMap<String, String>>(
            form, headers, HttpMethod.POST, URI.create("http://localhost:" + port + "/ginema-server/login"));
    ResponseEntity<Void> location = template.exchange(request, Void.class);
    assertEquals("http://localhost:" + port + "/ginema-server/", location.getHeaders().getFirst("Location"));
}

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

@Test
public void testUpdateHackpad() {
    String newContent = "<html><body>This is a new content</body></html>";
    String padId = RandomStringUtils.randomAlphanumeric(16);
    mockServer.expect(requestTo("http://test/api/1.0/pad/" + padId + "/content"))
            .andExpect(method(HttpMethod.POST)).andExpect(header(HTTP.CONTENT_TYPE, MediaType.TEXT_HTML_VALUE))
            .andExpect(content().string(newContent))
            .andRespond(withSuccess("{\"success\": true}", MediaType.APPLICATION_JSON));

    client.updateHackpad(new PadIdentity(padId), newContent);
    mockServer.verify();/*from  w w  w.j av  a 2  s.  c o  m*/
}

From source file:com.interop.webapp.WebAppTests.java

@Test
public void testLogin() throws Exception {
    HttpHeaders headers = getHeaders();//w ww .ja  va  2 s. c om
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", "user");
    form.set("password", "user");
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/login",
            HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class);
    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
    assertTrue("Wrong location:\n" + entity.getHeaders(),
            entity.getHeaders().getLocation().toString().endsWith(port + "/"));
    assertNotNull("Missing cookie:\n" + entity.getHeaders(), entity.getHeaders().get("Set-Cookie"));
}

From source file:io.getlime.push.service.fcm.FcmClient.java

/**
 * Send given FCM request to the server.
 * @param request FCM data request./*from  w  w  w .  j  a  va  2  s  .co m*/
 * @return Listenable future for result callbacks.
 */
public ListenableFuture<ResponseEntity<FcmSendResponse>> exchange(FcmSendRequest request) {
    HttpEntity<FcmSendRequest> entity = new HttpEntity<>(request, headers);
    return restTemplate.exchange(fcm_url, HttpMethod.POST, entity, FcmSendResponse.class);
}

From source file:ru.mystamps.web.support.spring.security.SecurityConfig.java

@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().mvcMatchers(Url.ADD_CATEGORY_PAGE).hasAuthority(StringAuthority.CREATE_CATEGORY)
            .mvcMatchers(Url.ADD_COUNTRY_PAGE).hasAuthority(StringAuthority.CREATE_COUNTRY)
            .mvcMatchers(Url.ADD_SERIES_PAGE).hasAuthority(StringAuthority.CREATE_SERIES)
            .mvcMatchers(Url.SITE_EVENTS_PAGE).hasAuthority(StringAuthority.VIEW_SITE_EVENTS)
            .regexMatchers(HttpMethod.POST, "/series/[0-9]+")
            .hasAnyAuthority(StringAuthority.UPDATE_COLLECTION, StringAuthority.ADD_IMAGES_TO_SERIES)
            .regexMatchers(HttpMethod.POST, Url.ADD_SERIES_ASK_PAGE.replace("{id}", "[0-9]+"))
            .hasAuthority(StringAuthority.ADD_SERIES_SALES).anyRequest().permitAll().and().formLogin()
            .loginPage(Url.AUTHENTICATION_PAGE).usernameParameter("login").passwordParameter("password")
            .loginProcessingUrl(Url.LOGIN_PAGE).failureUrl(Url.AUTHENTICATION_PAGE + "?failed")
            .defaultSuccessUrl(Url.INDEX_PAGE, true).permitAll().and().logout().logoutUrl(Url.LOGOUT_PAGE)
            .logoutSuccessUrl(Url.INDEX_PAGE).invalidateHttpSession(true).permitAll().and().exceptionHandling()
            .accessDeniedHandler(getAccessDeniedHandler())
            // This entry point handles when you request a protected page and you are
            // not yet authenticated
            .authenticationEntryPoint(new Http403ForbiddenEntryPoint()).and().csrf()
            // Allow unsecured requests to H2 consoles.
            .ignoringAntMatchers("/console/**").and().rememberMe()
            // TODO: GH #27
            .disable().headers()/*from   ww w  .j  a  va 2  s . c om*/
            // TODO
            .disable();
}

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

@Test
public void signupUsernameExists() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/users")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", jsonMediaType.toString()))
            .andExpect(content().string(compactedJson("data/user_signup")))
            .andRespond(withStatus(HttpStatus.CONFLICT).body(compactedJson("data/user_signup_username_exists"))
                    .headers(responseHeaders));

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

    User user = new User();

    user.setUsername("username");
    user.setPassword("password");

    AuthenticationResult result = userOperations.signup(user);
    Assert.assertFalse(result.succeed());

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

    Assert.assertEquals(ErrorCode.APP_USER_USERNAME_ALREADY_USED, result.getError().getCode());
    Assert.assertEquals("There is already an user with this username.", result.getError().getMessage());

    mockServer.verify();/*from  w  w w  .  jav a  2s. c  o  m*/
}