通过Spring Social获取完整的Linkedin Profile时出现400错误请求错误

时间:2015-03-08 17:32:35

标签: java spring linkedin spring-social spring-social-linkedin

我正在使用Spring Social通过LinkedIn登录用户。当我访问LinkedInUserProfile它工作正常,但当我尝试访问完整的配置文件时,我得到以下异常。因此下面代码中的第2行工作正常,但第3行抛出异常

LinkedIn linkedinApi = (LinkedIn) connection.getApi();
LinkedInProfile linkedinProfile = linkedinApi.profileOperations().getUserProfile();
LinkedInProfileFull linkedinProfileFull = linkedinApi.profileOperations().getUserProfileFull();

结论是

[ERROR] 2015-03-08 08:55:06.124 [http-nio-8443-exec-2] ProviderSignInController - Exception while completing OAuth 2 connection: 
org.springframework.social.UncategorizedApiException: 
    at org.springframework.social.linkedin.api.impl.LinkedInErrorHandler.handleUncategorizedError(LinkedInErrorHandler.java:62) ~[spring-social-linkedin-1.0.1.RELEASE.jar:1.0.1.RELEASE]
    at org.springframework.social.linkedin.api.impl.LinkedInErrorHandler.handleError(LinkedInErrorHandler.java:55) ~[spring-social-linkedin-1.0.1.RELEASE.jar:1.0.1.RELEASE]
    at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:588) ~[spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:546) ~[spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:517) ~[spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:255) ~[spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.social.linkedin.api.impl.ProfileTemplate.getProfileFullById(ProfileTemplate.java:127) ~[spring-social-linkedin-1.0.1.RELEASE.jar:1.0.1.RELEASE]
    at org.springframework.social.linkedin.api.impl.ProfileTemplate.getProfileFullById(ProfileTemplate.java:104) ~[spring-social-linkedin-1.0.1.RELEASE.jar:1.0.1.RELEASE]
    at com.icanrecruit.social.security.AccountConnectionSignUp.execute(AccountConnectionSignUp.java:39) ~[AccountConnectionSignUp.class:?]
    at org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository.findUserIdsWithConnection(JdbcUsersConnectionRepository.java:86) ~[spring-social-core-1.1.0.RELEASE.jar:1.1.0.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_65]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_65]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at com.sun.proxy.$Proxy29.findUserIdsWithConnection(Unknown Source) ~[?:?]
    at org.springframework.social.connect.web.ProviderSignInController.handleSignIn(ProviderSignInController.java:260) ~[spring-social-web-1.1.0.RELEASE.jar:1.1.0.RELEASE]
    at org.springframework.social.connect.web.ProviderSignInController.oauth2Callback(ProviderSignInController.java:217) [spring-social-web-1.1.0.RELEASE.jar:1.1.0.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_65]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_65]
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) [spring-webmvc-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) [spring-webmvc-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690) [spring-webmvc-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) [spring-webmvc-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945) [spring-webmvc-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876) [spring-webmvc-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) [spring-webmvc-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) [spring-webmvc-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) [servlet-api.jar:?]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) [spring-webmvc-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) [servlet-api.jar:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.17]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.17]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.17]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.17]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.17]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at com.icanrecruit.security.api.TokenAuthenticationFilter.doFilter(TokenAuthenticationFilter.java:53) [TokenAuthenticationFilter.class:?]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.17]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.17]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) [catalina.jar:8.0.17]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.17]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:613) [catalina.jar:8.0.17]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [catalina.jar:8.0.17]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.17]
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) [catalina.jar:8.0.17]
    at org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:504) [catalina.jar:8.0.17]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.17]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516) [catalina.jar:8.0.17]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086) [tomcat-coyote.jar:8.0.17]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659) [tomcat-coyote.jar:8.0.17]
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) [tomcat-coyote.jar:8.0.17]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558) [tomcat-coyote.jar:8.0.17]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515) [tomcat-coyote.jar:8.0.17]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_65]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_65]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.17]
    at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
