Results 1 to 10 of 13

Thread: Spring Social Linkedin Connection: 400 Bad Request

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Location
    Dhaka, Bangladesh
    Posts
    13

    Default Spring Social Linkedin Connection: 400 Bad Request

    I have connected to facebook and twitter using spring social (spring-social-showcase demo) and it working as very nice. Now I am trying to integrate linkedin api into it.

    The pom.xml file is shown bellow.

    <properties>
    <org.springframework.social.linkedin-version>1.0.0.BUILD-SNAPSHOT</org.springframework.social.linkedin-version>
    </properties>

    <dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-linkedin</artifactId><version>${org.springframework.social.l inkedin-version}</version>
    </dependency>


    SocialConfig file is shown bellow.

    @Bean
    @Scope(value="singleton", proxyMode=ScopedProxyMode.INTERFACES)
    public ConnectionFactoryLocator connectionFactoryLocator() {
    ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();

    registry.addConnectionFactory(new LinkedInConnectionFactory(environment.getProperty( "linkedin.apikey"),
    environment.getProperty("linkedin.secretkey")));
    return registry;
    }

    @Bean
    @Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)
    public LinkedIn linkedin() {
    Connection<LinkedIn> linkedin = connectionRepository().findPrimaryConnection(Linke dIn.class);
    return linkedin != null ? linkedin.getApi() : null;
    }


    And application.properties file is shown bellow
    #Linkedin properties
    linkedin.apikey=#########
    linkedin.secretkey=####################

    When I try to connect linkedin using the <form action="<c:url value="/connect/linkedin" />" method="POST"> then it generates the following error

    org.springframework.web.client.HttpClientErrorExce ption: 400 Bad Request
    org.springframework.web.client.DefaultResponseErro rHandler.handleError(DefaultResponseErrorHandler.j ava:75)
    org.springframework.web.client.RestTemplate.handle ResponseError(RestTemplate.java:486)
    org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:443)
    org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:415)
    org.springframework.web.client.RestTemplate.exchan ge(RestTemplate.java:391)
    org.springframework.social.oauth1.OAuth1Template.e xchangeForToken(OAuth1Template.java:194)
    org.springframework.social.oauth1.OAuth1Template.f etchRequestToken(OAuth1Template.java:116)
    org.springframework.social.connect.web.ConnectSupp ort.fetchRequestToken(ConnectSupport.java:143)
    org.springframework.social.connect.web.ConnectSupp ort.buildOAuth1Url(ConnectSupport.java:136)
    org.springframework.social.connect.web.ConnectSupp ort.buildOAuthUrl(ConnectSupport.java:95)
    org.springframework.social.connect.web.ConnectCont roller.connect(ConnectController.java:161)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)

    I want to connect linkedin like twitter. Please help.

  2. #2
    Join Date
    Aug 2004
    Posts
    1,067

    Default

    Looking at your pasted code, I see nothing obvious that would cause the problem, but I'm leaning toward it being a case of an incorrect consumer key or secret. It's hard to say for sure.

    But, to help out, I've added LinkedIn functionality to the Spring Social Showcase in a "linkedin" branch at https://github.com/SpringSource/spri.../tree/linkedin. I put it in a separate branch so that the main branch wouldn't depend upon the unreleased LinkedIn module. I ran it through the normal paces of testing the showcase and it worked fine with LinkedIn.

    Have a look. And let us know if you figure out what wasn't working for you...it'd be good to know for future reference.
    Craig Walls
    Spring Social Project Lead

  3. #3
    Join Date
    Oct 2011
    Location
    Dhaka, Bangladesh
    Posts
    13

    Default

    I downloaded the new code you given. I run it, twitter and facebook is okay but linkedin is not working. The error is same. The error is given bellow.

    HTTP Status 500 -

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.springframework.web.util.NestedServletExceptio n: Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorExce ption: 400 Bad Request
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:886)
    org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:790)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.springframework.web.filter.HiddenHttpMethodFil ter.doFilterInternal(HiddenHttpMethodFilter.java:7 7)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 312)
    org.springframework.security.web.access.intercept. FilterSecurityInterceptor.invoke(FilterSecurityInt erceptor.java:116)
    org.springframework.security.web.access.intercept. FilterSecurityInterceptor.doFilter(FilterSecurityI nterceptor.java:83)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.access.ExceptionT ranslationFilter.doFilter(ExceptionTranslationFilt er.java:113)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.session.SessionMa nagementFilter.doFilter(SessionManagementFilter.ja va:101)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.authentication.An onymousAuthenticationFilter.doFilter(AnonymousAuth enticationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.servletapi.Securi tyContextHolderAwareRequestFilter.doFilter(Securit yContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.savedrequest.Requ estCacheAwareFilter.doFilter(RequestCacheAwareFilt er.java:45)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.authentication.Ab stractAuthenticationProcessingFilter.doFilter(Abst ractAuthenticationProcessingFilter.java:182)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.authentication.lo gout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.context.SecurityC ontextPersistenceFilter.doFilter(SecurityContextPe rsistenceFilter.java:87)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.FilterChainProxy. doFilter(FilterChainProxy.java:174)
    org.springframework.web.filter.DelegatingFilterPro xy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterPro xy.doFilter(DelegatingFilterProxy.java:259)
    org.springframework.web.filter.CharacterEncodingFi lter.doFilterInternal(CharacterEncodingFilter.java :88)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)

    root cause

    org.springframework.web.client.HttpClientErrorExce ption: 400 Bad Request
    org.springframework.web.client.DefaultResponseErro rHandler.handleError(DefaultResponseErrorHandler.j ava:75)
    org.springframework.web.client.RestTemplate.handle ResponseError(RestTemplate.java:486)
    org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:443)
    org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:415)
    org.springframework.web.client.RestTemplate.exchan ge(RestTemplate.java:391)
    org.springframework.social.oauth1.OAuth1Template.e xchangeForToken(OAuth1Template.java:194)
    org.springframework.social.oauth1.OAuth1Template.f etchRequestToken(OAuth1Template.java:116)
    org.springframework.social.connect.web.ConnectSupp ort.fetchRequestToken(ConnectSupport.java:143)
    org.springframework.social.connect.web.ConnectSupp ort.buildOAuth1Url(ConnectSupport.java:136)
    org.springframework.social.connect.web.ConnectSupp ort.buildOAuthUrl(ConnectSupport.java:95)
    org.springframework.social.connect.web.ConnectCont roller.connect(ConnectController.java:161)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.web.method.support.InvocableHa ndlerMethod.invoke(InvocableHandlerMethod.java:212 )
    org.springframework.web.method.support.InvocableHa ndlerMethod.invokeForRequest(InvocableHandlerMetho d.java:126)
    org.springframework.web.servlet.mvc.method.annotat ion.ServletInvocableHandlerMethod.invokeAndHandle( ServletInvocableHandlerMethod.java:96)
    org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerAdapter.invokeHandlerMeth od(RequestMappingHandlerAdapter.java:629)
    org.springframework.web.servlet.mvc.method.annotat ion.RequestMappingHandlerAdapter.handleInternal(Re questMappingHandlerAdapter.java:590)
    org.springframework.web.servlet.mvc.method.Abstrac tHandlerMethodAdapter.handle(AbstractHandlerMethod Adapter.java:80)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:900)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:827)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:874)
    org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:790)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.springframework.web.filter.HiddenHttpMethodFil ter.doFilterInternal(HiddenHttpMethodFilter.java:7 7)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 312)
    org.springframework.security.web.access.intercept. FilterSecurityInterceptor.invoke(FilterSecurityInt erceptor.java:116)
    org.springframework.security.web.access.intercept. FilterSecurityInterceptor.doFilter(FilterSecurityI nterceptor.java:83)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.access.ExceptionT ranslationFilter.doFilter(ExceptionTranslationFilt er.java:113)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.session.SessionMa nagementFilter.doFilter(SessionManagementFilter.ja va:101)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.authentication.An onymousAuthenticationFilter.doFilter(AnonymousAuth enticationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.servletapi.Securi tyContextHolderAwareRequestFilter.doFilter(Securit yContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.savedrequest.Requ estCacheAwareFilter.doFilter(RequestCacheAwareFilt er.java:45)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.authentication.Ab stractAuthenticationProcessingFilter.doFilter(Abst ractAuthenticationProcessingFilter.java:182)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.authentication.lo gout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.context.SecurityC ontextPersistenceFilter.doFilter(SecurityContextPe rsistenceFilter.java:87)
    org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 324)
    org.springframework.security.web.FilterChainProxy. doFilter(FilterChainProxy.java:174)
    org.springframework.web.filter.DelegatingFilterPro xy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterPro xy.doFilter(DelegatingFilterProxy.java:259)
    org.springframework.web.filter.CharacterEncodingFi lter.doFilterInternal(CharacterEncodingFilter.java :88)
    org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)

    I am waiting for your response.
    Thanks
    Rafiq

  4. #4
    Join Date
    Aug 2004
    Posts
    1,067

    Default

    Honestly, I'm stumped. Assuming you are running the LinkedIn-enabled showcase unchanged after pulling it from GitHub, it *should* just work. It works for me and I've had a few others try it and they've had no trouble connecting to LinkedIn, either. Given that, it seems that the problem isn't in the code, but is probably something environmental on your end. I don't know for sure what it might be.

    Just trying to narrow it down, could you try running the following code (in a main method or JUnit test):

    Code:
    String consumerKey = "8U1nfplbpkkBTIKDcuonVY_gZ_9Pl0UOhbXr6qNIL1ByPz4ZietgM92sR-mMzpTM";
    String consumerSecret = "zFIPCSMPVy9Bg5P1NFhxlTXniXX9pPDBPru2WGZqegYUQHHPTMpAr26vBPbb6iQ6";		
    LinkedInConnectionFactory licf = new LinkedInConnectionFactory(consumerKey, consumerSecret);
    OAuth1Operations oauth = licf.getOAuthOperations();
    OAuthToken requestToken = oauth.fetchRequestToken("http://localhost:8080/spring-social-showcase/connect/linkedin", null);		
    System.out.println(requestToken.getValue() + "  ::  " + requestToken.getSecret());
    I'm not interested in what values are printed, but am interested in whether you get an exception or if you get a request token/secret.
    Last edited by habuma; Nov 28th, 2011 at 09:09 AM.
    Craig Walls
    Spring Social Project Lead

  5. #5
    Join Date
    Oct 2011
    Location
    Dhaka, Bangladesh
    Posts
    13

    Default

    I have got the same error messages in browser. I have also tested this in another pc (sts 2.8.0) but the result is same. I could not get request token/secret.

    Please help me.
    Rafiq
    Last edited by rafiq; Nov 27th, 2011 at 10:23 PM.

  6. #6
    Join Date
    Aug 2004
    Posts
    1,067

    Default

    Rafiq: Are you saying that when running the code snippet that I gave you in a main method or test method you get the same exception and stack trace as you did in the browser? Again, I'm stumped...because that very same chunk of code gives me a request token and secret.

    At this point I'm wondering if it's a matter of dependencies not lining up. Of course, if you've pulled the LinkedIn-enabled Spring Social Showcase that I gave you, then you *should* be running with the same set of dependencies as I am. That is, unless your local Maven repo is holding on to some bad dependencies (shouldn't happen, but I've seen it happen plenty of times). Perhaps you could try moving/renaming your local Maven repo and building/running the LinkedIn-enabled showcase again? No guarantees, but it's worth a shot.
    Craig Walls
    Spring Social Project Lead

Tags for this Thread

Posting Permissions

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