Hello, I am working on a custom DataSource, extending BasicDataSource, for connecting to Twitter. I would like to wire some dependencies using the Spring Dependency Injection princple. When I do this, however, this generates an error, upon starting the hostedmode.
I am using SmartGWT Power, nightly build 13-12-2010.
Wiring up my TwitterDataSource bean with a reference bean, in applicationContext.xml, Spring style
(if I remove the code above, the error below is not appearing)
The error I am getting:
Any clue what is going on? Is it at all possible to use dependency injection within your custom datasources?
PS: this is the code of the TwitterDataSource, for what it is worth
I am using SmartGWT Power, nightly build 13-12-2010.
Wiring up my TwitterDataSource bean with a reference bean, in applicationContext.xml, Spring style
Code:
<!-- custom twitter datasource --> <beans:bean id="twitterDataSource" class="com.mypackage.server.customdatasources.TwitterDataSource"> <beans:property name="keysContainer" ref="twitterKeys"/> </beans:bean>
The error I am getting:
Code:
=== 2010-12-20 13:17:23,548 [ad-0] INFO ISCInit - Isomorphic SmartClient Framework - Initializing === 2010-12-20 13:17:23,586 [ad-0] INFO ConfigLoader - Attempting to load framework.properties from CLASSPATH === 2010-12-20 13:17:23,644 [ad-0] INFO ConfigLoader - Successfully loaded framework.properties from CLASSPATH at location: jar:file:/Users/marten/Work/EclipseWorkspaces/SocialDipping/war/WEB-INF/lib/isomorphic_core_rpc.jar!/framework.properties === 2010-12-20 13:17:23,644 [ad-0] INFO ConfigLoader - Attempting to load project.properties from CLASSPATH === 2010-12-20 13:17:23,646 [ad-0] INFO ConfigLoader - Unable to locate project.properties in CLASSPATH === 2010-12-20 13:17:23,649 [ad-0] INFO ConfigLoader - Successfully loaded isc_interfaces.properties from CLASSPATH at location: jar:file:/Users/marten/Work/EclipseWorkspaces/SocialDipping/war/WEB-INF/lib/isomorphic_core_rpc.jar!/isc_interfaces.properties === 2010-12-20 13:17:23,649 [ad-0] INFO ConfigLoader - Attempting to load server.properties from CLASSPATH === 2010-12-20 13:17:23,651 [ad-0] INFO ConfigLoader - Successfully loaded server.properties from CLASSPATH at location: file:/Users/marten/Work/EclipseWorkspaces/SocialDipping/war/WEB-INF/classes/server.properties === 2010-12-20 13:17:23,656 [ad-0] INFO Logger - Logging system started. === 2010-12-20 13:17:23,656 [ad-0] INFO ISCInit - Isomorphic SmartClient Framework (SC_SNAPSHOT-2010-12-13/PowerEdition Deployment 2010-12-13) - Initialization Complete === 2010-12-20 13:17:23,657 [ad-0] INFO ISCInit - No ServletContext available yet - using container IO for now === 2010-12-20 13:17:23,676 [ad-0] ERROR ISCFile - Configured for containerIO, but servletContext not available! Problem loading builtinTypes.xml Exception when loading from __USE_CONTAINER__/generatedcode/sc/system/schema/builtinTypes.xml: java.lang.NullPointerException at com.isomorphic.io.ISCFile.<init>(ISCFile.java:145) at com.isomorphic.store.ProcessedFileCache.getObjectFromFile(ProcessedFileCache.java:135) at com.isomorphic.xml.XML.getXMLDocument(XML.java:254) at com.isomorphic.xml.XML.toDSRecords(XML.java:262) at com.isomorphic.xml.XML.toDSRecords(XML.java:265) at com.isomorphic.datasource.BasicDataSource.<clinit>(BasicDataSource.java:1603) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:71) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:948) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:901) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:574) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543) at org.mortbay.jetty.servlet.Context.startContext(Context.java:136) at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220) at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513) at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448) at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:447) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39) at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39) at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) at org.mortbay.jetty.Server.doStart(Server.java:222) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39) at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:543) at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:421) at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1035) at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:783) at com.google.gwt.dev.DevMode.main(DevMode.java:275) +++ [INFO,ContextLoader,Thread-0] Root WebApplicationContext: initialization completed in 2363 ms === 2010-12-20 13:17:24,052 [ad-0] INFO ISCInit - Auto-detected webRoot - using: /Users/marten/Work/EclipseWorkspaces/SocialDipping/war
PS: this is the code of the TwitterDataSource, for what it is worth
Code:
package nl.sytematic.projects.SocialDipping.server.customdatasources; /** * TwitterDatasource that can retrieve and send data to twitter. * Requires that the user is already authenticated using oAuth. Use TwitterAuthenticationServlet for this. * If the CRUD methods are called when there is no Auth key available, an error is returned. */ public class TwitterDataSource extends BasicDataSource { protected TwitterPublicKeyAndSecretContainer keys; //to be set using dependency injection public void setKeysContainer(TwitterPublicKeyAndSecretContainer c) { this.keys = c; } public TwitterPublicKeyAndSecretContainer getKeysContainer() { return this.keys; } protected final int NOT_AUTHENTICATED_ON_TWITTER = -403; //lets use negative numbers for our errors protected Twitter twitter = null; /** * Post something on Twitter */ @Override public DSResponse executeAdd(DSRequest req) throws Exception { // Check if authorisation token and access token are stored in the logged in user profile. // if not, return error, so that the client can redirect to the oAuth page using the TwitterAuthenticationServlet. DSResponse res = new DSResponse(); if (!isAuthenticatedOnTwitter(req)) { return getNotAuthenticatedDsResponse(); } else { initializeAuthedTwitterConnection(); } //authenticated, post on tweet parameter on twitter. String tweet = (String) req.getFieldValue("tweet"); if (res.getErrors() == null || res.getErrors().isEmpty()) { twitter.setStatus(tweet); } return res; } ... }
Comment