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:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java

public void testCreateSubjectWithMalformedJSON() {
    try {//from w ww. jav a2s.  c om
        String badSubject = "{\"subject\": bad-subject-form\"}";
        MultiValueMap<String, String> headers = new HttpHeaders();
        headers.add("Content-type", "application/json");
        headers.add(PolicyHelper.PREDIX_ZONE_ID, this.acsZone1Name);
        HttpEntity<String> httpEntity = new HttpEntity<String>(badSubject, headers);
        this.acsAdminRestTemplate.put(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH + "/bad-subject-form",
                httpEntity);
    } catch (HttpClientErrorException e) {
        Assert.assertEquals(e.getStatusCode(), HttpStatus.BAD_REQUEST);
        return;
    }
    this.acsAdminRestTemplate.exchange(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH + "/bad-subject-form",
            HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class);
    Assert.fail("testCreateSubjectWithMalformedJSON should have failed!");
}

From source file:com.ge.predix.test.utils.PrivilegeHelper.java

public void deleteSubject(final RestTemplate restTemplate, final String acsUrl, final String subjectId,
        final HttpHeaders headers) throws Exception {
    if (subjectId != null) {
        URI subjectUri = URI.create(acsUrl + ACS_SUBJECT_API_PATH + URLEncoder.encode(subjectId, "UTF-8"));
        restTemplate.exchange(subjectUri, HttpMethod.DELETE, new HttpEntity<>(headers), String.class);
    }/*w w  w.  ja  v a 2  s  . c  om*/
}

From source file:de.zib.gndms.gndmc.AbstractClient.java

/**
 * Executes a DELETE on a url, where the request header contains a given user name and workflow id.
 * /*from w  ww.  ja  v  a 2  s  .c om*/
 * @param url The url of the request.
 * @param dn The user name.
 * @param wid The workflow id.
 * @return The response as entity with Void body.
 */
protected final ResponseEntity<Integer> unifiedDelete(final String url, final String dn, final String wid) {
    return unifiedX(HttpMethod.DELETE, Integer.class, 42, url, dn, wid);
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Deletes the node with the given key from etcd.
 * //from ww w. ja v  a2 s.  co m
 * @param key
 *            the node's key
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse delete(final String key) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);

    return execute(builder, HttpMethod.DELETE, null, EtcdResponse.class);
}

From source file:com.ge.predix.test.utils.PolicyHelper.java

public void deletePolicySet(final RestTemplate restTemplate, final String acsUrl, final String testPolicyName,
        final HttpHeaders headers) {
    if (testPolicyName != null) {
        restTemplate.exchange(acsUrl + ACS_POLICY_SET_API_PATH + testPolicyName, HttpMethod.DELETE,
                new HttpEntity<>(headers), String.class);
    }//www. j av a  2  s .c  om
}

