Grails Controller var from session scope (Grails 3) - session

I now use the newly Grails version 3.0.4, when I set a controller variable with a session value my application does not run.
My controller class:
class AppSecController {
def sessionObject = SessionVars.mySessionObject()
}
I was used this way to get session values on controller vars in older grails versions, and this run successfully, but in Grails 3.0.4 it doesn't works.
The sessioned vars are defined on before() method from an initial Interceptor.
The error stack:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.company.core.security.AppSecController': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.company.core.security.AppSecController]: Constructor threw exception; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1101)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at grails.boot.GrailsApp.run(GrailsApp.groovy:52)
at grails.boot.GrailsApp.run(GrailsApp.groovy:322)
at grails.boot.GrailsApp.run(GrailsApp.groovy:311)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at core.Application.main(Application.groovy:27)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.company.core.security.AppSecController]: Constructor threw exception; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.grails.spring.beans.factory.OptimizedAutowireCapableBeanFactory$1.instantiate(OptimizedAutowireCapableBeanFactory.java:89)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1094)
... 21 more
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
at org.springframework.web.context.request.RequestContextHolder$currentRequestAttributes.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at com.company.core.SessionHandler.getSession(SessionHandler.groovy:19)
at com.company.core.SessionHandler.getVar(SessionHandler.groovy:31)
at com.company.core.SessionHandler$getVar$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at com.company.core.security.SessionVars.mySessionObject(SessionVars.groovy:40)
at com.company.core.security.SessionVars$mySessionObject.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at com.company.core.security.AppSecController.<init>(AppSecController.groovy:10)
at com.company.core.security.AppSecController.<init>(AppSecController.groovy)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
Please if anyone has been able to directly session objects on controller vars. Thanks.

Controllers are be default singleton this means only one exists for the whole application and is created at startup time, hence you cannot access session variables.
One option is to change the scope to prototype, this will create a new controller for each request. In your controller class define:
static scope = 'prototype'

Related

RestProxy request from the #Shaduled singleton bean

I'm trying to run an external service call from this code:
#Component
#Slf4j
#RequiredArgsConstructor
public class ContractStateUpdateJob {
#Autowired
private UserAttributesServiceProxy userAttributesServiceProxy;
#Scheduled(fixedRateString = "${application.jobs.contractStateUpdateJob}")
public void updateContracts(){
userAttributesServiceProxy.sendRequest(USER_ATTRIBUTE_GET_CONTRACTS_PATH,
HttpMethod.GET,HttpEntity.EMPTY);
}
}
and i am getting
Caused by: org.springframework.beans.factory.support.ScopeNotActiveException: Error creating bean with name 'scopedTarget.restTemplate': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:383)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:676)
at org.springframework.web.client.RestTemplate$$EnhancerBySpringCGLIB$$26176277.exchange(<generated>)
at de.aoksystems.occonnect.postbox.soe.api.proxy.AbstractServiceProxy.sendRequest(AbstractServiceProxy.java:51)
... 56 common frames omitted
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:42)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:371)
Who knows what could be a problem here?

How to disable all connection pooling in Spring Boot?

