Announcement Announcement Module
No announcement yet.
RestTemplate.setInterceptor NoSuchMethodError Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • RestTemplate.setInterceptor NoSuchMethodError

    I setup an an android app using Spring Mobile and Spring Android 1.0.0.M2 according to the instructions on the respective pages. These libraries are being managed by Maven, so they should be pulling the correct versions listed above.

    However, when I execute my code (no compile time errors) I get a runtime error

    03-04 16:22:09.036: ERROR/AndroidRuntime(6206): FATAL EXCEPTION: main
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206): java.lang.NoSuchMethodError: org.springframework.web.client.RestTemplate.setInterceptors
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at<init>(
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at org.openschedule.util.TwitterPrefs.getTwitterTemplate(
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at org.openschedule.activities.twitter.TwitterActivity.postTweet(
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at org.openschedule.activities.twitter.TwitterActivity.onCreate(
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at$2500(
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at$H.handleMessage(
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at android.os.Handler.dispatchMessage(
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at android.os.Looper.loop(
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at java.lang.reflect.Method.invokeNative(Native Method)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at java.lang.reflect.Method.invoke(
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at$
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at dalvik.system.NativeStart.main(Native Method)
    I have verified that the RestTemplate code does not contain this method.

    It is being called from eClientFactory
    	public static RestTemplate create(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) {
    		RestTemplate client = new RestTemplate();
    		if (interceptorsSupported) {
    			// favored
    			client.setInterceptors(new ClientHttpRequestInterceptor[] { new OAuth1RequestInterceptor(consumerKey, consumerSecret, accessToken, accessTokenSecret)});   // HERE IS THE CODE BEING CALLED.
    		} else {
    			// 3.0.x compatibility
    			client.setRequestFactory(new Spring30OAuth1RequestFactory(client.getRequestFactory(), consumerKey, consumerSecret, accessToken, accessTokenSecret));
    		return client;
    Thanks for any help.

  • #2
    Looks like this was an error with my maven config. I was able to get this working by explicitly including the spring-web library in the maven dependencies. It was in as a compile-time dependency from spring-mobile and spring-android, however, it looks like its needed at runtime as well.

    FYI for anyone else running into this issue.


    • #3
      @dmfrey The setInterceptors method is part of the Spring Framework 3.1.0.M1 release that was recently announced. Spring Social includes support for this new functionality, which is why it's trying to call that method. You don't want to include the full Spring Web in your pom for an Android app, because Spring Android contains somewhat of a subset of the Rest Template functionality from Spring Web.

      I'm currently working on the next milestone release for Spring Android that will include support for Spring Social. If you are feeling adventurous, you can try out the latest build snapshot. It includes an updated Rest Template, and a new spring-android-auth library. The Auth library has an SqliteConnectionRepository for use with Spring Social on an Android device. All of this will be documented within the next release. Watch for the release soon. Thanks!


      • #4
        Spring Android Auth

        What are some of the details of the spring-android-auth library?


        • #5

          Thanks for the update. If I get a chance, I will take a look at the snapshot. I am really looking forward to seeing the sqllite integration for managing these auths.

          I agree, though, including the full spring-web module is not the most appropriate solution.

          I really like how spring-android is progressing.


          • #6
            @dutchman_mn With the next milestone it is simply going to include Spring Social support. The library has a transitive dependency (excluding spring-web) on spring-social-core, so you'll get all the oauth functionality from that. We needed a new library for the sqlite connector, since that doesn't go in Rest Template. We're discussing future plans for what to include in Auth. Feedback is always appreciated!


            • #7
              Spring Android Auth

              In my case, I am working on Android apps that extend enterprise functionality to the smartphone. So I am not looking for a social media security solution but more of a security solution that plays well with the current state of what my clients currently have. How do you see your OAuth implementation working in that scenario?


              • #8

                Take a look at the Greenhouse app. It sets up Oauth in Spring Security at the web app level and the android app uses Oauth to authenticate to the server. Once it has exchanged keys, the android app is essentially authenticated.


                • #9
                  Re: Spring Android Auth

                  No, I know how OAuth works and have played with it a bit. My question is, for the developer connecting an Android app to some enterprise service, what does OAuth give you over what I currently have now?


                  • #10
                    @dutchman_mn outside of OAuth, there are several different technologies used in the enterprise. We are discussing which ones to address and how to address them in Android. Take a look at this flow diagram from Google. It's a good example of how some of these technologies might overlap and interact.


                    Certainly, if you have a particular use case, we can create a story for it.