Example usage for org.springframework.http HttpMethod DELETE

List of usage examples for org.springframework.http HttpMethod DELETE

Introduction

In this page you can find the example usage for org.springframework.http HttpMethod DELETE.

Prototype

HttpMethod DELETE

To view the source code for org.springframework.http HttpMethod DELETE.

Click Source Link

Usage

From source file:org.dawnsci.marketplace.config.SecurityConfiguration.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.formLogin().loginPage("/signin").loginProcessingUrl("/signin/authenticate")
            .failureUrl("/signin?param.error=bad_credentials").and().logout().logoutUrl("/signout")
            .deleteCookies("JSESSIONID").and().authorizeRequests().antMatchers("/**").permitAll()
            .antMatchers(HttpMethod.POST, "/**").authenticated().antMatchers(HttpMethod.PUT, "/**")
            .authenticated().antMatchers(HttpMethod.DELETE, "/**").authenticated().and().httpBasic().and()
            .rememberMe();/*w ww .j  a v  a2 s . com*/
}

From source file:com.appglu.impl.PushTemplateTest.java

@Test
public void removeDeviceNotFound() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/push/device/f3f71c5a-0a98-48f7-9acd-d38d714d76ad"))
            .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NOT_FOUND)
                    .body(compactedJson("data/error_not_found")).headers(responseHeaders));

    boolean success = pushOperations.removeDevice("f3f71c5a-0a98-48f7-9acd-d38d714d76ad");
    Assert.assertFalse(success);//from  ww w. ja va2s .c  o  m

    mockServer.verify();
}

From source file:org.zalando.github.spring.TeamsTemplateTest.java

@Test
public void deleteTeam() throws Exception {
    mockServer.expect(requestTo("https://api.github.com/teams/1")).andExpect(method(HttpMethod.DELETE))
            // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN"))
            .andRespond(withNoContent());

    teamsTemplate.deleteTeam(1);// ww w  .j  a v a2  s .c  om

}

From source file:com.example.DatastoreSampleApplicationTests.java

@Test
public void basicTest() throws Exception {
    Singer johnDoe = new Singer(null, "John", "Doe", null);
    Singer janeDoe = new Singer(null, "Jane", "Doe", null);
    Singer richardRoe = new Singer(null, "Richard", "Roe", null);
    Singer frodoBaggins = new Singer(null, "Frodo", "Baggins", null);

    List<Singer> singersAsc = getSingers("/singers?sort=lastName,ASC");
    assertThat(singersAsc).as("Verify ASC order").containsExactly(johnDoe, janeDoe, richardRoe);

    List<Singer> singersDesc = getSingers("/singers?sort=lastName,DESC");
    assertThat(singersDesc).as("Verify DESC order").containsExactly(richardRoe, johnDoe, janeDoe);

    sendRequest("/singers",
            "{\"singerId\": \"singerFrodo\", \"firstName\":" + " \"Frodo\", \"lastName\": \"Baggins\"}",
            HttpMethod.POST);/*w ww.  j a va  2s  .  c  o  m*/

    Awaitility.await().atMost(15, TimeUnit.SECONDS)
            .until(() -> getSingers("/singers?sort=lastName,ASC").size() == 4);

    List<Singer> singersAfterInsertion = getSingers("/singers?sort=lastName,ASC");
    assertThat(singersAfterInsertion).as("Verify post").containsExactly(frodoBaggins, johnDoe, janeDoe,
            richardRoe);

    sendRequest("/singers/singer1", null, HttpMethod.DELETE);

    Awaitility.await().atMost(15, TimeUnit.SECONDS)
            .until(() -> getSingers("/singers?sort=lastName,ASC").size() == 3);

    List<Singer> singersAfterDeletion = getSingers("/singers?sort=lastName,ASC");
    assertThat(singersAfterDeletion).as("Verify Delete").containsExactly(frodoBaggins, janeDoe, richardRoe);

    assertThat(baos.toString()).as("Verify relationships saved in transaction")
            .contains("Relationship links "
                    + "were saved between a singer, bands, and instruments in a single transaction: "
                    + "Singer{singerId='singer2', firstName='Jane', lastName='Doe', "
                    + "albums=[Album{albumName='a', date=2012-01-20}, Album{albumName='b', "
                    + "date=2018-02-12}], firstBand=General Band, bands=General Band,Big Bland Band, "
                    + "personalInstruments=recorder,cow bell}");

    assertThat(this.singerRepository.findById("singer2").get().getPersonalInstruments().stream()
            .map(Instrument::getType).collect(Collectors.toList())).containsExactlyInAnyOrder("recorder",
                    "cow bell");

    assertThat(this.singerRepository.findById("singer2").get().getBands().stream().map(Band::getName)
            .collect(Collectors.toList())).containsExactlyInAnyOrder("General Band", "Big Bland Band");

    Singer singer3 = this.singerRepository.findById("singer3").get();

    assertThat(singer3.getPersonalInstruments().stream().map(Instrument::getType).collect(Collectors.toList()))
            .containsExactlyInAnyOrder("triangle", "marimba");

    assertThat(singer3.getBands().stream().map(Band::getName).collect(Collectors.toList()))
            .containsExactlyInAnyOrder("Crooked Still", "Big Bland Band");

    assertThat(singer3.getLastModifiedTime()).isAfter(LocalDateTime.parse("2000-01-01T00:00:00"));

    assertThat(baos.toString())
            .contains("Query by example\n" + "Singer{singerId='singer1', firstName='John', lastName='Doe', "
                    + "albums=[], firstBand=null, bands=, personalInstruments=}\n"
                    + "Singer{singerId='singer2', firstName='Jane', lastName='Doe', "
                    + "albums=[Album{albumName='a', date=2012-01-20}");

    assertThat(baos.toString()).contains(
            "Using Pageable parameter\n" + "Singer{singerId='singer1', firstName='John', lastName='Doe', "
                    + "albums=[], firstBand=null, bands=, personalInstruments=}\n"
                    + "Singer{singerId='singer2', firstName='Jane', lastName='Doe', "
                    + "albums=[Album{albumName='a', date=2012-01-20}");

    assertThat(baos.toString()).contains("This concludes the sample.");
}

