Java Code Examples for org.springframework.web.client.resttemplate#put()

The following examples show how to use org.springframework.web.client.resttemplate#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PutAndDeleteController.java    From Spring-Boot-Book with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/put")
public void put() {
    RestTemplate client= restTemplateBuilder.build();
    User user = new User();
    user.setName("hongwei");
    client.put("http://localhost:8080/{1}", user, 7);
}
 
Example 2
Source File: PostTest.java    From Spring-Boot-Book with Apache License 2.0 5 votes vote down vote up
@Test
public void put() {
    RestTemplate client= restTemplateBuilder.build();
    User user = new User();
    user.setName("longzhiran");
    client.put("http://localhost:8080/{1}", user, 4);
}
 
Example 3
Source File: RestTemplateTest.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    RestTemplate rest = new RestTemplate();
    String url = "http://localhost:20202/gray/instance/{id}/switchStatus?switch=0";
    Map<String, String> params = new HashMap<>();
    params.put("id", "service-a:20104");
    rest.put(url, null, "service-a:20104");
}
 
Example 4
Source File: RestTemplateDemoController.java    From springbootexamples with Apache License 2.0 5 votes vote down vote up
@Test
 public void updatePut(){
String uri = "http://localhost:8080/sbe/bootUser";
HttpHeaders headers = new HttpHeaders();
   headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
   
   MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
   params.add("name", "ljk2");
   params.add("age", "19");
   params.add("addr", "addr");
   
   RestTemplate restTemplate = new RestTemplate();
   HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<MultiValueMap<String, String>>(params,headers);
   restTemplate.put(uri, httpEntity);
 }
 
Example 5
Source File: RestTemplateDemoController.java    From springbootexamples with Apache License 2.0 5 votes vote down vote up
@Test
 public void updatePut(){
String uri = "http://localhost:8080/sbe/bootUser";
HttpHeaders headers = new HttpHeaders();
   headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
   
   MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
   params.add("name", "ljk2");
   params.add("age", "19");
   params.add("addr", "addr");
   
   RestTemplate restTemplate = new RestTemplate();
   HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<MultiValueMap<String, String>>(params,headers);
   restTemplate.put(uri, httpEntity);
 }
 
Example 6
Source File: RestTemplateDemoController.java    From springbootexamples with Apache License 2.0 5 votes vote down vote up
@Test
 public void updatePut(){
String uri = "http://localhost:8080/sbe/bootUser";
HttpHeaders headers = new HttpHeaders();
   headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
   
   MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
   params.add("name", "ljk2");
   params.add("age", "19");
   params.add("addr", "addr");
   
   RestTemplate restTemplate = new RestTemplate();
   HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<MultiValueMap<String, String>>(params,headers);
   restTemplate.put(uri, httpEntity);
 }
 
Example 7
Source File: BlockchainClient.java    From jblockchain with Apache License 2.0 5 votes vote down vote up
private static void publishTransaction(URL node, Path privateKey, String text, byte[] senderHash) throws Exception {
    RestTemplate restTemplate = new RestTemplate();
    byte[] signature = SignatureUtils.sign(text.getBytes(), Files.readAllBytes(privateKey));
    Transaction transaction = new Transaction(text, senderHash, signature);
    restTemplate.put(node.toString() + "/transaction?publish=true", transaction);
    System.out.println("Hash of new transaction: " + Base64.encodeBase64String(transaction.getHash()));
}
 
Example 8
Source File: RestTemplateTest.java    From spring-tutorials with Apache License 2.0 5 votes vote down vote up
@Test
public void test_PUT() throws URISyntaxException {
    RestTemplate restTemplate = new RestTemplate();
    URI uri = new URI(baseUrl);

    String body = "The Body";

    restTemplate.put(baseUrl, body);
    restTemplate.put(uri, body);
}
 
Example 9
Source File: SalesOrderController.java    From cloud-espm-cloud-native with Apache License 2.0 4 votes vote down vote up
/**
 * update sales order
 * 
 * @param salesOrderId,
 *            status
 * @return ResponseEntity<String> message
 * @throws JSONException
 */
