Announcement Announcement Module
Collapse
No announcement yet.
SpringSocial LinkedIn - setInterceptors() noSuchMethod Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SpringSocial LinkedIn - setInterceptors() noSuchMethod

    Hi,

    I have been trying to integrate SpringSocial and LinkedIn with my webapp and I am having problems with the following exception:

    Code:
    org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.springframework.web.client.RestTemplate.setInterceptors([Lorg/springframework/http/client/ClientHttpRequestInterceptor;)V
    ...
    Caused by: java.lang.NoSuchMethodError: org.springframework.web.client.RestTemplate.setInterceptors([Lorg/springframework/http/client/ClientHttpRequestInterceptor;)V
        at org.springframework.social.oauth1.ProtectedResourceClientFactory.create(ProtectedResourceClientFactory.java:51)
        at org.springframework.social.oauth1.AbstractOAuth1ApiBinding.<init>(AbstractOAuth1ApiBinding.java:59)
        at org.springframework.social.linkedin.api.impl.LinkedInTemplate.<init>(LinkedInTemplate.java:65)
        at org.springframework.social.linkedin.connect.LinkedInServiceProvider.getApi(LinkedInServiceProvider.java:38)
        at org.springframework.social.linkedin.connect.LinkedInServiceProvider.getApi(LinkedInServiceProvider.java:27)
        at org.springframework.social.connect.support.OAuth1Connection.initApi(OAuth1Connection.java:94)
        ...
    I have a form on my page that makes a POST call to /connect/linkedin and the user gets correctly directed to LinkedIn for authorisation, but on being directed back to my application I get the above exception.


    I also posted the error on SO, and it was suggested that it was a class conflict, but I have gone through my POM (and the included libraries in Eclipse) and the only version of the RestTemplate and InterceptingHttpAccessor classes are from the 3.1.1 spring-web library and having checked the source they have the setInterceptor() method included.

    Anyone experienced similar issues or got any ideas what might be wrong?

    Cheers

  • #2
    The one and only time I've seen this error before was when there was, in fact, an older version of RestTemplate being pulled in that does not have the setInterceptors(). You say you have gone through and confirmed that there isn't, so I can't argue with what you see...but the error indicates that RestTemplate does not have setInterceptors() and if you're using Spring 3.1.x, it will have that method.

    Dependency management is a tricky business and with Maven and Eclipse it's easy to get a transitive dependency on some older version of Spring in play and it not be obvious where it is or how it got there (believe me, I've felt this frustration before). I have no advice other than to go through again, especially in the place where it is being executed (e.g., in Eclipse if that's where you're running this) and double verify it. One thing that has helped me before is to write a method somewhere in the same project that references RestTemplate and then F3 navigate to it. If you have the "Link with Editor" button enabled, it will show you the RestTemplate that it thinks is there in the Package Explorer...verify that it's the 3.1.x version you think it is.

    Comment


    • #3
      Thanks - It is a pain trying to manage transitive dependencies with Eclipse. I am using the M2Eclipse plugin, and have viewed the dependency heirarchy and confirmed that it is only the 3.1.1 version that is being pulled down (having gone through and excluded a whole bunch of other transitive dependencies that other libraries had on earlier Spring-web versions).

      Further to this, I have user ctrl+shift+t(open type shortcut in eclipse) and entered both RestTemplate and the interceptor and only one instance of the class shows up for each, and having opened them they display the method in question and also when I turn on the eclipse "jump to resource" option, it leads me to the 3.1.1 library

      sure it must be some eclipse madness, but not sure what..

      Comment


      • #4
        something strange is definitely happening..

        I just added the following code to an arbitrary part of a controller method that is invoked on loading the home page:

        RestTemplate restTemplate = new RestTemplate();
        List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
        restTemplate.setInterceptors(interceptors);

        And no error (and yes, I confirmed that the code was definitely being executed).. then go on to connect to LinkedIn and get the above error..


        Comment


        • #5
          So with this new code, you get no error in Eclipse (indicating that it finds the setInterceptors() method), but you do get the error at runtime?

          Sounds like (for some reason) your runtime dependencies aren't matching your dev/compile-time dependencies. I can't say why. You might try doing a Project->Clean in Eclipse...sometimes that sorts out this kind of problem.

          Comment


          • #6
            the new test code i inserted above both compiles in Eclipse and executes no problem at runtime.. its only once the LinkedInTemplate attempts to call the setInterceptors() method that it throws the exception!!

            Comment


            • #7
              Ok, I think I have found the problem. The stack trace states the cause is:

              Code:
              Caused by: java.lang.NoSuchMethodError: org.springframework.web.client.RestTemplate.setInterceptors([Lorg/springframework/http/client/ClientHttpRequestInterceptor;)V
              	at org.springframework.social.oauth1.ProtectedResourceClientFactory.create(ProtectedResourceClientFactory.java:51)
              	at org.springframework.social.oauth1.AbstractOAuth1ApiBinding.<init>(AbstractOAuth1ApiBinding.java:59)
              	at org.springframework.social.linkedin.api.impl.LinkedInTemplate.<init>(LinkedInTemplate.java:66)
              	at org.springframework.social.linkedin.connect.LinkedInServiceProvider.getApi(LinkedInServiceProvider.java:38)
              So looking at the calling code in bold (ProtectedResourceClientFactory.create()) it is as follows:

              Code:
              public static RestTemplate create(OAuth1Credentials credentials) {
              		RestTemplate client = new RestTemplate(ClientHttpRequestFactorySelector.getRequestFactory());
              		if (interceptorsSupported) {
              			// favored
              			client.setInterceptors(new ClientHttpRequestInterceptor[] { new OAuth1RequestInterceptor(credentials)});
              		}
              The problem is that the setInterceptors() method in the RestTemplate in Spring-Web-3.1.1 is expecting a List<ClientHttpRequestInterceptor> not an array (so the problem isnt that it cant find the method, but rather the signature is different).


              The ProtectedResourceClientFactory is part of the Spring-Social-Core project, and I am currently using version 1.0.0.RC3 of Spring-Social-Core - is there a more recent version of the project I should be using to align this? This is the latest i can see in this mvn repo: http://maven.springframework.org/milestone/ (is there a better maven repo that I can use for the social stuff?)



              Thanks for the help!

              Comment


              • #8
                Ok, have just seen there are more recent builds (if i dont just stick to milestone releases) which have this resolved..

                should i use the 1.1.0.BUILD-SNAPSHOT?

                (also is this the best repository?)

                Comment


                • #9
                  Certainly, 1.0.0.RC3 is quite old and you should be using something newer. The 1.1.0.BUILD-SNAPSHOT is currently stable as far as I know...but it is a snapshot, so that could change (that's the nature of the snapshot). For a more stable build, I recommend that you use 1.0.2.RELEASE...it doesn't have any of the latest and greatest work in it, but I can promise that it doesn't run the risk of breaking after a nightly build is performed.

                  Comment


                  • #10
                    Perfect, that got past that problem. Thanks.

                    Comment

                    Working...
                    X