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

The following examples show how to use org.springframework.web.client.RestTemplate#delete() . 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: NexusArtifactClient.java    From cubeai with Apache License 2.0 8 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 File: NexusArtifactClient.java    From cubeai with 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 File: NexusArtifactClient.java    From cubeai with 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 File: NexusArtifactClient.java    From cubeai with 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
Source File: RangerSecurityServiceConnector.java    From egeria with Apache License 2.0 5 votes vote down vote up
@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 File: AbstractIT.java    From bowman with 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
Source File: RestTemplateTest.java    From spring-tutorials with Apache License 2.0 5 votes vote down vote up
@Test
public void test_DELETE() throws URISyntaxException {
    RestTemplate restTemplate = new RestTemplate();
    URI uri = new URI(baseUrl);

    restTemplate.delete(baseUrl);
    restTemplate.delete(uri);
}
 
Example 8
Source File: APISteps.java    From OpenESPI-DataCustodian-java with Apache License 2.0 5 votes vote down vote up
@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
Source File: PutAndDeleteController.java    From Spring-Boot-Book with Apache License 2.0 4 votes vote down vote up
@RequestMapping("/delete")
public void delete() {
    RestTemplate client= restTemplateBuilder.build();
    client.delete("http://localhost:8080/{1}", 8);
}
 
Example 10
Source File: PostTest.java    From Spring-Boot-Book with 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
Source File: JaxrsClient.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
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
Source File: RestRequests.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void deleteGreeting(RestTemplate restTemplate) {
   // We want to delete Greeting at index=2
   restTemplate.delete("http://localhost:8080/greeting/2");

}