@PutMapping("/{salesOrderId}/{statusCode}")
@ResponseBody
public ResponseEntity<String> updateSalesOrder(@PathVariable("salesOrderId") final String salesOrderId,
		@PathVariable("statusCode") final String statusCode, @RequestBody final String note,
		RequestEntity<String> requestEntity) throws JSONException, IllegalArgumentException, TokenFlowException {
	if (salesOrderService.getById(salesOrderId) != null) {
		if (Arrays.stream(environment.getActiveProfiles()).anyMatch(env -> env.equalsIgnoreCase("local"))) {
			return errorMessage("Service is currently unavailable", HttpStatus.SERVICE_UNAVAILABLE);
		} else if (Arrays.stream(environment.getActiveProfiles()).anyMatch(env -> env.equalsIgnoreCase("cloud"))) {
			final String productId = salesOrderService.getById(salesOrderId).getProductId();
			final BigDecimal quantity = salesOrderService.getById(salesOrderId).getQuantity();
			if(statusCode.equalsIgnoreCase("S")){
				try{
					Token jwtToken = SpringSecurityContext.getToken();
					String appToken = jwtToken.getAppToken();
					headers.set("Authorization", "Bearer " + appToken);
					headers.set("Content-Type", "application/json");
					RestTemplate restTemplate = new RestTemplate();
					// creation of payload as json object from input
					String quanEdit = "-" + quantity;
					BigDecimal addQuan = new BigDecimal(quanEdit);
					JSONObject updatedStock = new JSONObject();
					updatedStock.put("quantity", addQuan);
					updatedStock.put("productId", productId);
					final String S_PATH = geProductServiceUri() + productId;
					HttpEntity<String> request = new HttpEntity<String>(updatedStock.toString(), headers);
					// call product service
					restTemplate.put(S_PATH, request); 	
				}catch(Exception e){
					return errorMessage(e.getMessage() + " " + productId,
							HttpStatus.BAD_REQUEST);
				}
			}
			salesOrderService.updateStatus(salesOrderId, statusCode, note);
			return new ResponseEntity<>("Sales Order with ID " + salesOrderId + " updated", HttpStatus.OK);
		}
	} else {
		
		return errorMessage("SalesOrder not found", HttpStatus.NOT_FOUND);
	}
	return errorMessage("Stock not found", HttpStatus.NOT_FOUND);
}
 
Example 10
Source File: JaxrsClient.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
private static void testPut(RestTemplate template, String cseUrlPrefix) {
  template.put(cseUrlPrefix + "/compute/sayhi/{name}", null, "world");
}
 
Example 11
Source File: BlockchainClient.java    From jblockchain with Apache License 2.0 4 votes vote down vote up
private static void publishAddress(URL node, Path publicKey, String name) throws IOException {
    RestTemplate restTemplate = new RestTemplate();
    Address address = new Address(name, Files.readAllBytes(publicKey));
    restTemplate.put(node.toString() + "/address?publish=true", address);
    System.out.println("Hash of new address: " + Base64.encodeBase64String(address.getHash()));
}
 
Example 12
Source File: RestRequests.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void putGreeting(RestTemplate restTemplate) {
   Greeting aGreeting = new Greeting(1, "Modified Greeting");

   // We want to modify the Greeting at index=1
   restTemplate.put("http://localhost:8080/greeting/1", aGreeting);
}
 
Example 13
Source File: APISteps.java    From OpenESPI-DataCustodian-java with Apache License 2.0 4 votes vote down vote up
@Ignore
@And("^I PUT \\/espi\\/1_1\\/resource\\/RetailCustomer\\/\\{RetailCustomerID\\}\\/UsagePoint\\/\\{UsagePointID\\}$")
public void I_PUT_espi__resource_RetailCustomer_RetailCustomerID_UsagePoint_UsagePointID()
		throws Throwable {
	driver.get(StepUtils.DATA_CUSTODIAN_BASE_URL
			+ "/espi/1_1/resource/RetailCustomer/1/UsagePoint");
	String xml = driver.getPageSource();

	String idWithPrefix = getXPathValue(
			"/:feed/:entry/:title[contains(text(),'Created')]/../:id", xml);
	String id = idWithPrefix.replace("urn:uuid:", "");
	String selfHref = getXPathValue(
			"/:feed/:entry/:title[contains(text(),'Created')]/../:link[@rel='self']/@href",
			xml);

	String requestBody = "<entry xmlns=\"http://www.w3.org/2005/Atom\">>"
			+ "  <id>"
			+ idWithPrefix
			+ "</id>"
			+ "  <published>2012-10-24T00:00:00Z</published>"
			+ "  <updated>2012-10-24T00:00:00Z</updated>"
			+ "  <link rel=\"self\""
			+ "        href=\"/espi/1_1/resource/RetailCustomer/1/UsagePoint/"
			+ id
			+ "\"/>"
			+ "  <link rel=\"up\""
			+ "        href=\"/espi/1_1/resource/RetailCustomer/1/UsagePoint\"/>"
			+ "  <link rel=\"related\""
			+ "        href=\"/espi/1_1/resource/RetailCustomer/1/UsagePoint/"
			+ id
			+ "/MeterReading\"/>"
			+ "  <link rel=\"related\""
			+ "        href=\"/espi/1_1/resource/RetailCustomer/1/UsagePoint/"
			+ id
			+ "/ElectricPowerUsageSummary\"/>"
			+ "  <link rel=\"related\""
			+ "        href=\"/espi/1_1/resource/UsagePoint/01/LocalTimeParameters/01\"/>"
			+ "  <title>Updated</title>"
			+ "  <content>"
			+ "    <UsagePoint xmlns=\"http://naesb.org/espi\">"
			+ "      <ServiceCategory>"
			+ "        <kind>0</kind>"
			+ "      </ServiceCategory>"
			+ "    </UsagePoint>"
			+ "  </content>" + "</entry>";
	HttpEntity<String> request = new HttpEntity<>(requestBody);
	RestTemplate rest = new RestTemplate();
	rest.put(StepUtils.DATA_CUSTODIAN_BASE_URL + selfHref, request);
}