From source file:com.frequentis.maritime.mcsr.config.SecurityConfiguration.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    //super.configure(http);
    log.debug("Configuring HttpSecurity");
    log.debug("RememberMe service {}", rememberMeServices);
    http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            .sessionAuthenticationStrategy(sessionAuthenticationStrategy()).and()
            .addFilterBefore(basicAuthenticationFilter(), LogoutFilter.class)
            .addFilterBefore(new SkippingFilter(keycloakPreAuthActionsFilter()), LogoutFilter.class)
            .addFilterBefore(new SkippingFilter(keycloakAuthenticationProcessingFilter()),
                    X509AuthenticationFilter.class)
            .exceptionHandling().authenticationEntryPoint(authenticationEntryPoint()).and()
            //            .addFilterAfter(new CsrfCookieGeneratorFilter(), CsrfFilter.class)
            //            .exceptionHandling()
            //            .accessDeniedHandler(new CustomAccessDeniedHandler())
            //            .authenticationEntryPoint(authenticationEntryPoint)
            //        .and()
            .rememberMe().rememberMeServices(rememberMeServices).rememberMeParameter("remember-me")
            .key(jHipsterProperties.getSecurity().getRememberMe().getKey()).and().formLogin()
            .loginProcessingUrl("/api/authentication").successHandler(ajaxAuthenticationSuccessHandler)
            .failureHandler(ajaxAuthenticationFailureHandler).usernameParameter("j_username")
            .passwordParameter("j_password").permitAll().and().logout().logoutUrl("/api/logout")
            .logoutSuccessHandler(ajaxLogoutSuccessHandler).deleteCookies("JSESSIONID", "CSRF-TOKEN")
            .permitAll().and().headers().frameOptions().disable().and().authorizeRequests()
            .antMatchers("/api/register").hasAuthority(AuthoritiesConstants.ADMIN)
            .antMatchers("/api/elasticsearch/**").permitAll().antMatchers("/api/activate").permitAll()
            .antMatchers("/api/authenticate").permitAll()
            .antMatchers("/api/account/reset_password/inactivateit").permitAll()
            .antMatchers("/api/account/reset_password/finish").permitAll().antMatchers("/api/profile-info")
            .permitAll().antMatchers("/websocket/tracker").hasAuthority(AuthoritiesConstants.ADMIN)
            .antMatchers("/websocket/**").permitAll().antMatchers("/management/**")
            .hasAuthority(AuthoritiesConstants.ADMIN).antMatchers("/v2/api-docs/**").permitAll()
            .antMatchers(HttpMethod.PUT, "/api/**").authenticated().antMatchers(HttpMethod.POST, "/api/**")
            .authenticated().antMatchers(HttpMethod.DELETE, "/api/**").authenticated()
            .antMatchers(HttpMethod.TRACE, "/api/**").authenticated().antMatchers(HttpMethod.HEAD, "/api/**")
            .authenticated().antMatchers(HttpMethod.PATCH, "/api/**").authenticated()
            .antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll().antMatchers(HttpMethod.GET, "/api/**")
            .permitAll().antMatchers("/swagger-resources/configuration/ui").permitAll()
            .antMatchers("/swagger-ui/index.html").permitAll().and().csrf().disable();

}

From source file:de.zib.gndms.gndmc.dspace.test.MockRestTemplate.java

/**
 * Checks if the given HTTP method is allowed to be executed on the given url.
 * /*from ww w . j  a  va2 s  .  co  m*/
 * @param url The url the method shall be executed.
 * @param method The HTTP method.
 * @return true, if the method can be executed on the url, else false.
 */
private boolean validUrlMethod(final String url, final HttpMethod method) {
    if (url.matches(serviceURL + "/dspace")) {
        if (method.equals(HttpMethod.GET)) {
            return true;
        }
    }

    if (url.matches(serviceURL + "/dspace/_\\w+")) {
        if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.PUT)
                || method.equals(HttpMethod.DELETE)) {
            return true;
        }
    }

    if (url.matches(serviceURL + "/dspace/_\\w+/config")) {
        if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.PUT)) {
            return true;
        }
    }

    if (url.matches(serviceURL + "/dspace/_\\w+/slicekinds")) {
        if (method.equals(HttpMethod.GET)) {
            return true;
        }
    }

    if (url.matches(serviceURL + "/dspace/_\\w+/_\\w+")) {
        if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE)
                || method.equals(HttpMethod.POST)) {
            return true;
        }
    }

    if (url.matches(serviceURL + "/dspace/_\\w+/_\\w+/_\\w+")) {
        if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE)
                || method.equals(HttpMethod.POST)) {
            return true;
        }
    }

    if (url.matches(serviceURL + "/dspace/_\\w+/_\\w+/_\\w+/files")) {
        if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.DELETE)) {
            return true;
        }
    }

    if (url.matches(serviceURL + "/dspace/_\\w+/_\\w+/_\\w+/gsiftp")) {
        if (method.equals(HttpMethod.GET)) {
            return true;
        }
    }

    if (url.matches(serviceURL + "/dspace/_\\w+/_\\w+/_\\w+/_\\w+")) {
        if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.PUT)
                || method.equals(HttpMethod.DELETE)) {
            return true;
        }
    }
    return false;
}

