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.iata.ndc.trial.controllers.DefaultController.java

@RequestMapping(value = "/sita", method = RequestMethod.GET)
public String getSita() {

    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.getObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    converters.add(converter);/*ww  w .j  a  v a 2 s  . c  om*/
    restTemplate.setMessageConverters(converters);

    HttpHeaders headers = new HttpHeaders();
    headers.add("client-key", "zmd9apqgg2jwekf8zgqg5ybf");
    headers.setContentType(MediaType.APPLICATION_JSON);

    ResponseEntity<BALocationsResponseWrapper> baLocationsResponse = restTemplate.exchange(
            "https://api.ba.com/rest-v1/v1/balocations", HttpMethod.GET, new HttpEntity<Object>(headers),
            BALocationsResponseWrapper.class);
    System.out.println(baLocationsResponse.getBody().getGetBALocationsResponse().getCountry().size());
    return "index";
}

From source file:com.bodybuilding.argos.discovery.ClusterListDiscoveryTest.java

@Test
public void testGetClusters_withMultipleUrls() {
    String mockBody = "" + "[\n" + "{\n" + "\"name\": \"test1\",\n" + "\"link\": \"http://meh.com\",\n"
            + "\"turbineStream\": \"http://meh.com/turbine/turbine.stream?cluster=test1\"\n" + "},\n" + "{\n"
            + "\"name\": \"test2\",\n" + "\"link\": \"http://meh2.com\",\n"
            + "\"turbineStream\": \"http://meh2.com:8080/turbine/turbine.stream?cluster=test2\"\n" + "}" + "]";

    String mockBody2 = "" + "[\n" + "{\n" + "\"name\": \"test3\",\n" + "\"link\": \"http://meh.com\",\n"
            + "\"turbineStream\": \"http://meh.com/turbine/turbine.stream?cluster=test1\"\n" + "},\n" + "{\n"
            + "\"name\": \"test4\",\n" + "\"link\": \"http://meh2.com\",\n"
            + "\"turbineStream\": \"http://meh2.com:8080/turbine/turbine.stream?cluster=test2\"\n" + "}" + "]";

    RestTemplate restTemplate = new RestTemplate();
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
    mockServer.expect(requestTo("http://127.0.0.1")).andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(mockBody, MediaType.APPLICATION_JSON));
    mockServer.expect(requestTo("http://127.0.0.2")).andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(mockBody2, MediaType.APPLICATION_JSON));

    Set<String> urls = Sets.newLinkedHashSet();
    urls.add("http://127.0.0.1");
    urls.add("http://127.0.0.2");
    ClusterListDiscovery discovery = new ClusterListDiscovery(urls, restTemplate);
    Collection<Cluster> clusters = discovery.getCurrentClusters();
    mockServer.verify();//w  w w.  j  av a 2  s.  c o  m
    assertNotNull(clusters);
    assertEquals(4, clusters.size());
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchDigitizations.java

/**
 * Method, where all digitizations are read from server.
 * All heavy lifting is made here./*from ww w  .j av a  2  s  .  c o m*/
 *
 * @param params omitted here
 * @return list of fetched digitizations
 */
@Override
protected List<Digitization> doInBackground(Void... params) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_DIGITIZATIONS;

    setState(RUNNING, R.string.working_ws_digitization);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    try {
        // Make the network request
        Log.d(TAG, url);
        ResponseEntity<DigitizationList> response = restTemplate.exchange(url, HttpMethod.GET, entity,
                DigitizationList.class);
        DigitizationList body = response.getBody();

        if (body != null) {
            return body.getDigitizations();
        }

    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return Collections.emptyList();
}

From source file:com.cemeterylistingswebtest.test.rest.LoginControllerTest.java

@Test(enabled = false)
public void testreadClubById() {
    String ID = "2";
    HttpEntity<?> requestEntity = getHttpEntity();
    ResponseEntity<Cemetery> responseEntity = restTemplate.exchange(URL + "api/Subscriber/id/" + ID,
            HttpMethod.GET, requestEntity, Cemetery.class);
    Cemetery cemetery = responseEntity.getBody();

    Assert.assertNotNull(cemetery);//w  w w.j a  v  a  2  s  .  c  om

}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchElectrodeFixes.java

/**
 * Method, where all electrodeTypes are read from server.
 * All heavy lifting is made here.// w ww  .  j  a v  a2s  . c om
 *
 * @param params omitted here
 * @return list of fetched electrodeFixes
 */
@Override
protected List<ElectrodeFix> doInBackground(Void... params) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_ELECTRODE_FIXLIST;

    setState(RUNNING, R.string.working_ws_electrode_fix);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    try {
        // Make the network request
        Log.d(TAG, url);
        ResponseEntity<ElectrodeFixList> response = restTemplate.exchange(url, HttpMethod.GET, entity,
                ElectrodeFixList.class);
        ElectrodeFixList body = response.getBody();

        if (body != null) {
            return body.getElectrodeFixList();
        }

    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return Collections.emptyList();
}

From source file:org.openbaton.nse.beans.connectivitymanageragent.ConnectivityManagerRequestor.java

