Example usage for org.springframework.web.client RestTemplate exchange

List of usage examples for org.springframework.web.client RestTemplate exchange

Introduction

In this page you can find the example usage for org.springframework.web.client RestTemplate exchange.

Prototype

@Override
    public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
            ParameterizedTypeReference<T> responseType) throws RestClientException 

Source Link

Usage

From source file:com.provenance.cloudprovenance.connector.traceability.TraceabilityStoreConnector.java

public synchronized int updateTraceabilityRecord(String serviceId, String traceabilityRecordURI,
        String traceabilityNewEntryData) {

    logger.info("URI to the updated record: " + traceabilityRecordURI);
    //String restURI = "http://" + server_add + ":" + port_no + "/" + service
    //   + "/" + resource + "/" + serviceId + "/"
    //+ this.TRACEABILITY_TYPE + "/" + traceabilityExistingEntryId;

    RestTemplate restTemplate = new RestTemplate();

    HttpEntity<String> entityContent = new HttpEntity<String>(traceabilityNewEntryData, null);

    ResponseEntity<String> response = restTemplate.exchange(traceabilityRecordURI, HttpMethod.PUT,
            entityContent, String.class);

    // int responseNo = restTemplate.getForObject(restURI, Integer.class);
    //      restTemplate.put(traceabilityRecordURI, traceabilityNewEntryData);

    // TODO - how do I get the header value

    return response.getStatusCode().value();
}

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

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

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

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

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

From source file:io.fabric8.che.starter.client.WorkspaceClient.java

public WorkspaceStatus getWorkspaceStatus(String cheServerUrl, String workspaceId) {
    String url = CheRestEndpoints.CHECK_WORKSPACE.generateUrl(cheServerUrl, workspaceId);

    RestTemplate template = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> entity = new HttpEntity<String>(headers);

    ResponseEntity<WorkspaceStatus> status = template.exchange(url, HttpMethod.GET, entity,
            WorkspaceStatus.class);
    return status.getBody();
}

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

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

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

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

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

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./* ww  w.ja va2 s. co  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:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchHardwareList.java

/**
 * Method, where all hardwareList are read from server.
 * All heavy lifting is made here./*from   w w  w.j a  va2 s .  c  om*/
 *
 * @param params omitted here
 * @return list of fetched hardware
 */
@Override
protected List<Hardware> 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_HARDWARE;

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

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

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

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

/**
 * Method, where all softwareList are read from server.
 * All heavy lifting is made here.//from   w  w  w.  j  a  v a2 s.c om
 *
 * @param params omitted here
 * @return list of fetched software
 */
@Override
protected List<Software> 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_SOFTWARE;

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

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

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

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./*  ww  w .ja  va2  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:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchElectrodeFixes.java

/**
 * Method, where all electrodeTypes are read from server.
 * All heavy lifting is made here.//from  w  w  w.ja v  a2s.com
 *
 * @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:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchWeatherList.java

/**
 * Method, where all weatherList are read from server.
 * All heavy lifting is made here./*from  www .j a va2 s .  com*/
 *
 * @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();
}