From source file:com.orange.ngsi.client.NgsiRestClient.java

/**
 * Delete the attribute value instance of a context element
 * @param url the URL of the broker/*from  w  ww  . j  a  va  2  s .c  o  m*/
 * @param httpHeaders the HTTP header to use, or null for default
 * @param entityID the ID of the entity
 * @param attributeName the name of the attribute
 * @param valueID the instant ID of the attribute
 * @return a future for a StatusCode
 */
public ListenableFuture<StatusCode> deleteContextAttributeValue(String url, HttpHeaders httpHeaders,
        String entityID, String attributeName, String valueID) {
    return request(HttpMethod.DELETE,
            url + entitiesPath + entityID + attributesPath + attributeName + valuesPath + valueID, httpHeaders,
            null, StatusCode.class);
}

From source file:org.starfishrespect.myconsumption.android.ui.ChartChoiceFragment.java

private void deleteSensor(int index) {
    AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    builder.setTitle(R.string.dialog_title_confirmation);
    builder.setMessage(//from   w w w  . j  a v  a2  s .  com
            String.format(getResources().getString(R.string.dialog_message_confirmation_delete_sensor),
                    sensors.get(lastLongClickItem).getName()));
    builder.setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.setPositiveButton(R.string.button_yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            new AsyncTask<Void, Boolean, Void>() {
                @Override
                protected Void doInBackground(Void... params) {
                    RestTemplate template = new RestTemplate();
                    HttpHeaders httpHeaders = CryptoUtils.createHeadersCurrentUser();
                    template.getMessageConverters().add(new FormHttpMessageConverter());
                    template.getMessageConverters().add(new StringHttpMessageConverter());

                    String url = SingleInstance.getServerUrl() + "users/"
                            + SingleInstance.getUserController().getUser().getName() + "/sensor/"
                            + sensors.get(lastLongClickItem).getSensorId();

                    template.exchange(url, HttpMethod.DELETE, new HttpEntity<>(httpHeaders), String.class);

                    try {
                        SingleInstance.getDatabaseHelper().getSensorDao()
                                .delete(sensors.get(lastLongClickItem));
                        new SensorValuesDao(SingleInstance.getDatabaseHelper())
                                .removeSensor(sensors.get(lastLongClickItem).getSensorId());
                    } catch (SQLException e) {
                        publishProgress(false);
                    }
                    publishProgress(true);
                    return null;
                }

                @Override
                protected void onProgressUpdate(Boolean... values) {
                    for (boolean b : values) {
                        if (b) {
                            new AlertDialog.Builder(mActivity).setTitle(R.string.dialog_title_information)
                                    .setMessage(R.string.dialog_message_information_sensor_deleted)
                                    .setPositiveButton(R.string.button_ok,
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    EventBus.getDefault().post(new ReloadUserEvent(false));
                                                    dialog.dismiss();
                                                }
                                            })
                                    .show();
                        } else {
                            new AlertDialog.Builder(mActivity).setTitle(R.string.dialog_title_information)
                                    .setMessage("unknown error while deleting from DB").setPositiveButton(
                                            R.string.button_ok, new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.dismiss();
                                                }
                                            })
                                    .show();
                        }
                    }
                }
            }.execute();
            dialog.dismiss();
        }

    });
    builder.show();

}

From source file:com.sitewhere.rest.service.SiteWhereClient.java

@Override
public DeviceAssignment deleteDeviceAssignment(String assignmentToken, boolean force)
        throws SiteWhereException {
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("assignmentToken", assignmentToken);
    String url = getBaseUrl() + "assignments/{assignmentToken}";
    if (force) {//from w  w w  . j  a v  a2 s .com
        url += "?force=true";
    }
    return sendRest(url, HttpMethod.DELETE, null, DeviceAssignment.class, vars);
}