public Server getServerData(String hypervisorName, String serverName) {

    logger.debug("Getting data for server " + serverName + " that belong to " + hypervisorName);
    String url = configuration.getBaseUrl() + "/server/" + hypervisorName + "/" + serverName;
    HttpHeaders headers = new HttpHeaders();
    HttpEntity<String> getEntity = new HttpEntity<>(headers);
    ResponseEntity<String> server = template.exchange(url, HttpMethod.GET, getEntity, String.class);

    logger.debug("Setting of QoS has produced http status:" + server.getStatusCode() + " with body: "
            + server.getBody());/*from ww  w.ja v  a2  s  .  c o m*/

    if (!server.getStatusCode().is2xxSuccessful()) {
        return null;
    } else {
        Server result = mapper.fromJson(server.getBody(), Server.class);
        logger.debug("Request produced " + server.getStatusCode() + " with data "
                + mapper.toJson(result, Server.class));
        return result;
    }
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchElectrodeTypes.java

/**
 * Method, where all electrodeTypes are read from server.
 * All heavy lifting is made here.// w w w .j a v a2 s. c o  m
 *
 * @param params omitted here
 * @return list of fetched electrodeTypes
 */
@Override
protected List<ElectrodeType> doInBackground(Void... params) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_ELECTRODE_TYPES;

    setState(RUNNING, R.string.working_ws_electrode_type);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    try {
        // Make the network request
        Log.d(TAG, url);
        ResponseEntity<ElectrodeTypeList> response = restTemplate.exchange(url, HttpMethod.GET, entity,
                ElectrodeTypeList.class);
        ElectrodeTypeList body = response.getBody();

        if (body != null) {
            return body.getElectrodeTypes();
        }

    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return Collections.emptyList();
}

From source file:com.epam.reportportal.gateway.CompositeInfoEndpoint.java

@RequestMapping(value = "/composite/{endpoint}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody//from  www .j  ava  2 s .  co m
public Map<String, ?> compose(@PathVariable("endpoint") String endpoint) {
    return discoveryClient.getServices().stream()
            .map((Function<String, AbstractMap.SimpleImmutableEntry<String, Object>>) service -> {
                try {
                    List<ServiceInstance> instances = discoveryClient.getInstances(service);
                    if (instances.isEmpty()) {
                        return new AbstractMap.SimpleImmutableEntry<>(service, "DOWN");
                    }
                    ServiceInstance instance = instances.get(0);
                    String protocol = instance.isSecure() ? "https" : "http";
                    HttpHeaders headers = new HttpHeaders();
                    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
                    return new AbstractMap.SimpleImmutableEntry<>(instance.getServiceId(),
                            loadBalancedRestTemplate.exchange(protocol + "://{service}/{endpoint}",
                                    HttpMethod.GET, new HttpEntity<>(null, headers), Map.class,
                                    instance.getServiceId(), endpoint).getBody());
                } catch (Exception e) {
                    return new AbstractMap.SimpleImmutableEntry<>(service, "DOWN");
                }
            }).collect(toMap(AbstractMap.SimpleImmutableEntry::getKey,
                    AbstractMap.SimpleImmutableEntry::getValue, (value1, value2) -> value2));

}

From source file:org.opendatakit.api.admin.UserAdminServiceTest.java

@Test
public void putGetDeleteListTest() {

    // Get initial number of users
    // (Admin and anonymous are automatically created)
    String getUserListUrl = ConstantsUtils.url(server) + "/admin/users/";
    ResponseEntity<List<UserEntity>> initialUserList = restTemplate.exchange(getUserListUrl, HttpMethod.GET,
            null, new ParameterizedTypeReference<List<UserEntity>>() {
            });//from w  ww  .ja v a 2s  . c  o  m

    int initialNumberUsers = initialUserList.getBody().size();
    logger.info(initialNumberUsers + " users already exist in the database");

    logger.info("List of all users");
    for (UserEntity entity : initialUserList.getBody()) {
        logger.info(entity);
    }

    logger.info("Create multiple test users");
    for (UserEntity userEntity : testUserList) {
        TestUtils.putGetOneUser(restTemplate, server, userEntity);
    }

    logger.info("Retrieve list of all users");
    getUserListUrl = ConstantsUtils.url(server) + "/admin/users/";
    ResponseEntity<List<UserEntity>> getResponse = restTemplate.exchange(getUserListUrl, HttpMethod.GET, null,
            new ParameterizedTypeReference<List<UserEntity>>() {
            });

    logger.info("List of all users");
    for (UserEntity entity : getResponse.getBody()) {
        logger.info(entity);
    }

    logger.info("Check that " + testUserList.size() + " users were added.");
    assertThat(getResponse.getStatusCode(), is(HttpStatus.OK));
    logger.info("" + getResponse.getBody().size() + " - " + initialNumberUsers + " = " + testUserList.size());
    assertThat(getResponse.getBody().size() - initialNumberUsers, is(testUserList.size()));

    logger.info("Delete the new users");
    for (UserEntity userEntity : testUserList) {
        TestUtils.deleteGetOneUser(restTemplate, server, userEntity);
    }
}

From source file:comsat.sample.ui.method.SampleMethodSecurityApplicationTests.java

@Test
public void testDenied() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", "user");
    form.set("password", "user");
    getCsrf(form, headers);//  w w  w. jav  a  2  s.c  o  m
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/login",
            HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class);
    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
    String cookie = entity.getHeaders().getFirst("Set-Cookie");
    headers.set("Cookie", cookie);
    ResponseEntity<String> page = new TestRestTemplate().exchange(entity.getHeaders().getLocation(),
            HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
    assertEquals(HttpStatus.FORBIDDEN, page.getStatusCode());
    assertTrue("Wrong body (message doesn't match):\n" + entity.getBody(),
            page.getBody().contains("Access denied"));
}