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:org.obiba.mica.user.UserProfileService.java

private <T> T executeQuery(String serviceUrl, Class<T> returnType) {

    RestTemplate template = newRestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.set(APPLICATION_AUTH_HEADER, getApplicationAuth());
    HttpEntity<String> entity = new HttpEntity<>(null, headers);
    ResponseEntity<T> response = template.exchange(serviceUrl, HttpMethod.GET, entity, returnType);

    return response.getBody();
}

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

/**
 * Method, where all scenarios are read from server.
 * All heavy lifting is made here./*from  w ww  .  j a  v a  2s  .c o  m*/
 *
 * @param params omitted here
 * @return list of fetched scenarios
 */
@Override
protected List<Scenario> 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_SCENARIOS + qualifier;

    setState(RUNNING, R.string.working_ws_scenarios);
    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<ScenarioList> response = restTemplate.exchange(url, HttpMethod.GET, entity,
                ScenarioList.class);
        ScenarioList body = response.getBody();

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

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

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRouteCreatingStep.java

private String getAppRoutesInfo(String subDomain, String domainGuid) {
    String cfGetRoutesUrl = cfApiUrl + GET_ROUTES_ENDPOINT_TEMPLATE;

    ResponseEntity<String> response = cfRestTemplate.exchange(cfGetRoutesUrl, HttpMethod.GET,
            HttpCommunication.simpleJsonRequest(), String.class, subDomain, domainGuid);
    return response.getBody();
}

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

/**
 * Method, where all electrodeLocations are read from server.
 * All heavy lifting is made here./*from  www  .  j av a 2  s.  com*/
 *
 * @param params omitted here
 * @return list of fetched electrodeLocations
 */
@Override
protected List<ElectrodeLocation> 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_LOCATIONS;

    setState(RUNNING, R.string.working_ws_electrode_location);
    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<ElectrodeLocationList> response = restTemplate.exchange(url, HttpMethod.GET, entity,
                ElectrodeLocationList.class);
        ElectrodeLocationList body = response.getBody();

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

    } 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.CemeteryControllerTest.java

@Test(enabled = false)
public void testgetAllClubs() {
    HttpEntity<?> requestEntity = getHttpEntity();
    ResponseEntity<Cemetery[]> responseEntity = restTemplate.exchange(URL + "api/cemetery/show", HttpMethod.GET,
            requestEntity, Cemetery[].class);
    Cemetery[] cemeteries = responseEntity.getBody();
    for (Cemetery cemetery : cemeteries) {
        System.out.println("The Club Name is " + cemetery.getContactName());

    }//from  w ww .  j  ava 2  s .  com

    Assert.assertTrue(cemeteries.length > 0);
}

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

/**
 * Method, where all research groups 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 research groups
 */
@Override
protected List<ResearchGroup> 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_RESEARCH_GROUPS + qualifier;

    setState(RUNNING, R.string.working_ws_groups);
    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<ResearchGroupList> response = restTemplate.exchange(url, HttpMethod.GET, entity,
                ResearchGroupList.class);
        ResearchGroupList body = response.getBody();

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

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

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

public void expectStudentStudyRightsRequest(String studentNumber, String responseFile) {
    server.expect(requestTo(studyRightsUrl(studentNumber))).andExpect(method(HttpMethod.GET)).andRespond(
            withSuccess(SampleDataFiles.toText("oodi/" + responseFile), MediaType.APPLICATION_JSON));
}

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

public void testreadTrackById() {
    String trackId = "2";
    HttpEntity<?> requestEntity = getHttpEntity();
    ResponseEntity<Track> responseEntity = restTemplate.exchange(URL + "api/track/id/" + trackId,
            HttpMethod.GET, requestEntity, Track.class);
    Track track = responseEntity.getBody();

    Assert.assertNotNull(track);//from  w  w w .  j a  v  a2 s.  c om

}

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

/**
 * Method, where all weatherList are read from server.
 * All heavy lifting is made here.// w w w.j a  va 2 s .  c  om
 *
 * @param params parameters - omitted here
 * @return list of fetched weather
 */
@Override
protected List<Weather> 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_WEATHER + "/" + researchGroupId;

    setState(RUNNING, R.string.working_ws_weather);
    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<WeatherList> response = restTemplate.exchange(url, HttpMethod.GET, entity,
                WeatherList.class);
        WeatherList body = response.getBody();

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

    } 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.DisplayDeceasedControllerTest.java

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

    Assert.assertNotNull(cemetery);/*from www  .  jav  a 2s . c  o m*/

}