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:com.appglu.impl.SyncTemplate.java

/**
 * {@inheritDoc}//from w  w  w .j ava  2s .  c o m
 */
public void downloadChangesForTables(final List<TableVersion> tables,
        final InputStreamCallback inputStreamCallback) throws AppGluRestClientException {
    RequestCallback requestCallback = new RequestCallback() {
        public void doWithRequest(ClientHttpRequest request) throws IOException {
            HttpEntity<Object> requestEntity = new HttpEntity<Object>(new TableVersionBody(tables));

            HttpHeaders requestHeaders = requestEntity.getHeaders();
            if (!requestHeaders.isEmpty()) {
                request.getHeaders().putAll(requestHeaders);
            }

            jsonMessageConverter.write(requestEntity.getBody(), requestHeaders.getContentType(), request);
        }
    };

    ResponseExtractor<Object> responseExtractor = new ResponseExtractor<Object>() {
        public Object extractData(ClientHttpResponse response) throws IOException {
            inputStreamCallback.doWithInputStream(response.getBody());
            return null;
        }
    };

    try {
        this.restOperations.execute(CHANGES_FOR_TABLES_URL, HttpMethod.POST, requestCallback,
                responseExtractor);
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.cisco.cta.taxii.adapter.AdapterTaskMultipartIT.java

private void initialMultipartRequestResponse() throws IOException {
    when(httpResp.getRawStatusCode()).thenReturn(200);
    when(httpResp.getBody()).thenReturn(taxiiPollRespBodyInitial);
    when(httpResp2.getRawStatusCode()).thenReturn(200);
    when(httpResp2.getBody()).thenReturn(taxiiPollRespBodyNext);
    task.run();/*from  w w  w  . j  a v a  2s.co  m*/
    verify(httpRequestFactory, times(2)).createRequest(pollServiceUri, HttpMethod.POST);
    assertThat(httpReqHeaders, hasAllTaxiiHeaders());
    verify(httpReq).execute();
    verify(httpReq2).execute();
    assertThat(httpReqBody, is(initialPollRequest("123", "collection_name")));
    assertThat(httpReq2Body, is(pollFulfillment("123", "collection_name", "1000#2000", "2")));
    httpReqBody.reset();
}

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

@Test(expected = AppGluRestClientException.class)
public void changesForTablesUsingCallback_NoVersion() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/sync/changes")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", jsonMediaType.toString()))
            .andExpect(content().string(compactedJson("data/sync_changes_for_tables_request")))
            .andRespond(withStatus(HttpStatus.OK).body(compactedJson("data/sync_parser_no_version"))
                    .headers(responseHeaders));

    MemoryTableChangesCallback callback = new MemoryTableChangesCallback();

    TableVersion loggedTable = new TableVersion("logged_table");
    TableVersion otherTable = new TableVersion("other_table", 1);

    this.syncOperations.changesForTables(callback, loggedTable, otherTable);
}

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

@Test
public void loginUnauthorized() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/users/login")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", jsonMediaType.toString()))
            .andExpect(content().string(compactedJson("data/user_login")))
            .andRespond(withStatus(HttpStatus.UNAUTHORIZED).body(compactedJson("data/user_unauthorized"))
                    .headers(responseHeaders));

    Assert.assertFalse(appGluTemplate.isUserAuthenticated());
    Assert.assertNull(appGluTemplate.getAuthenticatedUser());

    AuthenticationResult result = userOperations.login("username", "password");
    Assert.assertFalse(result.succeed());

    Assert.assertFalse(appGluTemplate.isUserAuthenticated());
    Assert.assertNull(appGluTemplate.getAuthenticatedUser());

    Assert.assertEquals(ErrorCode.APP_USER_UNAUTHORIZED, result.getError().getCode());
    Assert.assertEquals("Unauthorized to access resource because credentials are wrong or missing.",
            result.getError().getMessage());

    mockServer.verify();//w  ww . ja va 2 s . com
}

From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java

@Test
public void passwordGrantClientWithoutSecretIsOk() throws Exception {
    BaseClientDetails client = new BaseClientDetails(new RandomValueStringGenerator().generate(), "", "foo,bar",
            "password", "uaa.none");
    ResponseEntity<Void> result = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/oauth/clients"), HttpMethod.POST,
            new HttpEntity<BaseClientDetails>(client, headers), Void.class);

    assertEquals(HttpStatus.CREATED, result.getStatusCode());
}

From source file:com.aestheticsw.jobkeywords.service.termextractor.impl.fivefilters.FiveFiltersClient.java

public String[][] executeFiveFiltersPost(String content) {
    String query = "http://termextract.fivefilters.org/extract.php";

    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("text", content);
    params.add("output", "json");
    params.add("max", "300");

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(
            params, requestHeaders);//from  w w  w . jav  a  2  s.  co m

    ResponseEntity<String[][]> stringArrayEntty = restTemplate.exchange(query, HttpMethod.POST, requestEntity,
            String[][].class);

    String[][] stringArray = stringArrayEntty.getBody();

    return stringArray;
}

