I have read RoboSpice documentation on the product, and I try to compile most of your examples. I found one example which I may partly use. I have further developed it as it fulfills my need, and yet here comes the problem:
When I modify the code to connect it to the local database on my mobile, the problem is that it doesn´t work as I expected. I hope that there are some who are using “RoboSpice” for connecting the JSON Web Service and save it on the data base of the mobile.
The only thing I´ve done is to add the ORM Lite. I don´t know the right way to do it. Below is the code I use for service and for getters and setters.
@DatabaseTable(tableName="Follower")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Follower {
@DatabaseField(id = true)
private String login;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
}
public class FollowerList extends ArrayList<Follower> {
private static final long serialVersionUID = 8192333539004718470L;
}
public class SpiceService extends SpringAndroidSpiceService {
private static final String TAG = "SpiceService";
private static final String DATABASE_NAME = "Github.db";
private static final int DATABASE_VERSION = 1;
private static final int WEBSERVICES_TIMEOUT = 10000;
@Override
public int getThreadCount() {
return 3;
}
@Override
public CacheManager createCacheManager(Application application) throws CacheCreationException {
CacheManager cacheManager = new CacheManager();
try {
List<Class<?>> classCollection = new ArrayList<Class<?>>();
classCollection.add(Follower.class);
RoboSpiceDatabaseHelper databaseHelper = new RoboSpiceDatabaseHelper(application, DATABASE_NAME, DATABASE_VERSION);
InDatabaseObjectPersisterFactory inDatabaseObjectPersisterFactory = new InDatabaseObjectPersisterFactory(application, databaseHelper, classCollection);
cacheManager.addPersister(inDatabaseObjectPersisterFactory);
} catch (Exception ex) {
ex.printStackTrace();
}
return cacheManager;
}
@Override
public RestTemplate createRestTemplate() {
RestTemplate restTemplate = new RestTemplate() {
@Override
protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
ClientHttpRequest request = super.createRequest(url, method);
HttpHeaders headers = request.getHeaders();
headers.setAcceptEncoding(ContentCodingType.IDENTITY);
return request;
}
};
try {
// Bug on http connection for Android < 2.2
// http://android-developers.blogspot.fr/2011/09/androids-http-clients.html
// But still a problem for upload with Spring-android on android 4.1
System.setProperty("http.keepAlive", "false");
// Set timeout for requests
ClientHttpRequestFactory factory = restTemplate.getRequestFactory();
if (factory instanceof HttpComponentsClientHttpRequestFactory) {
// Set timeout for requests
Log.i(TAG, "HttpClient is used");
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
httpRequestFactory.setReadTimeout(WEBSERVICES_TIMEOUT);
httpRequestFactory.setConnectTimeout(WEBSERVICES_TIMEOUT);
} else if (factory instanceof SimpleClientHttpRequestFactory) {
Log.i(TAG, "HttpUrlConnection is used");
SimpleClientHttpRequestFactory httpRequestFactory = (SimpleClientHttpRequestFactory) factory;
httpRequestFactory.setConnectTimeout(WEBSERVICES_TIMEOUT);
httpRequestFactory.setReadTimeout(WEBSERVICES_TIMEOUT);
}
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// Web services support JSON responses
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
FormHttpMessageConverter formHttpMessageConverter = new FormHttpMessageConverter();
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
final List<HttpMessageConverter<?>> listHttpMessageConverters = restTemplate.getMessageConverters();
// Add converter types to list of HttpMessageConverter's (json, form, string)
listHttpMessageConverters.add(jsonConverter);
listHttpMessageConverters.add(formHttpMessageConverter);
listHttpMessageConverters.add(stringHttpMessageConverter);
restTemplate.setMessageConverters(listHttpMessageConverters);
} catch (Exception ex) {
ex.printStackTrace();
}
return restTemplate;
}
}
When I run the program, I get “fault complaints” (error messages) as shown below:
java.lang.RuntimeException: Class dk.test.list.FollowerList is not handled by any registered factoryList
I do hope there are some who can help me solving the problem. I thank the people behind the development of the product and hope to get answers to my questions.
I thank you in beforehand.