Context
By default our SpringBoot application uses HikariCP for its connection pooling.
We are currently investigating how to increase the performance of our application, and want to check out how our load tests behave when using PgPool instead.
It is our understanding that HikariCP and PgPool will not work well with each other and thus that we should be able to disable HikariCP in order to test the performance when using PgPool appropriately.
Question
How does one ensure that no connection pooling ("CP") is used at all at the application level?
Precision
The ultimate goal being to plug PgPool in between our application and our database.
It's my (potentially flawed) understanding that HikariCP should be disabled for that, and that each getConnection() call should return a new connection fetch from the JDBC URL configured for our application. And that that JDBC URL should eventually point to PgPool instead of the DB, which will take care of returning pooled connections.
Attempts
First, we simply removed Hikari from the dependencies:
configurations.all { exclude group: 'com.zaxxer' }
But we'd get this error:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.]
13:04:34.0242 - ERROR TenantId[] UserId[] TraceId[] Thread[main]
Logger[org.springframework.boot.SpringApplication]
Msg[Application run failed]
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)
at com.sap.s4hana.eureka.business.centralinventory.application.Application.main(Application.java:17)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104)
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:450)
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:199)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
... 8 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'prometheusMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthRegistryCustomizer' defined in class path resource
...(I interrupt the stacktrace there due to company policy)
nested exception is java.lang.IllegalStateException: No supported DataSource type found
I eventually got around to adding the following to our dependencies:
implementation 'org.apache.tomcat:tomcat-jdbc:10.0.14'
But then I'm left wondering:
Does Tomcat enable CP by default? (Which would thus mean I have not effectively removed application-level CP)
Is there not a way to simply add a configuration in application.properties to keep the servlet container but avoid CP? (So that I don't need to remove Hikari from the dependencies.)
I also tried adding (inspired by this SO answer):
spring.datasource.type=org.springframework.jdbc.datasource.DriverManagerDataSource
spring.datasource.driver-class-name=org.postgresql.Driver
And also tried replacing that DriverManagerDataSource with SimpleDriverDataSource, but to no apparent avail since I cannot seem to confirm that indeed no CP is used.

Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object

i am trying to connect db2 from my java code in web sphere application server.
i am getting following exception.please suggest any one on this.
Caused by: com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object. [Root exception is javax.xml.stream.FactoryConfigurationError: Provider javax.xml.stream.XMLInputFactory could not be instantiated: java.util.ServiceConfigurationError: javax.xml.stream.XMLInputFactory: Provider com.sun.xml.internal.stream.XMLInputFactoryImpl not a subtype] at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:1232) at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookup(Helpers.java:925) at com.ibm.ws.naming.jndicos.CNContextImpl.processBoundObjectForLookup(CNContextImpl.java:2877) at com.ibm.ws.naming.jndicos.CNContextImpl.processResolveResults(CNContextImpl.java:3974) at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1876) at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1777) at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1434) at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:616) at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:165) at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179) at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161) at javax.naming.InitialContext.lookup(InitialContext.java:428) at com.deere.u90.iaf.jdbc.connection.ConnectionManager.initializeEnvironment(ConnectionManager.java:276) ... 38 more Caused by: javax.xml.stream.FactoryConfigurationError: Provider javax.xml.stream.XMLInputFactory could not be instantiated: java.util.ServiceConfigurationError: javax.xml.stream.XMLInputFactory: Provider com.sun.xml.internal.stream.XMLInputFactoryImpl not a subtype at javax.xml.stream.XMLInputFactory.newFactory(Unknown Source) at javax.xml.stream.XMLInputFactory.newInstance(Unknown Source) at com.ibm.websphere.product.metadata.im.IMMetadata.setHistoryEventsFromHistoryXml(IMMetadata.java:745) at com.ibm.websphere.product.metadata.im.IMMetadata.parseHistoryXmlFile(IMMetadata.java:587) at com.ibm.websphere.product.metadata.im.IMMetadata.parseInstallRegistryFiles(IMMetadata.java:399) at com.ibm.websphere.product.metadata.im.IMMetadata.(IMMetadata.java:269) at com.ibm.websphere.product.metadata.im.IMMetadata.getIMMetadataInstance(IMMetadata.java:133) at com.ibm.websphere.product.metadata.WASMetadata.parseMetadataFiles(WASMetadata.java:939) at com.ibm.websphere.product.metadata.WASMetadata.(WASMetadata.java:784) at com.ibm.websphere.product.metadata.WASMetadata.getWASMetadataInstance(WASMetadata.java:215) at com.ibm.websphere.product.WASDirectory.initMetadataInstance(WASDirectory.java:1415) at com.ibm.websphere.product.WASDirectory.getIMLogLocation(WASDirectory.java:435) at com.ibm.websphere.product.VersionInfo.printSource(VersionInfo.java:1534) at com.ibm.websphere.product.VersionInfo.printReport(VersionInfo.java:1322) at com.ibm.websphere.product.VersionInfo.runReport(VersionInfo.java:1064) at com.ibm.websphere.product.VersionInfo.runReport(VersionInfo.java:1025) at com.ibm.ws.rsadapter.spi.ServerFunction$7.run(ServerFunction.java:596) at com.ibm.ws.rsadapter.spi.ServerFunction$7.run(ServerFunction.java:590) at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) at com.ibm.ws.rsadapter.spi.ServerFunction.getServerVersion(ServerFunction.java:588) at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.(WSManagedConnectionFactoryImpl.java:748) at java.lang.J9VMInternals.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1899) at com.ibm.ejs.j2c.J2CUtilityClass.createMCFEntry(J2CUtilityClass.java:468) at com.ibm.ejs.j2c.ConnectionFactoryBuilderServerImpl.createMCFandPM(ConnectionFactoryBuilderServerImpl.java:592) at com.ibm.ejs.j2c.ConnectionFactoryBuilderServerImpl.processObjectInstance(ConnectionFactoryBuilderServerImpl.java:1185) at com.ibm.ejs.j2c.ServerFunction.processObjectInstance(ServerFunction.java:2009) at com.ibm.ejs.j2c.ConnectionFactoryBuilderImpl.getObjectInstance(ConnectionFactoryBuilderImpl.java:662) at org.apache.aries.jndi.ObjectFactoryHelper.getObjectInstanceUsingObjectFactoryBuilders(ObjectFactoryHelper.java:349) at org.apache.aries.jndi.ObjectFactoryHelper.getObjectInstance(ObjectFactoryHelper.java:89) at org.apache.aries.jndi.OSGiObjectFactoryBuilder.getObjectInstance(OSGiObjectFactoryBuilder.java:62) at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:311) at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:1122) ... 50 more
I was facing the same issue and here was my resolution
I had wrongly spelled my jta data source in IBM Admin Console and was using a different name in my persistence xml so Websphere couldn't connect.
Please check the Resources Tab in the Admin Console and validate your jta data source name as declared in persistence xml

