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:rest.ApplianceRestController.java

@Test
public void testCreate() {
    Appliance app = new Appliance.Builder("samTv003").brand("samsung").descrip("HDTV").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:com.mycompany.trader.TradingConnect.java

private static void loginAndSaveJsessionIdCookie(final String user, final String password,
        final HttpHeaders headersToUpdate) {

    String url = "http://localhost:" + port + "/blueprint-trading-services/login.html";

    new RestTemplate().execute(url, HttpMethod.POST, new RequestCallback() {
        @Override/*from w  w w.  jav  a2  s.  c  o m*/
        public void doWithRequest(ClientHttpRequest request) throws IOException {
            MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
            map.add("username", user);
            map.add("password", password);
            new FormHttpMessageConverter().write(map, MediaType.APPLICATION_FORM_URLENCODED, request);
        }
    }, new ResponseExtractor<Object>() {
        @Override
        public Object extractData(ClientHttpResponse response) throws IOException {
            headersToUpdate.add("Cookie", response.getHeaders().getFirst("Set-Cookie"));
            return null;
        }
    });
}

From source file:com.bradley.musicapp.test.restapi.PersonRestControllerTest.java

@Test
public void tesCreate() {
    Name name = new Name();
    name.setFirstName("bradley");
    name.setLastName("bradley");

    Person p = new Person.Builder().name(name).build();

    System.out.println("rest Template = " + restTemplate);
    HttpEntity<Person> requestEntity = new HttpEntity<>(p, getContentType());
    //       Make the HTTP POST request, marshaling the request to JSON, and the response to a String

    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/person/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:io.pivotal.strepsirrhini.chaoslemur.reporter.DataDogReporterTest.java

@Test
public void badSendEvent() {
    this.mockServer.expect(requestTo(URI)).andExpect(method(HttpMethod.POST)).andRespond(withBadRequest());

    this.dataDog.sendEvent(new Event(UUID.randomUUID(), Collections.emptyList()));

    this.mockServer.verify();
}

From source file:com.nobu.dvdrentalweb.test.restapi.AccountRestControllerTest.java

@Test
public void tesCreate() {
    Account account = new Account.Builder().accountName("Savings").accountType("Gold Card").build();
    HttpEntity<Account> requestEntity = new HttpEntity<>(account, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/account/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:com.cisco.cta.taxii.adapter.RequestFactory.java

/**
 * Create the TAXII request.//from w w  w. j av a2 s.  co m
 * 
 * @param feed The TAXII feed.
 * @return TAXII poll request.
 * @throws Exception When any error occurs.
 */
public ClientHttpRequest createPollRequest(String messageId, TaxiiStatus.Feed feed) throws Exception {
    ClientHttpRequest req = httpRequestFactory.createRequest(pollEndpoint.toURI(), HttpMethod.POST);
    httpHeadersAppender.appendTo(req.getHeaders());
    httpBodyWriter.write(messageId, feed, req.getBody());
    return req;
}

From source file:com.miserablemind.api.consumer.tradeking.api.impl.StreamingTemplate.java

@Override
public Stream quotesAndTradesStream(final List<StreamListener> listeners, String[] quotes) {
    String quotesString = this.buildCommaSeparatedParameterValue(quotes);
    Stream stream = new ThreadedStreamConsumer() {
        protected StreamReader getStreamReader() throws StreamCreationException {
            MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>(1);
            parameters.set("symbols", String.valueOf(quotesString));
            return createStream(HttpMethod.POST, URL_STREAM_QUOTES_TRADES, parameters, listeners);
        }/*from  w  w  w . j ava2 s .  c o m*/
    };
    stream.open();
    return stream;
}

From source file:org.n52.restfulwpsproxy.wps.ExecuteClient.java

public StatusInfoDocument asyncExecute(String processId, ExecuteDocument executeDocument)
        throws URISyntaxException {
    HttpEntity<ExecuteDocument> requestEntity = new HttpEntity<ExecuteDocument>(executeDocument, headers);
    return restTemplate.exchange(baseUrl, HttpMethod.POST, requestEntity, StatusInfoDocument.class).getBody();
}

From source file:com.flipkart.poseidon.filters.RequestGzipFilter.java

@Override
public void doFilter(final ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest servletRequest = (HttpServletRequest) request;
    HttpServletResponse servletResponse = (HttpServletResponse) response;
    boolean isGzipped = servletRequest.getHeader(HttpHeaders.CONTENT_ENCODING) != null
            && servletRequest.getHeader(HttpHeaders.CONTENT_ENCODING).contains("gzip");
    boolean requestTypeSupported = HttpMethod.POST.toString().equals(servletRequest.getMethod())
            || HttpMethod.PUT.toString().equals(servletRequest.getMethod())
            || HttpMethod.PATCH.toString().equals(servletRequest.getMethod());
    if (isGzipped && !requestTypeSupported) {
        throw new IllegalStateException(new StringBuilder().append(servletRequest.getMethod())
                .append(" is not supports gzipped body of parameters.")
                .append(" Only POST requests are currently supported.").toString());
    }/*from w  w  w.  ja  va2  s.co  m*/
    if (isGzipped) {
        servletRequest = new GzippedInputStreamWrapper(servletRequest);
    }
    chain.doFilter(servletRequest, servletResponse);
}

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

@Test
public void createIssue() throws Exception {
    mockServer.expect(requestTo("https://api.github.com/repos/klaus/simple/issues"))
            .andExpect(method(HttpMethod.POST)).andExpect(content().contentType(MediaType.APPLICATION_JSON))
            // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN"))
            .andRespond(withSuccess(new ClassPathResource("createIssue.json", getClass()),
                    MediaType.APPLICATION_JSON));

    Issue issue = issuesTemplate.createIssue(new IssueRequest("issueTitle"), "klaus", "simple");

    Assertions.assertThat(issue).isNotNull();
    Assertions.assertThat(issue.getId()).isEqualTo(1);
}