From source file:de.fhg.fokus.nubomedia.paas.VNFRServiceImpl.java

/**
 * Unregisters an App to the VNFR with the specific internal application identify
 * // ww w.ja v  a2  s.  c o  m
 * @param internalAppId - identifier of the registered application on the VNFR
 */
public void unregisterApplication(String internalAppId) {
    String webServiceUrl = serviceProfile.getServiceApiUrl() + "/" + internalAppId;
    logger.info("unregistering application " + webServiceUrl);

    ResponseEntity<Void> response = restTemplate.exchange(webServiceUrl, HttpMethod.DELETE, null, Void.class);
    Void body = response.getBody();
}

From source file:cucumber.api.spring.test.web.servlet.MockMvcStepdefs.java

@When("^I perform a DELETE request on \"(.*?)\"$")
public void i_perform_a_delete_request_on(String uri) throws Throwable {
    i_perform_a_request_on(HttpMethod.DELETE, uri);
}

From source file:org.drugis.addis.config.SecurityConfig.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    String[] whitelist = { "/", "/trialverse", "/trialverse/**", "/patavi", // allow POST mcda models anonymously
            "/favicon.ico", "/favicon.png", "/app/**", "/auth/**", "/signin", "/signup", "/**/modal/*.html",
            "/manual.html" };
    // Disable CSFR protection on the following urls:
    List<AntPathRequestMatcher> requestMatchers = Arrays.asList(whitelist).stream()
            .map(AntPathRequestMatcher::new).collect(Collectors.toList());
    CookieCsrfTokenRepository csrfTokenRepository = new CookieCsrfTokenRepository();
    csrfTokenRepository.setCookieHttpOnly(false);
    http.formLogin().loginPage("/signin").loginProcessingUrl("/signin/authenticate")
            .failureUrl("/signin?param.error=bad_credentials").and().authorizeRequests().antMatchers(whitelist)
            .permitAll().antMatchers(HttpMethod.GET, "/**").permitAll().antMatchers(HttpMethod.POST, "/**")
            .authenticated().antMatchers(HttpMethod.PUT, "/**").authenticated()
            .antMatchers(HttpMethod.DELETE, "/**").authenticated().and().rememberMe().and().exceptionHandling()
            .authenticationEntryPoint(new Http403ForbiddenEntryPoint()).and()
            .apply(new SpringSocialConfigurer().alwaysUsePostLoginUrl(false)).and().csrf()
            .csrfTokenRepository(csrfTokenRepository)
            .requireCsrfProtectionMatcher(
                    request -> !(requestMatchers.stream().anyMatch(matcher -> matcher.matches(request))
                            || Optional.fromNullable(request.getHeader("X-Auth-Application-Key")).isPresent()
                            || HttpMethod.GET.toString().equals(request.getMethod())))
            .and().setSharedObject(ApplicationContext.class, context);

    http.addFilterBefore(new AuthenticationFilter(authenticationManager()), BasicAuthenticationFilter.class);

}

