Example usage for org.springframework.http HttpMethod GET

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

Introduction

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

Prototype

HttpMethod GET

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

Click Source Link

Usage

From source file:com.gopivotal.cla.github.RateLimitingClientHttpRequestInterceptorTest.java

@Test
public void block() throws InterruptedException, IOException {
    CountDownLatch latch = new CountDownLatch(1);

    MockClientHttpRequest request = new MockClientHttpRequest();
    MockClientHttpResponse response = new MockClientHttpResponse(new byte[0], HttpStatus.OK);
    ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);

    request.setMethod(HttpMethod.GET);
    request.setURI(URI.create("http://localhost"));

    when(execution.execute(request, new byte[0])).thenReturn(response);

    new Thread(new Trigger(this.interceptor, latch)).start();
    latch.await();//from  w ww  . j  a v a 2s. com

    this.interceptor.intercept(request, new byte[0], execution);
}

From source file:eu.cloudwave.wp5.feedbackhandler.rest.JsonRestClientImplTest.java

@Test
public void testGet() throws JsonProcessingException, IOException {
    setupExpectation(HttpMethod.GET);
    assertResponseOk(jsonRestClient.get(ANY_URL));
}

From source file:com.greglturnquist.spring.social.ecobee.api.impl.ThermostatTemplateTest.java

@Test
public void testGetThermostat() throws Exception {

    final Selection selection = Selection.thermostats("161775386723");
    selection.getSelection().setIncludeRuntime(true);
    selection.getSelection().setIncludeSettings(true);
    selection.getSelection().setIncludeSensors(true);
    final String selectionStr = UriUtils.encodeQueryParam(this.getObjectMapper().writeValueAsString(selection),
            "UTF-8");
    mockServer.expect(requestTo("https://api.ecobee.com/1/thermostat?json=" + selectionStr))
            .andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(jsonResource("thermostats"), MediaType.APPLICATION_JSON));

    final Thermostat thermostat = ecobee.thermostatOperations().getThermostat("161775386723");
    assertThat(thermostat, notNullValue());
    assertThat(thermostat.getIdentifier(), equalTo("161775386723"));
    assertThat(thermostat.getName(), equalTo("My Test Thermostat"));
    assertThat(thermostat.getLastModified(), equalTo("2011-01-28 23:40:25"));
    assertThat(thermostat.getSettings().getHvacMode(), equalTo("heat"));
    assertThat(thermostat.getSettings().getVent(), is(nullValue()));
}

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

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

From source file:architectedsec.sample.oauth2.Dingus.java

public void doFetch() {

    System.out.println("MAKING THE OAUTH2 REST REQUEST\n");

    ParameterizedTypeReference<PagedResources<Order>> responseType = new ParameterizedTypeReference<PagedResources<Order>>() {
    };/*www. j a  v a2 s  .  com*/
    ResponseEntity<PagedResources<Order>> result = template.exchange(
            "http://localhost:8181/orders/search/findByCustomerName?name=123", HttpMethod.GET, null,
            responseType);

    System.out.println("HTTP STATUS CODE=" + result.getStatusCode().toString() + "\n");
    System.out.println("RESPONSE DATA SIZE=" + result.getBody().getContent().size() + "\n");

    Iterator<Order> itr = result.getBody().getContent().iterator();

    while (itr.hasNext()) {

        Order element = itr.next();

        // Note that exposing the id property of the record is not supported by default.
        // This makes sense since it could be a security vulnerability.  However, you can expose if needed...
        // Cf. http://stackoverflow.com/questions/24936636/while-using-spring-data-rest-after-migrating-an-app-to-spring-boot-i-have-obser
        // N.B. The additional comment about the difference in configuration when using Spring-Boot.

        // System.out.println("Id=" + element.getId());

        System.out.println("Order-No=" + element.getOrderNumber());
        System.out.println("Order-Date=" + element.getOrderDate().toString());
        System.out.println("Customer=" + element.getCustomerName());
        System.out.println("Description=" + element.getDescription());
        System.out.println("Attr_j=" + element.getAttrJ());
        System.out.println("Attr_k=" + element.getAttrK());
        System.out.println("Attr_l=" + element.getAttrL() + "\n");

    }

    System.out.println("DONE MAKING THE REST REQUEST\n");

    return;

}

