Android Open Source - simple-json-android-exercise Simple Rest Client_






From Project

Back to project page simple-json-android-exercise.

License

The source code is released under:

Apache License

If you think the Android project simple-json-android-exercise listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//
// DO NOT EDIT THIS FILE, IT HAS BEEN GENERATED USING AndroidAnnotations.
////from  www  .j  a  v  a  2s .  co m


package com.example.simplejsonapp.rest;

import java.util.HashMap;
import com.example.simplejsonapp.entity.User;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

public class SimpleRestClient_
    implements SimpleRestClient
{

    private RestTemplate restTemplate;
    private String rootUrl;

    public SimpleRestClient_() {
        restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().add(new GsonHttpMessageConverter());
        rootUrl = "http://192.168.0.3:8080";
    }

    @Override
    public User getUserById(String id) {
        HashMap<String, Object> urlVariables = new HashMap<String, Object>();
        urlVariables.put("id", id);
        HttpHeaders httpHeaders = new HttpHeaders();
        HttpEntity<Object> requestEntity = new HttpEntity<Object>(httpHeaders);
        return restTemplate.exchange(rootUrl.concat("/getUser?userId={id}"), HttpMethod.GET, requestEntity, User.class, urlVariables).getBody();
    }

}




Java Source Code List

com.example.simplejsonapp.MainActivity.java
com.example.simplejsonapp.MainActivity_.java
com.example.simplejsonapp.entity.User.java
com.example.simplejsonapp.rest.SimpleRestClient.java
com.example.simplejsonapp.rest.SimpleRestClient_.java