List of usage examples for org.springframework.http HttpMethod POST
HttpMethod POST
To view the source code for org.springframework.http HttpMethod POST.
Click Source Link
From source file:com.cemeterylistingswebtest.test.rest.LoginControllerTest.java
@Test(enabled = false) public void testCreate() { Long subID = new Long(17); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2008); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.DATE, 4); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); UserRole user = new UserRole.Builder().setLevel(1).build(); Subscriber newSub = new Subscriber.Builder().setEmail("manfredOsulivan@horseRaddish.com") .setFirstName("Manfred").setSurname("Osulivan").setPwd("applesandsuch").setUsername("ManiFredOssy") .setSubscriptionDate(javaSqlDate).setUserRoleID(user).build(); HttpEntity<Subscriber> requestEntity = new HttpEntity<>(newSub, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/Subscriber/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 = newSub.getSubscriberID();/*from w w w . j a v a 2s .co m*/ }
From source file:org.openlmis.fulfillment.service.stockmanagement.StockEventStockManagementService.java
/** * Saves the given stock event to the stockmanagement service. * * @param stockEventDto the physical inventory to be submitted *//*from w ww . jav a 2s .co m*/ @SuppressWarnings("PMD.PreserveStackTrace") public void submit(StockEventDto stockEventDto) { String url = getServiceUrl() + getUrl(); LOGGER.debug("Sending Stock Events to Stock Management: {}", stockEventDto); try { restTemplate.exchange(createUri(url), HttpMethod.POST, createEntity(stockEventDto), UUID.class); } catch (HttpStatusCodeException ex) { if (ex.getStatusCode() == HttpStatus.BAD_REQUEST) { try { LocalizedMessageDto localizedMessage = objectMapper.readValue(ex.getResponseBodyAsString(), LocalizedMessageDto.class); throw new ExternalApiException(ex, localizedMessage); } catch (IOException ex2) { throw new ServerException(ex2, MessageKeys.ERROR_IO, ex2.getMessage()); } } else { throw buildDataRetrievalException(ex); } } }
From source file:org.cloudbyexample.dc.web.client.docker.ProvisionClient.java
@Override public ProvisionResponse provision(String uuid) { ProvisionResponse response = null;//from w w w . j av a 2s. c om String url = client.createUrl(PROVISION_REQUEST); logger.debug("REST client provision. uuid={} url='{}'", uuid, url); // response = client.getRestTemplate().postForObject(url, responseClazz, createUuidVar(uuid)); Map<String, String> vars = createUuidVar(uuid); response = client.getRestTemplate() .exchange(url, HttpMethod.POST, new HttpEntity(null), responseClazz, vars).getBody(); return response; }
From source file:org.awesomeagile.webapp.security.google.GoogleConfigurableOAuth2Template.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<String, String> parameters) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( parameters, headers);/*from w ww . jav a 2s . com*/ ResponseEntity<Map> responseEntity = getRestTemplate().exchange(accessTokenUrl, HttpMethod.POST, requestEntity, Map.class); Map<String, Object> responseMap = responseEntity.getBody(); return extractAccessGrant(responseMap); }
From source file:com.cisco.cta.taxii.adapter.RequestFactoryTest.java
private void initMocks() throws Exception { MockitoAnnotations.initMocks(this); when(httpRequestFactory.createRequest(new URI("http://somehost/service"), HttpMethod.POST)) .thenReturn(request);//from w w w. ja va 2 s .com when(request.getHeaders()).thenReturn(headers); when(request.getBody()).thenReturn(body); }
From source file:io.github.microcks.util.test.SoapHttpTestRunner.java
/** * Build the HttpMethod corresponding to string. Always POST for a SoapHttpTestRunner. *//* ww w . j a v a2 s . c om*/ @Override public HttpMethod buildMethod(String method) { return HttpMethod.POST; }
From source file:com.cemeterylistingswebtest.test.rest.RegistrationControllerTest.java
@Test(enabled = false) public void testCreate() { System.out.println("Registration Testing"); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2008); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.DATE, 4); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); UserRole user = new UserRole.Builder().setLevel(1).build(); Subscriber newSub = new Subscriber.Builder().setEmail("zaakir@gmail.com").setFirstName("zaakir") .setSurname("arendse").setPwd("123").setUsername("zak").setSubscriptionDate(javaSqlDate) .setUserRoleID(user).build(); HttpEntity<Subscriber> requestEntity = new HttpEntity<>(newSub, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/Registration/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 = newSub.getSubscriberID();//from w w w . j av a2s . c om }
From source file:com.cemeterylistingswebtest.test.rest.DisplayDeceasedControllerTest.java
@Test(enabled = false) public void testCreate() { System.out.println("PublishListingService 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/DeceasedListing/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.appglu.impl.UserTemplateTest.java
@Test public void signup() { responseHeaders.add(UserSessionPersistence.X_APPGLU_SESSION_HEADER, "sessionId"); 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.CREATED).body(compactedJson("data/user_auth_response")) .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.assertTrue(result.succeed()); Assert.assertTrue(appGluTemplate.isUserAuthenticated()); Assert.assertNotNull(appGluTemplate.getAuthenticatedUser()); Assert.assertEquals(new Long(1L), appGluTemplate.getAuthenticatedUser().getId()); Assert.assertEquals("username", appGluTemplate.getAuthenticatedUser().getUsername()); Assert.assertNull(appGluTemplate.getAuthenticatedUser().getPassword()); mockServer.verify();/* w w w. jav a 2 s. c o m*/ }
From source file:eu.cloudwave.wp5.feedbackhandler.rest.JsonRestClientImplTest.java
@Test public void testPost() throws UnsupportedEncodingException, IOException { setupExpectation(HttpMethod.POST); assertResponseOk(jsonRestClient.post(ANY_URL, RestRequestBody.of())); }