From source file:cz.muni.fi.mushroomhunter.restclient.LocationUpdateSwingWorker.java

@Override
protected Integer doInBackground() throws Exception {
    DefaultTableModel model = (DefaultTableModel) restClient.getTblLocation().getModel();
    int selectedRow = restClient.getTblLocation().getSelectedRow();

    String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD;
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    List<MediaType> mediaTypeList = new ArrayList<>();
    mediaTypeList.add(MediaType.ALL);/*  w w w . j  av a  2s .  c  om*/
    headers.setAccept(mediaTypeList);

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

    HttpEntity request = new HttpEntity<>(headers);

    ResponseEntity<LocationDto> responseEntity = restTemplate.exchange(
            RestClient.SERVER_URL + "pa165/rest/location/" + RestClient.getLocationIDs().get(selectedRow),
            HttpMethod.GET, request, LocationDto.class);

    LocationDto locationDto = responseEntity.getBody();

    locationDto.setName(restClient.getTfLocationName().getText());
    locationDto.setDescription(restClient.getTfLocationDescription().getText());
    locationDto.setNearCity(restClient.getTfLocationNearCity().getText());

    ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
    String json = ow.writeValueAsString(locationDto);
    request = new HttpEntity(json, headers);

    restTemplate.exchange(RestClient.SERVER_URL + "pa165/rest/location", HttpMethod.PUT, request,
            LocationDto.class);
    return selectedRow;
}

From source file:org.openlmis.fulfillment.service.referencedata.RightReferenceDataServiceTest.java

@Test
public void shouldFindRightByName() throws Exception {
    // given/*  w  w w .j a v  a  2  s  .com*/
    String name = "testRight";

    RightDto rightDto = generateInstance();
    rightDto.setName(name);

    RightDto[] rights = new RightDto[] { rightDto };
    RightReferenceDataService service = (RightReferenceDataService) prepareService();
    ResponseEntity<RightDto[]> response = mock(ResponseEntity.class);

    // when
    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class),
            eq(service.getArrayResultClass()))).thenReturn(response);
    when(response.getBody()).thenReturn(rights);

    RightDto right = service.findRight(name);

    // then
    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(),
            eq(service.getArrayResultClass()));

    URI uri = uriCaptor.getValue();
    String url = service.getServiceUrl() + service.getUrl() + "search?name=" + name;

    assertThat(uri.toString(), is(equalTo(url)));
    assertThat(right.getName(), is(equalTo(name)));

    assertAuthHeader(entityCaptor.getValue());
    assertThat(entityCaptor.getValue().getBody(), is(nullValue()));
}

From source file:com.google.cloud.servicebroker.awwvision.RedditScraper.java

@RequestMapping("/reddit")
String getRedditUrls(Model model, RestTemplate restTemplate) throws GeneralSecurityException {
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.USER_AGENT, redditUserAgent);
    RedditResponse response = restTemplate
            .exchange(REDDIT_URL, HttpMethod.GET, new HttpEntity<String>(headers), RedditResponse.class)
            .getBody();/*  w ww  .j  ava  2 s . c  o m*/

    storeAndLabel(response);

    return "reddit";
}

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

public ResultDocument getResults(String processId, String jobId) {
    HttpEntity<?> requestEntity = new HttpEntity<Object>(null, headers);

    ResponseEntity<ResultDocument> resultDocument = restTemplate.exchange(
            new RequestUrlBuilder(GET_RESULT).jobID(jobId).build(), HttpMethod.GET, requestEntity,
            ResultDocument.class);

    return resultDocument.getBody();
}

From source file:fi.helsinki.opintoni.server.WebPageServer.java

public void expectRssFeedRequest(String firstFeedUrl, String secondFeedUrl) {
    server.expect(requestTo(RSSFeedSampleData.WEBPAGE_CONTAINING_RSS_FEED_URL))
            .andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(String.format(SampleDataFiles.toText("rssfeedwebpage/rssFeedWebPage.html"),
                    firstFeedUrl, secondFeedUrl), MediaType.TEXT_HTML));
}