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.apigw.authserver.ServerRunning.java

public ResponseEntity<Void> postForStatus(String path, HttpHeaders headers,
        MultiValueMap<String, String> formData) {
    HttpHeaders actualHeaders = new HttpHeaders();
    actualHeaders.putAll(headers);//from   w w w  .j a  v a 2 s . c  o m
    actualHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    return client.exchange(getUrl(path), HttpMethod.POST,
            new HttpEntity<MultiValueMap<String, String>>(formData, actualHeaders), Void.class);
}

From source file:org.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.BasicAuthEndPointsServiceEnabledPredefinedTests.java

@Test
public void simpleAuthenticationServiceTestInvalidCredentials() throws Exception {
    CredentialsVO credentialsVO = new CredentialsVO();
    credentialsVO.setUsername("user");
    credentialsVO.setPassword("badpassword");
    HttpEntity<CredentialsVO> entity = new HttpEntity<CredentialsVO>(credentialsVO);

    ResponseEntity<AuthorizationData> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + baseApiPath + simpleAuthenticationEndpointPath, HttpMethod.POST,
            entity, AuthorizationData.class);
    assertEquals(HttpStatus.UNAUTHORIZED, responseEntity.getStatusCode());
}

From source file:org.cloudfoundry.identity.uaa.login.feature.AutologinIT.java

@Test
public void testClientAuthorization() throws Exception {
    Map<String, String> requestBody = new HashMap<>();
    requestBody.put("username", testAccounts.getUserName());
    requestBody.put("password", testAccounts.getPassword());

    try {//from   w w  w .j ava 2  s . co  m
        restOperations.exchange(baseUrl + "/autologin", HttpMethod.POST, new HttpEntity<>(requestBody),
                Map.class);
    } catch (HttpClientErrorException e) {
        assertEquals(HttpStatus.UNAUTHORIZED, e.getStatusCode());
    }
}

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

/**
 * Creates a new node with the given key-value pair under the node with the
 * given key./*from w w w  .  j  ava2  s.  com*/
 * 
 * @param key
 *            the directory node's key
 * @param value
 *            the value of the created node
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse create(final String key, final String value) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);

    MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1);
    payload.set("value", value);

    return execute(builder, HttpMethod.POST, payload, EtcdResponse.class);
}

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.ja  v  a2  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:org.client.one.service.OAuthAuthenticationService.java

public String getAuthorizationCode(String accessTokenA, String redirectUri, String appTokenClientTwo) {
    RestOperations rest = new RestTemplate();

    HttpHeaders headersA = new HttpHeaders();
    headersA.set("Authorization", "Bearer " + accessTokenA);

    ResponseEntity<String> resAuth2 = rest
            .exchange(/*from  w  w  w  .j a  v  a 2 s . c  om*/
                    MessageFormat.format(
                            "{0}/oauth/authorize?"
                                    + "client_id={1}&response_type=code&scope=WRITE&redirect_uri={2}",
                            oauthServerBaseURL, appTokenClientTwo, redirectUri),
                    HttpMethod.POST, new HttpEntity<String>(headersA), String.class);

    String sessionId = resAuth2.getHeaders().get("Set-Cookie").get(0);
    int p1 = sessionId.indexOf("=") + 1;
    int p2 = sessionId.indexOf(";");
    sessionId = sessionId.substring(p1, p2);
    headersA.add("Cookie", "JSESSIONID=" + sessionId);

    resAuth2 = rest.exchange(
            MessageFormat.format("{0}/oauth/authorize?" + "user_oauth_approval=true&authorize=Authorize",
                    oauthServerBaseURL),
            HttpMethod.POST, new HttpEntity<String>(headersA), String.class);

    String code = resAuth2.getHeaders().get("location").get(0);
    p1 = code.lastIndexOf("=") + 1;
    code = code.substring(p1);

    return code;
}

From source file:org.appverse.web.framework.backend.test.util.oauth2.tests.predefined.authorizationcode.Oauth2AuthorizationCodeFlowPredefinedTests.java

@Test
public void obtainAuthorizationCode() throws Exception {
    UriComponentsBuilder builder = UriComponentsBuilder
            .fromHttpUrl(authServerBaseUrl + oauth2AuthorizeEndpointPath);
    builder.queryParam("username", getUsername());
    builder.queryParam("password", getPassword());
    builder.queryParam("client_id", getClientId());
    builder.queryParam("response_type", "code");
    builder.queryParam("redirect_uri", "http://anywhere");
    // builder.queryParam("realm","oauth2-resource");

    // optional builder.queryParam("scope", "");
    // recommended (optional) builder.queryParam("state", "");

    //HttpEntity<String> entity = new HttpEntity("",headers);
    HttpEntity<String> entity = new HttpEntity("");
    ResponseEntity<String> result2 = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST,
            entity, String.class);

    // check this! assertEquals(HttpStatus.FOUND, result2.getStatusCode());        

    // Obtain the token from redirection URL after #
    URI location = result2.getHeaders().getLocation();
    authorizationCode = extractAuthorizationCode(location.toString());
    assertNotNull(authorizationCode);/* w  ww .  j a  v  a 2  s  .c o  m*/
}

From source file:com.thecorpora.qbo.androidapk.rest.RESTClient.java

public void stopVideo(String url) {
    url = url.replace("stream", "stop");
    RestTemplate restTemplate = mRest.getRestTemplate();
    HttpHeaders httpHeaders = new HttpHeaders();
    HttpEntity<Object> requestEntity = new HttpEntity<Object>(httpHeaders);
    restTemplate.exchange(url, HttpMethod.POST, requestEntity, null);
}

From source file:com.projectx.mvc.servicehandler.quickregister.QuickRegisterHandler.java

@Override
public Boolean reSendEmailHash(CustomerIdTypeEmailTypeDTO customerDTO) {

    HttpEntity<CustomerIdTypeEmailTypeDTO> entity = new HttpEntity<CustomerIdTypeEmailTypeDTO>(customerDTO);

    ResponseEntity<Boolean> detailsSentStatus = restTemplate.exchange(
            env.getProperty("rest.host") + "/customer/quickregister/resendEmailHash", HttpMethod.POST, entity,
            Boolean.class);

    if (detailsSentStatus.getStatusCode() == HttpStatus.OK)
        return detailsSentStatus.getBody();
    else/*from ww  w  .  j a va 2  s  . co m*/
        throw new ResourceNotFoundException();
}