Example usage for org.springframework.http HttpMethod POST

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

Introduction

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

Prototype

HttpMethod POST

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

Click Source Link

Usage

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.RegisteringInApplicationBrokerStep.java

public CreatingPlanVisibilityStep register(BasicAuthServerCredentials appBrokerCredentials,
        RestTemplate appBrokerRestTemplate, String serviceName, String serviceDescription) {

    LOGGER.info("Registering service " + serviceName + " in application-broker");

    String requestBody = prepareAppBrokerJsonRequest(serviceName, serviceDescription);
    HttpHeaders headers = HttpCommunication.basicAuthJsonHeaders(appBrokerCredentials.getBasicAuthToken());
    HttpEntity<String> request = new HttpEntity<>(requestBody, headers);

    String appBrokerEndpoint = appBrokerCredentials.getHost() + APP_BROKER_CATALOG_ENDPOINT;
    appBrokerRestTemplate.exchange(appBrokerEndpoint, HttpMethod.POST, request, String.class);

    return new CreatingPlanVisibilityStep(cfApiUrl, cfRestTemplate);

}

From source file:com.tamnd.app.config.security.SpringSecurityConfig.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    http/* w ww  .  j a  va 2 s . c om*/
            //            .httpBasic()
            //               .authenticationEntryPoint(authorizeHandler)
            //            .and()
            .authorizeRequests().antMatchers("/static/**", "/favicon.ico", "/app/**").permitAll()
            .antMatchers("/", "/test").permitAll().antMatchers(HttpMethod.POST, "/rest/accounts").permitAll()
            .anyRequest().authenticated().and().addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class)
            .formLogin().defaultSuccessUrl(Common.DEFAULT_URL).loginProcessingUrl("/login")
            .loginPage(Common.LOGIN_URL).successHandler(authSuccess).failureHandler(authFailure).permitAll()
            .and().httpBasic().and().logout().logoutSuccessHandler(logoutSuccess).deleteCookies("JSESSIONID")
            .invalidateHttpSession(true).permitAll().and()
            //            .csrf().disable()
            .csrf().csrfTokenRepository(csrfTokenRepository()).and().exceptionHandling()
            .authenticationEntryPoint(unauthorizeHandler).and().sessionManagement()
            .invalidSessionUrl(Common.DEFAULT_URL).maximumSessions(1);

    //Enable HTTPS Channel
    //      if ("true".equals(System.getProperty("httpsOnly"))) {
    //         http.requiresChannel().anyRequest().requiresSecure();
    //      }
}

From source file:com.boxedfolder.carrot.config.security.WebSecurityConfig.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable();/* w ww . j  a  v  a 2  s .  co  m*/
    http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    http.authorizeRequests().antMatchers(HttpMethod.POST, "/client/analytics/logs/**").permitAll();

    // Define secured routes here
    String[] securedEndpoints = { "/client/ping", "/client/beacons/**", "/client/apps/**", "/client/events/**",
            "/client/analytics/**" };

    for (String endpoint : securedEndpoints) {
        http.authorizeRequests().antMatchers(endpoint).authenticated();
    }

    SecurityConfigurer<DefaultSecurityFilterChain, HttpSecurity> securityConfigurerAdapter = new XAuthTokenConfigurer(
            userDetailsServiceBean());
    http.apply(securityConfigurerAdapter);
}

From source file:rest.ApplianceRestController.java

public void testApplianceUpdate() {
    // LEFT AS AN EXERCISE FOR YOU
    // GET THE CLUB and THEN CHANGE AND MAKE A COPY
    //THEN SEND TO THE SERVER USING A PUT OR POST
    // THEN READ BACK TO SEE IF YOUR CHANGE HAS HAPPENED
    Appliance app = new Appliance.Builder("samTv003").brand("samsung").descrip("UHDTV").Build();
    HttpEntity<Appliance> requestEntity = new HttpEntity<>(app, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/app/create", HttpMethod.POST,
            requestEntity, String.class);
    System.out.println(" THE RESPONSE BODY " + responseEntity.getBody());
    System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode());
    System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders());
    Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK);

}

From source file:net.paslavsky.springrest.HttpHeadersHelperTest.java

