Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Newb Problem - ConnectInterceptor pre/postConnect not being called

  1. #1
    Join Date
    Mar 2012
    Posts
    9

    Default Newb Problem - ConnectInterceptor pre/postConnect not being called

    I've got the follow class, pretty much chapter and book from the Spring Social how-to's. Anyhow, I create a Facebook connection - all goes well, the db records are created, etc. However, the connect interceptor pre and post connect methods don't seem to fire as indicated either by print/logging statements or by debug breakpoints. Our spring core is 3.1.

    Any help on this would be appreciated. It is such a simple scenario, I'm completely baffled at the moment.

    Code:
    @Configuration
    public class SocialConfig {
    	@Value("${facebook.clientId}")
    	private String facebookClientId;
    	
    	@Value("${facebook.clientSecret}")
    	private String facebookClientSecret;
    
        @Inject
        private DataSource dataSource;
    
        @Inject
        private TextEncryptor textEncryptor;
    	
    	@Bean
        public ConnectionFactoryLocator connectionFactoryLocator() {
            ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
            registry.addConnectionFactory(new FacebookConnectionFactory(facebookClientId,facebookClientSecret));
            return registry;
        }
    	
        @Bean
        @Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)
        public ConnectionRepository connectionRepository(){
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            if (authentication == null) {
                throw new IllegalStateException("Unable to get a ConnectionRepository: no user signed in");
            }
            return usersConnectionRepository().createConnectionRepository(authentication.getName());
        }
    
        @Bean
        public UsersConnectionRepository usersConnectionRepository() {
            return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator(), 
                textEncryptor);
        }
    
        @Bean
        public ConnectController connectController() {
        	System.out.println("creating connectController bean ");
            ConnectController controller = new ConnectController(connectionFactoryLocator(), 
                connectionRepository());
            //controller.setApplicationUrl("http://localhost:8080/sigkat/");
            controller.addInterceptor(new FacebookConnectInterceptor());
            return controller;
        }
        
        protected static class FacebookConnectInterceptor implements ConnectInterceptor<Facebook>{
    
    		@Override
    		public void postConnect(Connection<Facebook> arg0, WebRequest arg1) {
    			System.out.println("FacebookConnectInterceptor.postConnect webrequest="+arg1);			
    		}
    
    		@Override
    		public void preConnect(ConnectionFactory<Facebook> arg0,
    				MultiValueMap<String, String> arg1, WebRequest arg2) {
    			System.out.println("FacebookConnectInterceptor.preConnect MultiValueMap="+arg1);	
    		}	
        }
    }

  2. #2
    Join Date
    Mar 2012
    Posts
    9

    Default

    So I've been debugging through this. The addInterceptor method seems to be satisfactorily adding the FacebookConnectionInterceptor to the ConnectController, but the preConnect method on ConnectController fails to find the interceptor in this block of code from ConnectController:

    Code:
    	private List<ConnectInterceptor<?>> interceptingConnectionsTo(ConnectionFactory<?> connectionFactory) {
    		Class<?> serviceType = GenericTypeResolver.resolveTypeArgument(connectionFactory.getClass(), ConnectionFactory.class);
    		List<ConnectInterceptor<?>> typedInterceptors = interceptors.get(serviceType);
    		if (typedInterceptors == null) {
    			typedInterceptors = Collections.emptyList();
    		}
    		return typedInterceptors;
    	}
    The serviceType is correctly being found as org.springframework.social.facebook.api.Facebook and on the addInterceptors, this is the key that is being used to put the interceptor into the ConnectController.interceptors map, so now I'm really stymied.

  3. #3

    Default

    I have been playing the showcase sample lately. The Facebook interceptor doesn't seem working while the twitter's one does.
    [URL="http://vicina.info"] 新闻,社区新闻,分类广告

  4. #4
    Join Date
    Mar 2012
    Posts
    9

    Default

    Well, I'm still stepping through code here. On starting the server, the FacebookConnectInterceptor gets added to the ConnectController.interceptors LinkedMultiValueMap map, but then when it comes to preConnect time, this map is empty.

  5. #5
    Join Date
    Aug 2004
    Posts
    1,069

    Default

    I did some quick testing with Spring Social Showcase this morning and confirmed that both the Twitter and Facebook interceptors are being called as they should be. This leaves me confused as to why they wouldn't work for you guys. I think you may be encountering separate issues here...

    vw729: You say it works for Twitter, but not for Facebook. That tells me that the connect interceptor code is working, but that there's probably an error of some sort while posting to Facebook. The interceptors in the showcase are designed to fail silently because it's more important that the connection be made successfully than for the message to be posted post-connect. My guess is that Facebook's giving an error of some sort and it's just being ignored. You can test this theory by putting some logging/System.out.println() messages in each of the interceptor's catch blocks.

    robatsu: Your problem seems more serious. Why would the map of interceptors be cleared out by the time you get to the preConnect()? I'll look closer at your config, but is there anything else you can tell me about your app that might be unique? (For example, are you deploying it to Google App Engine?)
    Craig Walls
    Spring Social Project Lead

  6. #6

    Default

    Sorry, the facebook interceptor is running. I messed up the usage.
    Last edited by vw729; Mar 15th, 2012 at 12:33 PM.
    [URL="http://vicina.info"] 新闻,社区新闻,分类广告

  7. #7

    Default

    Hi,

    I have the same problem that the Interceptor#preConnect and postConnect method isn't invoked.
    My configuration:

    HTML Code:
    <bean class="org.springframework.social.connect.web.ConnectController">
                <constructor-arg ref="connectionFactoryLocator" />
                <constructor-arg ref="connectionRepository" />
              <!--  <property name="applicationUrl" value="http://localhost:8080/JSPTest/home.htm" />-->
                <property name="interceptors">
                    <list>
                        <bean class="package.name.to.interceptor.MyTwitterConnectInterceptor" />
                    </list>
                </property>
            </bean>
    and my interceptor:

    Code:
    import org.springframework.social.connect.Connection;
    import org.springframework.social.connect.ConnectionFactory;
    import org.springframework.social.connect.web.ConnectInterceptor;
    import org.springframework.util.MultiValueMap;
    import org.springframework.web.context.request.WebRequest;
    
    public class MyTwitterConnectInterceptor implements ConnectInterceptor {
    
        public MyTwitterConnectInterceptor() {
            System.out.println("لللللللللللللللللللللللللللل Object of TCI");
            }
    
        @Override
        public void preConnect(ConnectionFactory cf, MultiValueMap mvm, WebRequest wr) {
            System.out.println("----------------- preConnect");
        }
    
        @Override
        public void postConnect(Connection cnctn, WebRequest wr) {
            System.out.println("للللللللللللللللللللللللللللل postConnect");
        }
    }
    The constructor of MyTwitterConnectInterceptor is invoked - therefore an interceptor- object exists but the both methods arn't invoked.
    Does anybody know what I'am doing wrong?

    Thanks a lot,
    Generic

  8. #8
    Join Date
    Oct 2011
    Location
    London, UK
    Posts
    27

    Default

    Hi

    Taking a look at the code you've posted, it doesn't look as if you are passing in the Twitter API type to the ConnectInterceptor interface - as I understand it you need to have:

    MyTwitterConnectInterceptor implements ConnectInterceptor<Twitter>

    That way the ConnectController can determine this is an interceptor for Twitter connections.

    Hope this helps,

    Michael

  9. #9
    Join Date
    Aug 2004
    Posts
    1,069

    Default

    I was about to answer exactly what Michael said. A connection interceptor is associated with a given kind of connection (e.g., Twitter, Facebook, LinkedIn, etc) and so you must parameterize the interceptor when you implement ConnectInterceptor to let it know which kind of connection that the interceptor should be applied for.
    Craig Walls
    Spring Social Project Lead

  10. #10

    Default

    I have a same problem. My preconnect and postconnect method isn't invoked. My interceptor is parameterized.
    Code:
    @Bean
    	public ConnectController connectController() {
    		ConnectController connectController = new ConnectController(
    				connectionFactoryLocator(), connectionRepository());
    		System.out.println("In Connect Controller");
    		connectController.addInterceptor(new
    		PostToWallAfterConnectInterceptor());
    		return connectController;
    	}
    Code:
    public class PostToWallAfterConnectInterceptor implements ConnectInterceptor<Facebook> {
    	
    	public PostToWallAfterConnectInterceptor(){
    		System.out.println("In Interceptor constr");
    	}
    
    	@Override
    	public void postConnect(Connection<Facebook> arg0, WebRequest arg1) {
    		// TODO Auto-generated method stub
    		System.out.println("In Interceptor pre");
    	}
    
    	@Override
    	public void preConnect(ConnectionFactory<Facebook> arg0,
    			MultiValueMap<String, String> arg1, WebRequest arg2) {
    		// TODO Auto-generated method stub
    		System.out.println("In Interceptor post");
    	}
    
    	
    }
    But the constructor is being invoked. Please help

Posting Permissions

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