Results 1 to 2 of 2

Thread: Can't find HttpClient?

  1. #1
    Join Date
    Jul 2012
    Posts
    2

    Default Can't find HttpClient?

    I am trying to use the latest Spring for Android 1.0.1 with a simple get:
    Code:
    RestTemplate restTemplate = new RestTemplate();
    	    restTemplate.setRequestFactory(new CommonsClientHttpRequestFactory());
    	    String url = "http://localhost:8090//rest/all";
    	    Mine m = restTemplate(getForObject(url, Mine.class);
    This results in a crash:
    Code:
    03-06 11:17:07.490: E/AndroidRuntime(544): FATAL EXCEPTION: main
    03-06 11:17:07.490: E/AndroidRuntime(544): java.lang.NoClassDefFoundError: org.apache.commons.httpclient.HttpClient
    03-06 11:17:07.490: E/AndroidRuntime(544): 	at org.springframework.http.client.CommonsClientHttpRequestFactory.<init>(CommonsClientHttpRequestFactory.java:63)
    Since it says HttpClient is missing, I downloaded httpcomponents-client-4.2.3 and added the seven jars to my project. I still get the same error.

    How do I get past this HttpClient error?

  2. #2
    Join Date
    Nov 2010
    Posts
    174

    Default

    Hi, httpcomponents-client-4.2.3 is not compatible with RestTemplate in Spring for Android. The CommonsClientHttpRequestFactory is for use with the Commons HttpClient 3.1. Support for this is deprecated in Spring for Android, in favor of one of the native Android HTTP clients.

    Spring for Android automatically uses the SimpleClientHttpRequestFactory (Gingerbread and newer) unless you specify a different factory as you are doing. I recommend trying to use RestTemplate without specifying one, unless you have a reason to.
    Roy Clarkson
    Spring Mobile Projects Lead

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •