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:id.co.teleanjar.ppobws.restclient.RestClientService.java

public Map<String, Object> inquiry(String idpel, String idloket, String merchantCode) throws IOException {
    String uri = "http://localhost:8080/ppobws/api/produk";
    RestTemplate restTemplate = new RestTemplate();

    HttpHeaders headers = createHeaders("superuser", "passwordku");
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(uri).queryParam("idpel", idpel)
            .queryParam("idloket", idloket).queryParam("merchantcode", merchantCode);
    HttpEntity<?> entity = new HttpEntity<>(headers);

    ResponseEntity<String> httpResp = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET,
            entity, String.class);
    String json = httpResp.getBody();
    LOGGER.info("JSON [{}]", json);
    LOGGER.info("STATUS [{}]", httpResp.getStatusCode().toString());

    Map<String, Object> map = new HashMap<>();
    ObjectMapper mapper = new ObjectMapper();

    map = mapper.readValue(json, new TypeReference<HashMap<String, Object>>() {
    });/*from w ww . j  a  v  a 2s . c om*/
    return map;
}

From source file:com.logaritex.hadoop.configuration.manager.http.AndroidHttpService.java

public <R> R get(String url, Class<R> responseType, Object... uriVariables) {

    R response = restTemplate.exchange(baseUrl + url, HttpMethod.GET, new HttpEntity<Object>(httpHeaders),
            responseType, uriVariables).getBody();

    return response;
}

From source file:tools.RequestSendingRunnable.java

private RequestEntity<Void> requestWithTraceId() {
    HttpHeaders headers = new HttpHeaders();
    headers.add(Span.TRACE_ID_NAME, Span.idToHex(this.traceId));
    headers.add(Span.SPAN_ID_NAME, Span.idToHex(this.spanId));
    URI uri = URI.create(this.url);
    RequestEntity<Void> requestEntity = new RequestEntity<>(headers, HttpMethod.GET, uri);
    log.info("Request [" + requestEntity + "] is ready");
    return requestEntity;
}

From source file:io.fabric8.quickstarts.camel.ApplicationTest.java

@Test
public void newOrderTest() {
    // Wait for maximum 5s until the first order gets inserted and processed
    NotifyBuilder notify = new NotifyBuilder(camelContext).fromRoute("generate-order").whenDone(2).and()
            .fromRoute("process-order").whenDone(1).create();
    assertThat(notify.matches(10, TimeUnit.SECONDS)).isTrue();

    // Then call the REST API
    ResponseEntity<Order> orderResponse = restTemplate.getForEntity("/camel-rest-sql/books/order/1",
            Order.class);
    assertThat(orderResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
    Order order = orderResponse.getBody();
    assertThat(order.getId()).isEqualTo(1);
    assertThat(order.getAmount()).isBetween(1, 10);
    assertThat(order.getItem()).isIn("Camel", "ActiveMQ");
    assertThat(order.getDescription()).isIn("Camel in Action", "ActiveMQ in Action");
    assertThat(order.isProcessed()).isTrue();

    ResponseEntity<List<Book>> booksResponse = restTemplate.exchange("/camel-rest-sql/books", HttpMethod.GET,
            null, new ParameterizedTypeReference<List<Book>>() {
            });/* w  w w.j a  va  2s. c o m*/
    assertThat(booksResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
    List<Book> books = booksResponse.getBody();
    assertThat(books).hasSize(2);
    assertThat(books).element(0).hasFieldOrPropertyWithValue("description", "ActiveMQ in Action");
    assertThat(books).element(1).hasFieldOrPropertyWithValue("description", "Camel in Action");
}

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

@Test(expected = EtcdException.class)
public void getWithResourceAccessException() throws EtcdException {
    server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample"))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
            .andRespond(MockRestResponseCreators.withStatus(HttpStatus.NOT_FOUND)
                    .contentType(MediaType.APPLICATION_JSON)
                    .body(new ClassPathResource("EtcdClientTest_get.json")));

    try {// w w  w  . j  a  v  a2 s  . co  m
        client.get("sample");
    } finally {
        server.verify();
    }
}

From source file:com.work.petclinic.SampleWebUiApplicationTests.java

@Test
public void testHome() throws Exception {
    ResponseEntity<String> page = sendRequest("http://localhost:" + this.port, HttpMethod.GET);

    assertEquals(HttpStatus.OK, page.getStatusCode());
    assertTrue("Wrong body (title doesn't match):\n" + page.getBody(),
            page.getBody().contains(getMessageBundleText("app.title")));
    assertTrue("Wrong body (did not find heading):\n" + page.getBody(),
            page.getBody().contains(getMessageBundleText("welcome")));
}

From source file:de.wirthedv.appname.SpringBootFacesApplicationTests.java

@Test
public void testJsfWelcomePageAccessibleByAdmin() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.add(WebSecurityConfiguration.PREAUTH_USER_HEADER, "admin");
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port,
            HttpMethod.GET, new HttpEntity<Void>(headers), String.class);

    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("<h1>Home page</h1>"));
}

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

@Override
public List<Status> listStatuses(String owner, String repository, String ref) {
    Map<String, Object> uriVariables = new HashMap<>();
    uriVariables.put("owner", owner);
    uriVariables.put("repository", repository);
    uriVariables.put("ref", ref);

    return getRestOperations()
            .exchange(buildUri("/repos/{owner}/{repository}/commits/{ref}/statuses", uriVariables),
                    HttpMethod.GET, null, statusListTypeRef)
            .getBody();/*from   w ww .  j av  a 2s .co m*/
}

From source file:io.fabric8.che.starter.client.keycloak.KeycloakClient.java

private String getResponseBody(KeycloakEndpoint endpoint, String authHeader) {
    RestTemplate template = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.add("Authorization", authHeader);
    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
    ResponseEntity<String> response = template.exchange(endpoint.toString(), HttpMethod.GET, entity,
            String.class);
    return response.getBody();
}

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

public void expectStudentCourseImplementationEventsRequest(String courseImplementationId) {
    server.expect(requestTo(eventsUrl(courseImplementationId))).andExpect(method(HttpMethod.GET)).andRespond(
            withSuccess(SampleDataFiles.toText("coursepage/studentevents.json"), MediaType.APPLICATION_JSON));
}