@DataProvider
public Object[][] data() {
    DateFormat dateFormat = createDateFormat();
    final long currentTime = System.currentTimeMillis();
    final String currentTimeStr = dateFormat.format(new Date(currentTime));
    return new Object[][] { new Object[] { "Other", new Object[] { 123 }, "123" },
            new Object[] { "Other", new Object[] { "123" }, "123" },
            new Object[] { "Other", new String[] { "123" }, "123" },
            new Object[] { "Other", Arrays.asList("123"), "123" }, new Object[] { "Other", "123", "123" },
            new Object[] { "Accept", MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON_VALUE },
            new Object[] { "Accept", Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML),
                    MediaType.APPLICATION_JSON_VALUE + ", " + MediaType.APPLICATION_XML_VALUE },
            new Object[] { "Accept-Charset", java.nio.charset.Charset.forName("UTF-8"), "utf-8" },
            new Object[] { "Allow", HttpMethod.GET, "GET" }, new Object[] { "Allow",
                    new TreeSet<HttpMethod>(Arrays.asList(HttpMethod.PUT, HttpMethod.POST)), "POST,PUT" },
            new Object[] { "Connection", "close", "close" },
            new Object[] { "Content-Disposition", "form-data; name=\"AttachedFile1\"; filename=\"photo-1.jpg\"",
                    "form-data; name=\"AttachedFile1\"; filename=\"photo-1.jpg\"" },
            new Object[] { "Content-Disposition", new String[] { "AttachedFile1", "photo-1.jpg" },
                    "form-data; name=\"AttachedFile1\"; filename=\"photo-1.jpg\"" },
            new Object[] { "Content-Disposition", "AttachedFile1", "form-data; name=\"AttachedFile1\"" },
            new Object[] { "Content-Length", 123l, "123" },
            new Object[] { "Content-Type", MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON_VALUE },
            new Object[] { "Content-Type", MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE },
            new Object[] { "Date", currentTime, currentTimeStr },
            new Object[] { "ETag", "W/\"123456789\"", "W/\"123456789\"" },
            new Object[] { "Expires", currentTime, currentTimeStr },
            new Object[] { "If-Modified-Since", currentTime, currentTimeStr },
            new Object[] { "If-None-Match", "737060cd8c284d8af7ad3082f209582d",
                    "737060cd8c284d8af7ad3082f209582d" },
            new Object[] { "Last-Modified", currentTime, currentTimeStr },
            new Object[] { "Location", "http://example.com/", "http://example.com/" },
            new Object[] { "Location", URI.create("http://example.com/"), "http://example.com/" },
            new Object[] { "Origin", "www.a.com", "www.a.com" },
            new Object[] { "Pragma", "no-cache", "no-cache" }, new Object[] { "Upgrade",
                    "HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11", "HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11" }, };
}

From source file:com.create.controller.ValidationResultRestTestExecutor.java

private <R, T> void executeTestRestRequest(String urlTemplate, String testName, Class<R> requestObjectType,
        Class<T> validatedObjectType) throws Exception {
    final R requestObject = getRequestObject(urlTemplate, testName, requestObjectType);
    final HttpEntity<R> entity = new HttpEntity<>(requestObject);
    final ParameterizedTypeReference<ValidationResult<T>> genericResponseType = getGenericResponseType(
            validatedObjectType);/*from   w ww. j  a  v  a 2 s.  com*/

    final ResponseEntity<ValidationResult<T>> responseEntity = restTemplate.exchange(urlTemplate,
            HttpMethod.POST, entity, genericResponseType);

    final ValidationResult<T> responseObject = getResponseObject(urlTemplate, testName, validatedObjectType);
    assertThat(responseEntity.getBody(), is(responseObject));
    final HttpStatus statusCode = getExpectedStatusCode(responseObject);
    assertThat(responseEntity.getStatusCode(), is(statusCode));
}

From source file:net.eusashead.hateoas.springhalbuilder.controller.CustomerListController.java

@RequestMapping(method = RequestMethod.OPTIONS)
public ResponseEntity<Void> options(OptionsResponseBuilder<Void> builder) {
    return builder.allow(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.POST).build();
}

From source file:springfox.documentation.spring.web.readers.parameter.ParameterTypeReader.java

private static String queryOrForm(OperationContext context) {
    if (context.consumes().contains(MediaType.APPLICATION_FORM_URLENCODED)
            && context.httpMethod() == HttpMethod.POST) {
        return "form";
    }/* w w  w .  j a v  a 2s . com*/
    return "query";
}

From source file:library.SecurityConfiguration.java

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.httpBasic().and().authorizeRequests().antMatchers(HttpMethod.DELETE, "/user/delete").hasRole("ADMIN")
            .antMatchers(HttpMethod.DELETE, "/user/passBook").hasRole("ADMIN")
            .antMatchers(HttpMethod.DELETE, "/books/delete").hasRole("ADMIN")
            .antMatchers(HttpMethod.GET, "/users/all").hasRole("ADMIN")
            .antMatchers(HttpMethod.GET, "/users/user/**").hasAnyRole("USER", "ADMIN")
            .antMatchers(HttpMethod.GET, "/books/user/**").hasAnyRole("USER", "ADMIN")
            .antMatchers(HttpMethod.GET, "/books/book/**").hasAnyRole("USER", "ADMIN")
            .antMatchers(HttpMethod.POST, "/books/book/search").hasAnyRole("USER", "ADMIN")
            .antMatchers(HttpMethod.GET, "/book/status/*").hasAnyRole("USER", "ADMIN")
            .antMatchers(HttpMethod.GET, "/books/all").hasAnyRole("USER", "ADMIN")
            .antMatchers(HttpMethod.POST, "/users/user/search").hasRole("ADMIN")
            .antMatchers(HttpMethod.POST, "/user/takeBook").hasAnyRole("USER", "ADMIN")
            .antMatchers(HttpMethod.POST, "/books/add").hasRole("ADMIN")
            .antMatchers(HttpMethod.POST, "/books/update").hasRole("ADMIN").and().csrf().disable();
}

From source file:org.openlmis.fulfillment.service.AuthService.java

/**
 * Retrieves access token from the auth service.
 *
 * @return token.//ww w. j a  v  a 2 s .com
 */
@Cacheable("token")
public String obtainAccessToken() {
    String plainCreds = clientId + ":" + clientSecret;
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);

    HttpEntity<String> request = new HttpEntity<>(headers);

    RequestParameters params = RequestParameters.init().set("grant_type", "client_credentials");

    ResponseEntity<?> response = restTemplate.exchange(createUri(authorizationUrl, params), HttpMethod.POST,
            request, Object.class);

    return ((Map<String, String>) response.getBody()).get(ACCESS_TOKEN);
}