From source file:com.tikinou.schedulesdirect.ClientUtils.java

public <R_IMPL extends R, P extends BaseCommandParameter, R extends CommandResult, C extends ParameterizedCommand<P, R>, R_OVER> R_OVER executeRequest(
        SchedulesDirectClient client, C command, Class<R_IMPL> resultType, Class<R_OVER> resulTypetOverride) {
    StringBuilder url = new StringBuilder(client.getUrl());
    url.append("/").append(command.getEndPoint());
    String token = null;/*from   w w w . j  a  v  a2s  . c  o m*/
    if (command.getParameters() instanceof AuthenticatedBaseCommandParameter)
        token = ((AuthenticatedBaseCommandParameter) command.getParameters()).getToken();

    org.springframework.http.HttpMethod httpMethod = null;
    switch (command.getMethod()) {
    case GET:
        Map<String, String> reqParams = command.getParameters().toRequestParameters();
        if (reqParams != null) {
            url.append("?");
            int i = 0;
            for (Map.Entry<String, String> entry : reqParams.entrySet()) {
                if (i > 0)
                    url.append("&");
                url.append(entry.getKey()).append("=").append(entry.getValue());
                i++;
            }
        }
        httpMethod = org.springframework.http.HttpMethod.GET;
        break;
    case POST: {
        httpMethod = org.springframework.http.HttpMethod.POST;
        break;
    }
    case PUT: {
        httpMethod = org.springframework.http.HttpMethod.PUT;
        break;
    }
    case DELETE: {
        httpMethod = org.springframework.http.HttpMethod.DELETE;
        break;
    }
    }

    if (resulTypetOverride == null) {
        ResponseEntity<R_IMPL> res = restTemplate.exchange(url.toString(), httpMethod,
                getRequestEntity(client.getUserAgent(), command.getParameters(), token), resultType);
        if (res.getStatusCode() == HttpStatus.OK) {
            R result = res.getBody();
            command.setResults(result);
            command.setStatus(CommandStatus.SUCCESS);
        } else {
            command.setStatus(CommandStatus.FAILURE);
        }
    } else {
        ResponseEntity<R_OVER> res = restTemplate.exchange(url.toString(), httpMethod,
                getRequestEntity(client.getUserAgent(), command.getParameters(), token), resulTypetOverride);
        if (res.getStatusCode() == HttpStatus.OK) {
            command.setStatus(CommandStatus.SUCCESS);
        } else {
            command.setStatus(CommandStatus.FAILURE);
        }
        return res.getBody();
    }
    return null;
}

From source file:org.openbaton.nse.beans.connectivitymanageragent.ConnectivityManagerRequestor.java

public HttpStatus delQos(String hypervisorName, String qosId) {

    String url = configuration.getBaseUrl() + "/qoses/" + hypervisorName + "/" + qosId;
    HttpHeaders headers = new HttpHeaders();
    HttpEntity<String> delentity = new HttpEntity<>(headers);
    ResponseEntity<String> delete = template.exchange(url, HttpMethod.DELETE, delentity, String.class);

    if (delete.getStatusCode().is5xxServerError()) {
        logger.debug("The port is still here, returned " + delete.getStatusCode() + " with body "
                + delete.getBody());/* w ww  .  java 2s  .  c o m*/
        return delete.getStatusCode();
    }

    logger.debug("deleting qos " + qosId + " has returned " + delete.getStatusCode());

    return delete.getStatusCode();
}