Caused by: org.springframework.web.client.HttpClientErrorException: 400 Bad Request
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91) ~[spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
    at org.springframework.social.linkedin.api.impl.LinkedInErrorHandler.handleUncategorizedError(LinkedInErrorHandler.java:60) ~[spring-social-linkedin-1.0.1.RELEASE.jar:1.0.1.RELEASE]
    ... 88 more

当我调试时,日志如下,因此“ı”字符存在问题,因此它可能与本地化有关。谁知道这里发生了什么?

[DEBUG] 2015-03-08 08:55:05.971 [http-nio-8443-exec-2] RestTemplate - Created GET request for "https://api.linkedin.com/v1/people/id=vOp_9S25si:(ıd,fırst-name,last-name,headlıne,locatıon,ındustry,dıstance,relatıon-to-vıewer,current-share,num-connectıons,num-connectıons-capped,summary,specıaltıes,proposal-comments,assocıatıons,honors,ınterests,posıtıons,publıcatıons,patents,languages,skılls,certıfıcatıons,educatıons,three-current-posıtıons,three-past-posıtıons,num-recommenders,recommendatıons-receıved,phone-numbers,ım-accounts,twıtter-accounts,date-of-bırth,maın-address,member-url-resources,pıcture-url,site-standard-profile-request:(url),api-public-profile-request:(url),site-public-profile-request:(url),apı-standard-profıle-request,publıc-profıle-url,emaıl-address)?format=json"

1 个答案:

答案 0 :(得分:1)

对于那些面对类似事物的人,从我追踪的例外情况到ProfileTemplate.java的代码

https://github.com/spring-projects/spring-social-linkedin/blob/master/spring-social-linkedin/src/main/java/org/springframework/social/linkedin/api/impl/ProfileTemplate.java

使用ProfileField.values()

public enum ProfileField {
    ID,
    FIRST_NAME,
    LAST_NAME,
    HEADLINE,
    LOCATION,
    INDUSTRY,
    DISTANCE,
    RELATION_TO_VIEWER,
    CURRENT_SHARE,
    CONNECTIONS,
    NUM_CONNECTIONS,
    NUM_CONNECTIONS_CAPPED,
    SUMMARY,
    SPECIALTIES,
    PROPOSAL_COMMENTS,
    ASSOCIATIONS,
    HONORS,
    INTERESTS,
    POSITIONS,
    PUBLICATIONS,
    PATENTS,
    LANGUAGES,
    SKILLS,
    CERTIFICATIONS,
    EDUCATIONS,
    THREE_CURRENT_POSITIONS,
    THREE_PAST_POSITIONS,
    NUM_RECOMMENDERS,
    RECOMMENDATIONS_RECEIVED,
    PHONE_NUMBERS,
    IM_ACCOUNTS,
    TWITTER_ACCOUNTS,
    DATE_OF_BIRTH,
    MAIN_ADDRESS,
    MEMBER_URL_RESOURCES,
    PICTURE_URL,
    SITE_STANDARD_PROFILE_REQUEST_URL,
    API_PUBLIC_PROFILE_REQUEST_URL,
    SITE_PUBLIC_PROFILE_REQUEST_URL,
    API_STANDARD_PROFILE_REQUEST,
    PUBLIC_PROFILE_URL,
    EMAIL_ADDRESS
    ;

    public String toString() {
        switch (this) {
        case SITE_STANDARD_PROFILE_REQUEST_URL:
            return "site-standard-profile-request:(url)";
        case API_PUBLIC_PROFILE_REQUEST_URL:
            return "api-public-profile-request:(url)";
        case SITE_PUBLIC_PROFILE_REQUEST_URL:
            return "site-public-profile-request:(url)";
        default:
            return this.name().toLowerCase().replace('_', '-');
        }
    }

}

都是大写字母,当它们转为小写时,它使用的系统区域设置未被设置为" en",导致无效请求。当我改变系统本地时,问题就解决了。现在我可以使用" en" locale,如果我稍后需要更改它,这需要以不同的方式解决。