Spring Oauth2 Provider in Grails - dependency

I want to enable OAuth2 provider in my web application, which is based on Grails 2.2.2. However I'm struggling with spring-security-oauth2-provider plugin.
spring-security-oauth2-provider plugin uses spring-security-oauth2 library. I'm trying to run plugin version 1.0.4-SNAPSHOT from Git, which uses spring-security-oauth2-1.0.4.RELEASE library.
After plugin installation, my application will not start, saying that it could not initialize "oauth2ProviderFilter" bean with this exception and stack trace:
| Error 2013-06-15 23:51:51,434 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'oauth2ProviderFilter': Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauth2ProviderFilter': Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.doCreateBean(ReloadAwareAutowireCapableBeanFactory.java:122)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
at org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration.getApplicationContext(DefaultRuntimeSpringConfiguration.java:153)
at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:170)
at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:127)
at org.codehaus.groovy.grails.web.context.GrailsConfigUtils.configureWebApplicationContext(GrailsConfigUtils.java:121)
at org.codehaus.groovy.grails.web.context.GrailsContextLoader.initWebApplicationContext(GrailsContextLoader.java:107)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.reflect.MalformedParameterizedTypeException
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:53)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)
at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.generics.repository.ConstructorRepository.getParameterTypes(ConstructorRepository.java:94)
at java.lang.reflect.Method.getGenericParameterTypes(Method.java:291)
at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:387)
at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:114)
at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:72)
at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:56)
at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1130)
at java.beans.Introspector.getBeanInfo(Introspector.java:414)
at java.beans.Introspector.getBeanInfo(Introspector.java:161)
at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:217)
at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:142)
at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:324)
at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:331)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1242)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1101)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
After investigationg on oauth2 library documentation (here), I found out that oauth2ProviderFilter is an instance of OAuth2AuthenticationProcessingFilter. After inspecting source of this class (github), it looks like there are few properties (authenticationEntryPoint, authenticationManager, authencticationDetailsSource) that need to be instantiated. I thought that there might be a problem with dependency injection, so I tried to define oauth2ProviderFilter bean in resources.groovy with references to instances defined by Spring Security Core plugin.
I placed this in my resources.groovy:
beans = {
oauth2ProviderFilter(OAuth2AuthenticationProcessingFilter){
authenticationEntryPoint = ref('basicAuthenticationEntryPoint')
authenticationManager = ref('authenticationManager')
authenticationDetailsSource = ref('authenticationDetailsSource')
}
}
That did not solve the problem, there is still error saying that this filter can't be instantiated.
Since I'm no spring expert, do you think that this error might be connected with dependency injection during bean creation? Where might be the problem?
Is it possible that spring-security-oauth2 library is designed for spring framework version which and grails might be using different framework version and this might cause problems?
What are next steps I could take to find the cause of the problem and eventually fix the problem?
What happens when you run the release version of the plugin and not the SNAPSHOT? I found that when I work with latest versions of grails, many times they break existing plugins. So what I would do is...
Try to use release version of plugin with your 2.2.2 grails.
If that does not work, I would step back my grails version and try an older one with the released plugin.
If an older version does not work, I might be missing something in my setup, so I would try to figure out what it is.
If things work in older versions and it looks like my setup is good based on setting it up, then I would ask on the grails nabble on what is up and/or open a JIRA ticket.
Another thing to consider is how young/old the plugin is and how many previous bugs it had. We have many times either decided to debug the plugin because it was a worthwhile effort, but sometimes we decided to not use it because it had too many issues and were going to keep us back in the future.

java.lang.IllegalStateException: Cannot deserialize BeanFactory with id org.springframework.web.context.WebApplicationContext

When I stop my server I get this exception:
SEVERE: Exception loading sessions from persistent storage
java.lang.IllegalStateException: Cannot deserialize BeanFactory with id org.springframework.web.context.WebApplicationContext:/Life: no factory registered for this id
at org.springframework.beans.factory.support.DefaultListableBeanFactory$SerializedBeanFactoryReference.readResolve(DefaultListableBeanFactory.java:953)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadResolve(Unknown Source)
Why is that?
My guess: when spring beans are serialized (for example, as part of the http session), on restoring spring tries not to restore their original values (since they might be meaningless after the deserialization), but instead tries to fetch them by their id. If you have changed your bean definitions and have removed the bean in question, and spring tries to deserialize it (from where it has serialized it, under circumstances which I don't know based on the information given), it would throw the exception that no such bean exists.

Resources