Java Code Examples for org.springframework.web.client.RestTemplate#delete()

The following examples show how to use org.springframework.web.client.RestTemplate#delete() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: cubeai   File: NexusArtifactClient.java    License: Apache License 2.0 6 votes vote down vote up
public boolean deleteArtifact(String longUrl) {
    try {
        CloseableHttpClient httpClient;
        if (getUserName() != null && getPassword() != null) {
            URL url = new URL(getUrl());
            HttpHost httpHost = new HttpHost(url.getHost(), url.getPort());
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(new AuthScope(httpHost),
                new UsernamePasswordCredentials(getUserName(), getPassword()));
            httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
        } else {
            httpClient = HttpClientBuilder.create().build();
        }
        RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
        restTemplate.delete(new URI(longUrl));
    } catch (Exception e) {
        return false;
    }
    return true;
}
 
Example 2
Source Project: cubeai   File: NexusArtifactClient.java    License: Apache License 2.0 6 votes vote down vote up
public boolean deleteArtifact(String longUrl) {
    try {
        CloseableHttpClient httpClient;
        if (getUserName() != null && getPassword() != null) {
            URL url = new URL(getUrl());
            HttpHost httpHost = new HttpHost(url.getHost(), url.getPort());
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(new AuthScope(httpHost),
                new UsernamePasswordCredentials(getUserName(), getPassword()));
            httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
        } else {
            httpClient = HttpClientBuilder.create().build();
        }
        RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
        restTemplate.delete(new URI(longUrl));
    } catch (Exception e) {
        return false;
    }
    return true;
}
 
Example 3
Source Project: cubeai   File: NexusArtifactClient.java    License: Apache License 2.0 6 votes vote down vote up
public boolean deleteArtifact(String longUrl) {
    try {
        CloseableHttpClient httpClient;
        if (getUserName() != null && getPassword() != null) {
            URL url = new URL(getUrl());
            HttpHost httpHost = new HttpHost(url.getHost(), url.getPort());
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(new AuthScope(httpHost),
                new UsernamePasswordCredentials(getUserName(), getPassword()));
            httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
        } else {
            httpClient = HttpClientBuilder.create().build();
        }
        RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
        restTemplate.delete(new URI(longUrl));
    } catch (Exception e) {
        return false;
    }
    return true;
}
 
Example 4
Source Project: cubeai   File: NexusArtifactClient.java    License: Apache License 2.0 6 votes vote down vote up
public boolean deleteArtifact(String longUrl) {
    try {
        CloseableHttpClient httpClient;
        if (getUserName() != null && getPassword() != null) {
            URL url = new URL(getUrl());
            HttpHost httpHost = new HttpHost(url.getHost(), url.getPort());
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(new AuthScope(httpHost),
                new UsernamePasswordCredentials(getUserName(), getPassword()));
            httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
        } else {
            httpClient = HttpClientBuilder.create().build();
        }
        RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
        restTemplate.delete(new URI(longUrl));
    } catch (Exception e) {
        return false;
    }
    return true;
}
 
Example 5
@Override
public void deleteResource(String resourceGuid) {
    String resourceURL = getRangerURL(SERVICE_TAGS_RESOURCE_BY_GUID, resourceGuid);
    RestTemplate restTemplate = new RestTemplate();
    HttpEntity<String> entity = new HttpEntity<>(getHttpHeaders());

    try {
        restTemplate.delete(resourceURL, HttpMethod.DELETE, entity);
        log.info("The resource with guid = {} has been deleted", resourceGuid);
    } catch (HttpStatusCodeException exception) {
        log.debug("Unable to delete the resource with guid = {}", resourceGuid);
    }
}
 
Example 6
Source Project: bowman   File: AbstractIT.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() {
	RestTemplate cleanUpRestTemplate = new RestTemplate();
	
	for (URI createdEntity : Lists.reverse(createdEntityRecordingInterceptor.getCreatedEntities())) {
		try {
			cleanUpRestTemplate.delete(createdEntity);
		}
		catch (RestClientException exception) {
			// perhaps already deleted; continue
		}
	}
}
 
Example 7
@Test
public void test_DELETE() throws URISyntaxException {
    RestTemplate restTemplate = new RestTemplate();
    URI uri = new URI(baseUrl);

    restTemplate.delete(baseUrl);
    restTemplate.delete(uri);
}
 
Example 8
@And("^I DELETE \\/espi\\/1_1\\/resource\\/RetailCustomer\\/\\{RetailCustomerID\\}\\/UsagePoint\\/\\{UsagePointID\\}$")
public void I_DELETE_espi__resource_RetailCustomer_RetailCustomerID_UsagePoint_UsagePointID()
		throws Throwable {
	RestTemplate rest = new RestTemplate();
	rest.delete(StepUtils.DATA_CUSTODIAN_BASE_URL
			+ "/espi/1_1/resource/RetailCustomer/"
			+ CucumberSession.getUserHashedId() + "/UsagePoint/"
			+ CucumberSession.getUsagePointHashedId());
}
 
Example 9
@RequestMapping("/delete")
public void delete() {
    RestTemplate client= restTemplateBuilder.build();
    client.delete("http://localhost:8080/{1}", 8);
}
 
Example 10
Source Project: Spring-Boot-Book   File: PostTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void delete() {
    RestTemplate client= restTemplateBuilder.build();
    client.delete("http://localhost:8080/{1}", 4);
}
 
Example 11
private static void testDelete(RestTemplate template, String cseUrlPrefix) {
  Map<String, String> params = new HashMap<>();
  params.put("name", "world");
  template.delete(cseUrlPrefix + "/compute/sayhei/?name={name}", params);
}
 
Example 12
public void deleteGreeting(RestTemplate restTemplate) {
   // We want to delete Greeting at index=2
   restTemplate.delete("http://localhost:8080/greeting/2");

}