Hi, guys.
I'm use Spring 3.2.0 + MVC + WebFlow + Security + Spring MongoDb. All works fine, until I'm doing integration spring-social-canvas code example into project.
I'm trying to integrate spring-social into web app for using as canvas app.
There are two questions I have but I'll start with first one.
1.
'spring-social-canvas' example https://github.com/SpringSource/spri...ki/Quick-Start
uses code with JDBC access
I'm using mongodb as backend.Code:@Bean public UsersConnectionRepository usersConnectionRepository() { JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator(), Encryptors.noOpText()); repository.setConnectionSignUp(new SimpleConnectionSignUp()); .....
Application consists of two modules: 'common jar module' and 'web-app module'.
Mongo config, repositories, services are in 'common-module'. EXCEPT TWO REPOSITORY classes !!
Controllers. Interceptors and other web stuff are in 'web-module'.
I created 'UserConnection' entity for mongodb and made replacement implementations for classes:
public class JdbcUsersConnectionRepository implements UsersConnectionRepository {..... {
class JdbcConnectionRepository implements ConnectionRepository {.....
they both are used for managing 'UserConnection' entity by JDBC stuff.
So I have made two replacement classes below.
I put them inside WEB module as I thought it will help me to work out problem, but that didn't help. So they are still in WEB-add module. I hope that doesn't matter for now.
Because of implementing them for mongodb as below:Code:package com.web.repository; public interface UserConnectionRepository extends UsersConnectionRepository { // empty interface } package com.web.repository; public class UserConnectionRepositoryImpl extends SimpleMongoRepository<UserConnection, ObjectId> implements UserConnectionRepository { private ConnectionFactoryLocator connectionFactoryLocator = null; private TextEncryptor textEncryptor = null; private ConnectionSignUp connectionSignUp; private MongoTemplate template; ....... public UserConnectionRepositoryImpl(MongoTemplate template, ConnectionFactoryLocator connectionFactoryLocator, TextEncryptor textEncryptor, ConnectionSignUp connectionSignUp) { super(new MongoRepositoryFactory(template).<UserConnection, ObjectId>getEntityInformation(UserConnection.class), template); this.template = template; .............. } package com.web.repository; public class MongodbConnectionRepository implements ConnectionRepository { private final String userId; private final MongoTemplate mongoTemplate; private final ConnectionFactoryLocator connectionFactoryLocator; private final TextEncryptor textEncryptor; public MongodbConnectionRepository(String userId, MongoTemplate mongoTemplate, ConnectionFactoryLocator connectionFactoryLocator, TextEncryptor textEncryptor) { ....... } .....}
i'm forced to using one or another constructors with calling to super :Code:UserConnectionRepositoryImpl extends SimpleMongoRepository<UserConnection, ObjectId> implements UserConnectionRepository.....
super(new MongoRepositoryFactory(template).<UserConnection,
ObjectId>getEntityInformation(UserConnection.class ), template)
My 'common module' java config files look like:
Code:package com.core.config; @ImportResource("classpath:db-properties-config.xml") // it imports // <context:property-placeholder location="classpath*:mongodb.properties"/> @EnableMongoRepositories(basePackages = {"com.core.repository"}) public class MongoDbConfiguration extends AbstractMongoConfiguration { @Value("${mongo.host}") private String host; ....... @Override public MongoTemplate mongoTemplate() throws Exception { ........ } ...... } package com.core.repository; @Configuration @ComponentScan(basePackages = {"com.core.repository"}) @Import(MongoDbConfiguration.class) public class RepositoryConfig { @Autowired private MongoDbConfiguration mongoDbConfiguration; ....... } package com.core.service; @ComponentScan(basePackages = {"com.core.service"}) @Import({RepositoryConfig.class}) @ImportResource({"classpath:spring-security.xml", "classpath:velocityEmailSender-context.xml"}) @PropertySource("classpath:mail.properties") public class ServiceConfig { @Autowired private RepositoryConfig repositoryConfig; ......... }
The web app module is initialized by java config as well:
UserInterceptor class stays almost the same:Code:package com.web.config; @Configuration @ComponentScan(basePackages = {......... @PropertySource("classpath:social-app-settings.properties") public class SocialConfig { @Value("${facebook.clientId}:incorrectClientApiId") String facebookClientId; ....... @Autowired private MongoDbConfiguration mongoDbConfiguration; @Autowired private MongoTemplate template; ..... @Bean public ConnectionFactoryLocator connectionFactoryLocator() { ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry(); registry.addConnectionFactory(new FacebookConnectionFactory( ................. } @Bean public UsersConnectionRepository usersConnectionRepository() { try { if (template == null) { template = mongoDbConfiguration.mongoTemplate(); } } catch (Exception e) {............} UserConnectionRepository usersConnectionRepository = new UserConnectionRepositoryImpl( template, connectionFactoryLocator(), Encryptors.noOpText(), new SimpleConnectionSignUp()); return usersConnectionRepository; } @Bean @Scope(value="request", proxyMode= ScopedProxyMode.INTERFACES) public ConnectionRepository connectionRepository() { User user = SecurityContext.getCurrentUser(); return usersConnectionRepository().createConnectionRepository(user.getId().toString()); } @Bean public ProviderSignInController providerSignInController() { ProviderSignInController signInController = new ProviderSignInController(connectionFactoryLocator(), usersConnectionRepository(), new SimpleSignInAdapter()); ............. } The rest usual code from example............ } package com.web.config; @Configuration @EnableWebMvc @Import({ServiceConfig.class}) @ImportResource("classpath:/webflow-config.xml") public class WebAppConfig extends WebMvcConfigurerAdapter { ......... @Inject private UsersConnectionRepository usersConnectionRepository; ............. public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(localeChangeInterceptor()); registry.addInterceptor(new UserInterceptor(usersConnectionRepository)); ........ The rest code in not important........ } The main initialization is started by code: package com.web.config; public class MainWebAppInitializer implements WebApplicationInitializer { public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootCtx = createWebAppContext( ServiceConfig.class, RepositoryConfig.class, MongoDbConfiguration.class); rootCtx.setId("rootCtx"); AnnotationConfigWebApplicationContext webAppCtx = new AnnotationConfigWebApplicationContext(); webAppCtx.setParent(rootCtx); webAppCtx.setId("wac"); webAppCtx.register(WebAppConfig.class, SocialConfig.class); webAppCtx.setServletContext(servletContext); servletContext.addListener(new ContextLoaderListener(webAppCtx)); registerDispatcherServlet(servletContext, webAppCtx); .............. } /** Utility method private AnnotationConfigWebApplicationContext createWebAppContext(final Class<?>... annotatedClasses) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(annotatedClasses); return context; } The rest is not important.... }
Code:package com.web.social; public final class UserInterceptor extends HandlerInterceptorAdapter { private UsersConnectionRepository connectionRepository; private final UserCookieGenerator userCookieGenerator = new UserCookieGenerator(); public UserInterceptor(UsersConnectionRepository connectionRepository) { this.connectionRepository = connectionRepository; } ......... the rest is the same..... }
Stay turned, I ran out of lines in forum editor....


Reply With Quote
