Announcement Announcement Module
Collapse
No announcement yet.
RestTemplate.setInterceptor NoSuchMethodError Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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

    Code:
    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 org.springframework.social.oauth1.ProtectedResourceClientFactory.create(ProtectedResourceClientFactory.java:37)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at org.springframework.social.twitter.TwitterTemplate.<init>(TwitterTemplate.java:84)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at org.openschedule.util.TwitterPrefs.getTwitterTemplate(TwitterPrefs.java:131)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at org.openschedule.activities.twitter.TwitterActivity.postTweet(TwitterActivity.java:173)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at org.openschedule.activities.twitter.TwitterActivity.onCreate(TwitterActivity.java:74)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at android.app.ActivityThread.access$2500(ActivityThread.java:129)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at android.os.Handler.dispatchMessage(Handler.java:99)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at android.os.Looper.loop(Looper.java:143)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at android.app.ActivityThread.main(ActivityThread.java:4701)
    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(Method.java:521)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    03-04 16:22:09.036: ERROR/AndroidRuntime(6206):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    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 org.springframework.social.oauth1.ProtectedResourc eClientFactory
    Code:
    	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.

    Comment


    • #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!

      Comment


      • #4
        Spring Android Auth

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

        Comment


        • #5
          @rclarkson.

          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.

          Comment


          • #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!

            Comment


            • #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?

              Comment


              • #8
                @dutchman_mn,

                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.

                Comment


                • #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?

                  Comment


                  • #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.

                    http://sites.google.com/site/oauthgoog/Overlap

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

                    Comment

                    Working...
                    X