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.formkiq.web.AbstractIntegrationTest.java
/** * Add File to Folder./*from w ww. ja va 2 s . c om*/ * @param token {@link String} * @param folder {@link String} * @param data byte[] * @return {@link ResponseEntity} */ protected ResponseEntity<String> addFileToFolder(final String token, final String folder, final byte[] data) { String url = getDefaultHostAndPort() + API_FOLDER_FILE + "/" + folder + "?access_token=" + token; ResponseEntity<String> entity = exchangeRest(HttpMethod.POST, url, data, String.class); assertEquals("{\"message\":\"Save successful\"}", entity.getBody()); assertEquals(SC_OK, entity.getStatusCode().value()); return entity; }
From source file:com.projectx.mvc.servicehandler.quickregister.QuickRegisterHandler.java
@Override public Boolean verifyMobile(VerifyMobileDTO mobileDTO) { HttpEntity<VerifyMobileDTO> entity = new HttpEntity<VerifyMobileDTO>(mobileDTO); ResponseEntity<Boolean> verificationStatus = restTemplate.exchange( env.getProperty("rest.host") + "/customer/quickregister/verifyMobilePin", HttpMethod.POST, entity, Boolean.class); if (verificationStatus.getStatusCode() == HttpStatus.OK) return verificationStatus.getBody(); else/*from www. j a v a 2s .co m*/ throw new ResourceNotFoundException(); }
From source file:com.taxamo.example.ec.ApplicationController.java
/** * This method is invoked after Taxamo has successfully verified tax location evidence and * created a transaction./*www . j a v a 2 s .co m*/ * * Two things happen then: * - first, the express checkout token is used to capture payment in PayPal * - next, transaction is confirmed with Taxamo * * After that, confirmation page is displayed to the customer. * * @param payerId * @param token * @param transactionKey * @param model * @return */ @RequestMapping(value = "/confirm") public String confirm(@RequestParam("PayerID") String payerId, @RequestParam("token") String token, @RequestParam("taxamo_transaction_key") String transactionKey, Model model) { RestTemplate template = new RestTemplate(); MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.add("USER", ppUser); map.add("PWD", ppPass); map.add("SIGNATURE", ppSign); map.add("VERSION", "117"); map.add("METHOD", "DoExpressCheckoutPayment"); map.add("PAYERID", payerId); map.add("TOKEN", token); GetTransactionOut transaction; //more transaction details should be verified in real-life implementation try { transaction = taxamoApi.getTransaction(transactionKey); } catch (ApiException e) { e.printStackTrace(); model.addAttribute("error", "ERROR result: " + e.getMessage()); return "error"; } map.add("PAYMENTREQUEST_0_CURRENCYCODE", "EUR"); map.add("PAYMENTREQUEST_0_AMT", transaction.getTransaction().getTotalAmount().toString()); map.add("PAYMENTREQUEST_0_PAYMENTACTION", "Sale"); List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); messageConverters.add(new FormHttpMessageConverter()); messageConverters.add(new StringHttpMessageConverter()); template.setMessageConverters(messageConverters); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, requestHeaders); ResponseEntity<String> res = template.exchange( URI.create(properties.get(PropertiesConstants.PAYPAL_NVP).toString()), HttpMethod.POST, request, String.class); Map<String, List<String>> params = parseQueryParams(res.getBody()); String ack = params.get("ACK").get(0); if (!ack.equals("Success")) { model.addAttribute("error", params.get("L_LONGMESSAGE0").get(0)); return "error"; } else { try { ConfirmTransactionOut transactionOut = taxamoApi.confirmTransaction(transactionKey, new ConfirmTransactionIn()); model.addAttribute("status", transactionOut.getTransaction().getStatus()); } catch (ApiException ae) { ae.printStackTrace(); model.addAttribute("error", "ERROR result: " + ae.getMessage()); return "error"; } model.addAttribute("taxamo_transaction_key", transactionKey); return "redirect:/success-checkout"; } }
From source file:com.teradata.benchto.driver.DriverAppIntegrationTest.java
private void verifySerialExecutionStarted(String uniqueBenchmarkName, String queryName, int executionNumber) { verifyExecutionStarted(uniqueBenchmarkName, executionNumber); restServiceServer/*from w w w.ja va 2 s . com*/ .expect(matchAll(requestTo("http://graphite:18088/events/"), method(HttpMethod.POST), jsonPath("$.what", is("Benchmark " + uniqueBenchmarkName + ", query " + queryName + " (" + executionNumber + ") started")), jsonPath("$.tags", is("execution started TEST_ENV")), jsonPath("$.data", is("")))) .andRespond(withSuccess()); }
From source file:org.cloudfoundry.identity.api.web.ServerRunning.java
public ResponseEntity<String> postForString(String path, MultiValueMap<String, String> formData, HttpHeaders headers) {/*from w w w.j ava 2 s . c o m*/ if (headers.getContentType() == null) { headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); } return client.exchange(getUrl(path), HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(formData, headers), String.class); }
From source file:com.ge.predix.test.utils.UaaTestUtil.java
private BaseClientDetails createOrUpdateClient(final BaseClientDetails client) { MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE); if (StringUtils.isNotEmpty(this.zone)) { headers.add("X-Identity-Zone-Id", "uaa"); }//from w ww.j av a2 s .c o m HttpEntity<String> postEntity = new HttpEntity<String>(JSON_UTILS.serialize(client), headers); ResponseEntity<String> clientCreate = null; try { clientCreate = this.adminRestTemplate.exchange(this.uaaUrl + "/oauth/clients", HttpMethod.POST, postEntity, String.class); if (clientCreate.getStatusCode() == HttpStatus.CREATED) { return JSON_UTILS.deserialize(clientCreate.getBody(), BaseClientDetails.class); } else { throw new RuntimeException( "Unexpected return code for client create: " + clientCreate.getStatusCode()); } } catch (InvalidClientException ex) { if (ex.getMessage().equals("Client already exists: " + client.getClientId())) { HttpEntity<String> putEntity = new HttpEntity<String>(JSON_UTILS.serialize(client), headers); ResponseEntity<String> clientUpdate = this.adminRestTemplate.exchange( this.uaaUrl + "/oauth/clients/" + client.getClientId(), HttpMethod.PUT, putEntity, String.class); if (clientUpdate.getStatusCode() == HttpStatus.OK) { return JSON_UTILS.deserialize(clientUpdate.getBody(), BaseClientDetails.class); } else { throw new RuntimeException( "Unexpected return code for client update: " + clientUpdate.getStatusCode()); } } } throw new RuntimeException("Unexpected return code for client creation: " + clientCreate.getStatusCode()); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
/** * Update existing or append some attributes to an entity * @param entityId the entity ID// w w w . ja va 2 s .c o m * @param type optional entity type to avoid ambiguity when multiple entities have the same ID, null or zero-length for empty * @param attributes the attributes to update or to append * @param append if true, will only allow to append new attributes * @return the listener to notify of completion */ public ListenableFuture<Void> updateEntity(String entityId, String type, Map<String, Attribute> attributes, boolean append) { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(baseURL); builder.path("v2/entities/{entityId}"); addParam(builder, "type", type); if (append) { addParam(builder, "options", "append"); } return adapt( request(HttpMethod.POST, builder.buildAndExpand(entityId).toUriString(), attributes, Void.class)); }
From source file:com.orange.ngsi.client.UpdateContextRequestTest.java
@Test(expected = ResourceAccessException.class) public void eperformPostWithTimeout() throws Exception { protocolRegistry.unregisterHost(brokerUrl); this.mockServer.expect(requestTo(brokerUrl + "/ngsi10/updateContext")).andExpect(method(HttpMethod.POST)) .andRespond(TimeoutResponseCreator.withTimeout()); ngsiClient.updateContext(brokerUrl, null, createUpdateContextTempSensor(0)); }
From source file:org.appverse.web.framework.backend.test.util.oauth2.tests.predefined.authorizationcode.Oauth2AuthorizationCodeFlowPredefinedTests.java
@Test public void oauth2FlowTest() throws Exception { // Obtains the token obtainTokenFromOuth2LoginEndpoint(); // Call remotelog ResponseEntity<String> result = callRemoteLogWithAccessToken(); assertEquals(HttpStatus.OK, result.getStatusCode()); // Call remotelog once the access token has expired (we wait enough to make sure it has expired) Thread.sleep(getTokenExpirationDelayInSeconds() * 1000); // Call remotelog result = callRemoteLogWithAccessToken(); assertEquals(HttpStatus.UNAUTHORIZED, result.getStatusCode()); assertTrue(result.getBody().contains("Access token expired")); // Refresh the token refreshToken();//from w w w .j a v a 2s .c om if (!isJwtTokenStore) { // The following code is executed only if the token store is not a JwtTokenStore. The reason is that using this kind of store // the tokens can't be revoked (they just expire) and so this part of the test would fail. // A JwtTokenStore is not a proper store as the tokens are not stored anywhere (as they contain all the required info about the user // themselves. That's why the token revocation is not possible. // We call logout endpoint (we need to use the access token for this) UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(resourceServerBaseUrl + baseApiPath + oauth2LogoutEndpointPath); builder.queryParam("access_token", accessToken); ResponseEntity<String> result2 = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, null, String.class); assertEquals(HttpStatus.OK, result2.getStatusCode()); // We try to call the protected API again (after having logged out which removes the token) - We expect not to be able to call the service. // This will throw a exception. In this case here in the test we receive an exception but really what happened was 'access denied' // A production client will receive the proper http error result = callRemoteLogWithAccessToken(); assertEquals(HttpStatus.UNAUTHORIZED, result.getStatusCode()); } }