package a.b.cclass AuthInterceptor {
def authService
AuthInterceptor() {
matchAll()
}
boolean before() {
return authService.method1() // authService is always null here
}
}
grails.util.Holders.getGrailsApplication().config
etc
import grails.core.GrailsApplication
class ProjectInterceptor {
GrailsApplication grailsApplication
...
}
@Autowired
RedisService redisService=new RedisService()
----
redisService.foo = "bar"
Caused by: java.lang.NullPointerException: Cannot get property 'resource' on null object
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:57) ~[groovy-2.4.3.jar:2.4.3]
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:169) ~[groovy-2.4.3.jar:2.4.3]
at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44) ~[groovy-2.4.3.jar:2.4.3]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:293) ~[groovy-2.4.3.jar:2.4.3]
> On Apr 17, 2015, at 9:20 PM, Voffka <voff...@gmail.com> wrote:
>
> Hi,
> Section 7.5 of Grails 3 documentation says that filters are replaced with interceptors because they are more superior.
>
> However when interceptor is created under /grails-app/controllers/com.a.b.c folder Grails does not inject services into it.
> Any ideas why it does not work? Is it intentional or I am missing something?
>
> package a.b.c
>
> class AuthInterceptor {
>
> def authService
>
> AuthInterceptor() {
> matchAll()
> }
>
> boolean before() {
> return authService.method1() // authService is always null here
> }
> }
>
>
I think either of these will work...
- Instead of dynamically typing the property with "def", use a static type and mark the property with the @org.springframework.beans.factory.annotation.Autowired annotation.
- Dynamically type the property with "def" and mark the property with the @javax.annotation.Resource annotation
Let me know if those work for you.
Thanks.
JSB
--
Jeff Scott Brown
je...@jeffandbetsy.net
@Configuration
@EnableScheduling
@EnableWebSocketMessageBroker
class GConfig extends AbstractSessionWebSocketMessageBrokerConfigurer<ExpiringSession> {
protected void configureStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/stomp").withSockJS().setInterceptors(new HttpSessionIdHandshakeInterceptor());
//registry.addEndpoint("/stomp").withSockJS()
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/queue/", "/topic/");
registry.setApplicationDestinationPrefixes("/app");
}
@Bean
GrailsSimpAnnotationMethodMessageHandler grailsSimpAnnotationMethodMessageHandler(
MessageChannel clientInboundChannel,
MessageChannel clientOutboundChannel,
SimpMessagingTemplate brokerMessagingTemplate
) {
def handler = new GrailsSimpAnnotationMethodMessageHandler(clientInboundChannel, clientOutboundChannel, brokerMessagingTemplate)
clientInboundChannel.addInterceptor(new PresenceChannelInterceptor());
handler.destinationPrefixes = ["/app"]
return handler
}
}
------------------------------------------------------------------------------------------------
@Resource
RedisService redisService=new RedisService()
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
println " PresenceChannelInterceptor "
redisService.fooKey = " barVal"
MessageHeaders headers = message.getHeaders();
SimpMessageType type = (SimpMessageType) headers.get("simpMessageType");
String simpSessionId = (String) headers.get("simpSessionId");
if (type == SimpMessageType.CONNECT) {
Principal principal = (Principal) headers.get("simpUser");
println "tes CONNECT"
} else if (type == SimpMessageType.DISCONNECT) {
println "tes DISCONNECT"
}
return message;
}
------------------------------------------------------------------------------------------------
compile "org.grails.plugins:grails-redis:2.0.2" [ This is the plugin I am using for redis ]
------------------------------------------------------------------------------------------------
PresenceChannelInterceptor
ERROR org.springframework.web.socket.messaging.StompSubProtocolHandler - Failed to send client message to application via MessageChannel in session e7spulgf. Sending STOMP ERROR to client.
org.springframework.messaging.MessageDeliveryException: Failed to send message to ExecutorSubscribableChannel[clientInboundChannel]; nested exception is java.lang.NullPointerException: Cannot get property 'resource' on null object
at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:127) ~[spring-messaging-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:104) ~[spring-messaging-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageFromClient(StompSubProtocolHandler.java:263) ~[spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:309) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.handler.WebSocketHandlerDecorator.handleMessage(WebSocketHandlerDecorator.java:75) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.handler.WebSocketHandlerDecorator.handleMessage(WebSocketHandlerDecorator.java:75) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator.handleMessage(LoggingWebSocketHandlerDecorator.java:56) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.handleMessage(ExceptionWebSocketHandlerDecorator.java:72) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.delegateMessages(AbstractSockJsSession.java:385) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.handleMessage(WebSocketServerSockJsSession.java:194) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.sockjs.transport.handler.SockJsWebSocketHandler.handleTextMessage(SockJsWebSocketHandler.java:92) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.handler.AbstractWebSocketHandler.handleMessage(AbstractWebSocketHandler.java:43) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.handleTextMessage(StandardWebSocketHandlerAdapter.java:112) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.access$000(StandardWebSocketHandlerAdapter.java:42) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$3.onMessage(StandardWebSocketHandlerAdapter.java:82) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$3.onMessage(StandardWebSocketHandlerAdapter.java:79) [spring-websocket-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:393) [tomcat-embed-websocket-8.0.23.jar:8.0.23]
at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:494) [tomcat-embed-websocket-8.0.23.jar:8.0.23]
at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:289) [tomcat-embed-websocket-8.0.23.jar:8.0.23]
at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:130) [tomcat-embed-websocket-8.0.23.jar:8.0.23]
at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:60) [tomcat-embed-websocket-8.0.23.jar:8.0.23]
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:203) [tomcat-embed-websocket-8.0.23.jar:8.0.23]
at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:663) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521) [tomcat-embed-core-8.0.23.jar:8.0.23]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478) [tomcat-embed-core-8.0.23.jar:8.0.23]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_40]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_40]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.23.jar:8.0.23]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_40]
Caused by: java.lang.NullPointerException: Cannot get property 'resource' on null object
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:57) ~[groovy-2.4.3.jar:2.4.3]
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:169) ~[groovy-2.4.3.jar:2.4.3]
at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44) ~[groovy-2.4.3.jar:2.4.3]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:293) ~[groovy-2.4.3.jar:2.4.3]
at grails.plugins.redis.RedisService.withRedis(RedisService.groovy:100) ~[grails-redis-2.0.2.jar:na]
at grails.plugins.redis.RedisService$withRedis.callCurrent(Unknown Source) ~[na:na]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49) ~[groovy-2.4.3.jar:2.4.3]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:151) ~[groovy-2.4.3.jar:2.4.3]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) ~[groovy-2.4.3.jar:2.4.3]
at grails.plugins.redis.RedisService.propertyMissing(RedisService.groovy:88) ~[grails-redis-2.0.2.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_40]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_40]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_40]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_40]
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270) ~[springloaded-1.2.3.RELEASE.jar:1.2.3.RELEASE]
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) ~[groovy-2.4.3.jar:2.4.3]
at groovy.lang.MetaClassImpl.invokeMissingProperty(MetaClassImpl.java:877) ~[groovy-2.4.3.jar:2.4.3]
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2721) ~[groovy-2.4.3.jar:2.4.3]
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:3746) ~[groovy-2.4.3.jar:2.4.3]
at grails.plugins.redis.RedisService.setProperty(RedisService.groovy) ~[grails-redis-2.0.2.jar:na]
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setGroovyObjectProperty(ScriptBytecodeAdapter.java:530) ~[groovy-2.4.3.jar:2.4.3]
at com.ofi.config.PresenceChannelInterceptor.preSend(PresenceChannelInterceptor.groovy:27) ~[main/:na]
at org.springframework.messaging.support.AbstractMessageChannel$ChannelInterceptorChain.applyPreSend(AbstractMessageChannel.java:158) ~[spring-messaging-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:113) ~[spring-messaging-4.1.7.RELEASE.jar:4.1.7.RELEASE]
... 30 common frames omitted
Thanks,Baskaran.V
--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/eGJctiOThFc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/3680DC18-0232-44C5-9D33-A269F46C5189%40ociweb.com.
For more options, visit https://groups.google.com/d/optout.