From source file:com.citrix.g2w.webdriver.dependencies.AccountServiceQAIImpl.java

/**
 * Method used to create account and user.
 * //  ww w .ja v a 2  s  . c  om
 * @param plans
 *            (user plan)
 * @param email
 *            (user email)
 * @param password
 *            (user password)
 * @param firstName
 *            (user first name)
 * @param lastName
 *            (user last name)
 * @param locale
 *            (user locale)
 * @param timezone
 *            (user time zone)
 * @param isAdmin
 *            (is Admin)
 * @return accountInfo
 */
private Map<String, Long> createAccountAndUserInAS(final String[] plans, final String email,
        final String password, final String firstName, final String lastName, final String locale,
        final String timezone, final boolean isAdmin) {

    Map<String, Long> accountInfo;

    JSONObject request = new JSONObject();

    try {

        JSONObject accountJson = new JSONObject();
        accountJson.put("name", "Webtest Account");
        accountJson.put("country", "US");

        JSONObject userJson = new JSONObject();
        userJson.put("email", email);
        userJson.put("firstName", firstName);
        userJson.put("lastName", lastName);
        userJson.put("externalAdmin", isAdmin);
        userJson.put("password", password);
        userJson.put("locale", locale);
        userJson.put("timezone", timezone);

        request.put("account", accountJson);
        request.put("user", userJson);
        request.put("plans", plans);

        HttpEntity httpEntity = new HttpEntity(request.toString(), this.accountSvcHeaders);
        String result = this.restTemplate
                .exchange(this.accountSvcUrl + "/accounts/users", HttpMethod.POST, httpEntity, String.class)
                .getBody();

        accountInfo = this.objectMapper.readValue(result, Map.class);

        return accountInfo;

    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
}

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

@Test
public void subscribeContextRequestOK_XML() throws Exception {
    // Ensure host is registered (will use XML)
    ngsiClient.protocolRegistry.registerHost(baseUrl);

    String responseBody = xml(xmlConverter, createSubscribeContextResponseTemperature());

    this.mockServer.expect(requestTo(baseUrl + "/ngsi10/subscribeContext")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", MediaType.APPLICATION_XML_VALUE))
            .andExpect(header("Accept", MediaType.APPLICATION_XML_VALUE))
            .andExpect(xpath("subscribeContextRequest/entityIdList/*").nodeCount(1))
            .andExpect(xpath("subscribeContextRequest/entityIdList/entityId/id").string("Room1"))
            .andExpect(xpath("subscribeContextRequest/entityIdList/entityId/@type").string("Room"))
            .andExpect(xpath("subscribeContextRequest/entityIdList/entityId/@isPattern").string("false"))
            .andExpect(xpath("subscribeContextRequest/attributeList/*").nodeCount(1))
            .andExpect(xpath("subscribeContextRequest/attributeList/attribute").string("temperature"))
            .andExpect(xpath("subscribeContextRequest/reference").string("http://localhost:1028/accumulate"))
            .andExpect(xpath("subscribeContextRequest/duration").string("P1M"))
            .andExpect(xpath("subscribeContextRequest/throttling").string("PT1S"))
            .andExpect(//from   w w w  .ja  v a  2 s. co m
                    xpath("subscribeContextRequest/restriction/attributeExpression").string("xpath/expression"))
            .andExpect(
                    xpath("subscribeContextRequest/restriction/scope/operationScope/scopeType").string("type"))
            .andExpect(xpath("subscribeContextRequest/restriction/scope/operationScope/scopeValue")
                    .string("value"))
            .andRespond(withSuccess(responseBody, MediaType.APPLICATION_XML));

    SubscribeContextResponse response = ngsiClient
            .subscribeContext(baseUrl, null, createSubscribeContextTemperature()).get();
    this.mockServer.verify();

    Assert.assertNull(response.getSubscribeError());
    Assert.assertEquals("12345678", response.getSubscribeResponse().getSubscriptionId());
    Assert.assertEquals("P1M", response.getSubscribeResponse().getDuration());
}

From source file:com.cisco.cta.taxii.adapter.AdapterTaskIT.java

private void initialRequestResponse() throws IOException {
    when(httpResp.getRawStatusCode()).thenReturn(200);
    when(httpResp.getBody()).thenReturn(taxiiPollRespBodyInitial);
    task.run();/*from w  w  w.  jav  a  2s  .c  om*/
    verify(httpRequestFactory).createRequest(pollServiceUri, HttpMethod.POST);
    verify(httpReq).execute();
    assertThat(httpReqHeaders, hasAllTaxiiHeaders());
    assertThat(httpReqBody, is(initialPollRequest("123", "collection_name")));
    httpReqBody.reset();
}