Example usage for org.springframework.http HttpEntity HttpEntity

List of usage examples for org.springframework.http HttpEntity HttpEntity

Introduction

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

Prototype

public HttpEntity(MultiValueMap<String, String> headers) 

Source Link

Document

Create a new HttpEntity with the given headers and no body.

Usage

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  . j  a v  a2 s  . 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.FetchElectrodeTypes.java

/**
 * Method, where all electrodeTypes are read from server.
 * All heavy lifting is made here./*from  www  .  j a v  a 2 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:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchPharmaceuticals.java

/**
 * Method, where all pharmaceuticals are read from server.
 * All heavy lifting is made here./*  ww w.  j ava  2s  .co  m*/
 *
 * @param params omitted here
 * @return list of fetched pharmaceuticals
 */
@Override
protected List<Pharmaceutical> 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_PHARMACEUTICAL;

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

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

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

/**
 * Method, where all electrodeSystems are read from server.
 * All heavy lifting is made here.//from  w  w w  .  j  a v a2s. com
 *
 * @param params omitted here
 * @return list of fetched electrodeSystems
 */
@Override
protected List<ElectrodeSystem> 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_SYSTEMS;

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

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

    } 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.//  w  ww .j ava 2  s .  com
 *
 * @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.RemoveReservation.java

/**
 * Method, where reservation information is pushed to server in order to remove it.
 * All heavy lifting is made here./*  w w w. jav a 2  s  .co  m*/
 *
 * @param params only one Reservation object is accepted
 * @return true if reservation is removed
 */
@Override
protected Boolean doInBackground(Reservation... params) {

    Reservation data = params[0];

    //nothing to remove
    if (data == null)
        return false;

    try {

        setState(RUNNING, R.string.working_ws_remove);

        SharedPreferences credentials = getCredentials();
        String username = credentials.getString("username", null);
        String password = credentials.getString("password", null);
        String url = credentials.getString("url", null) + Values.SERVICE_RESERVATION + data.getReservationId();

        HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setAuthorization(authHeader);
        HttpEntity<Reservation> entity = new HttpEntity<Reservation>(requestHeaders);

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

        Log.d(TAG, url + "\n" + entity);
        restTemplate.exchange(url, HttpMethod.DELETE, entity, String.class);
        return true;
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage());
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return false;
}

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 ww w. j a  v  a2s  .c  o m
 *
 * @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: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.//from   w w  w  .  j a  v  a  2 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: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 v a2s .  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();
}

From source file:de.escalon.hypermedia.spring.sample.test.DummyEventControllerExposed.java

@RequestMapping("/query")
public HttpEntity<Resources<FooResource>> findList(@Input(include = { "offset", "size" }) Pageable pageable,
        @RequestParam(required = false) Integer foo1, @RequestParam(required = false) Integer foo2) {

    FooResource fooResource = new FooResource(pageable);
    fooResource.add(//from w w  w.j a v a  2 s  . co  m
            AffordanceBuilder.linkTo(methodOn(this.getClass()).findList(null, null, null)).withRel("template"));

    return new HttpEntity<Resources<FooResource>>(
            new Resources<FooResource>(Collections.singleton(fooResource)));

}