Grails JMS ActiveMQ, Virtual Topics, messageSelector - grails

We're currently using Grails 2.3.4 with ActiveMQ 5.7.0 and JMS Plugin 1.2, to successfully receive message maps by queues.
Now we want to switch to a "virtual topic" based scenario - and fail miserably, when it comes to receiving by Grails...
Standard Camel tests work, so the sending side seems ok.
Addendum: we use "selector-aware" configuration.
E. g. for a "queue-like" access to the "virtual topics" we need to set the "static messageSelector", but accessing the ActiveMQ by JMX never shows any value for the selector.
Has anyone had any experience using the ActiveMQ "virtual topic" with Grails!?
In addition, just recently I found that "grails-jms /src/groovy/grails/plugin/jms/listener/ListenerConfig.groovy" shows some strange code (see below).
Is there some Groovy woodoo at work or is it just an error?
def registerListenerContainer(beanBuilder) {
beanBuilder.with {
"${listenerContainerBeanName}"() {
it.parent = ref(containerParent + JmsListenerContainerAbstractBeanDefinitionBuilder.nameSuffix)
it.'abstract' = false
it.destroyMethod = "destroy"
destinationName = this.destinationName
pubSubDomain = topic
// (( ????????????
if (messageSelector) {
messageSelector = messageSelector
}
// )) ????????????
messageListener = ref(listenerAdapterBeanName)
}
}
}
Thanks for any help, comment, thought, whatsoever...

Related

Injecting service in Quartz job in Grails

developing application using Grails 2.5.1 i used Quartz plugin , and created a job successfully , but when i inject a service in this job i get org.quartz.JobExecutionException: java.lang.NullPointerException
here is the Job's code:
class EveryMonthJob {
def usersUtilsService
static triggers = {
cron name: 'EveryOneMonthJob', cronExpression: "* 31 2 L * ?"
}
def execute() {
usersUtilsService.testMe() // getting the exception here
}
}
There are any number of reasons that might not work. If you are creating an instance of the job yourself (as opposed to Spring creating the instance and subjecting it to dependency injection), that would explain why the reference is null. Another explanation could be that you have the property name wrong.
See the project at https://github.com/jeffbrown/sherifquestion. That is a Grails 2.5.1 app that does just what you are describing and it works fine. See https://github.com/jeffbrown/sherifquestion/blob/e0179f836314dccb5f83861ae8466bfd99717995/grails-app/jobs/demo/EveryMonthJob.groovy which looks like this:
class EveryMonthJob {
// generally I would statically type this property but
// am leaving it dynamically typed top be consistent with
// a question being asked...
def usersUtilsService
static triggers = {
simple repeatInterval: 5000l // execute job once in 5 seconds
}
def execute() {
usersUtilsService.testMe() // this works fine
}
}

Vaadin Push - ContextNotActiveException

I´m using Vaadin 7.5.8 on Wildfly 9.0.2. In our application we need Push support, so I´ve added the maven dependency
<groupId>com.vaadin</groupId>
<artifactId>vaadin-push</artifactId>
and added PushMode Parameter to servlet initialization.
#WebServlet(value = {"/ui/*", "/VAADIN/*"}, asyncSupported = true, initParams = {
#WebInitParam(name = "UIProvider", value = "com.vaadin.cdi.CDIUIProvider"),
#WebInitParam(name = "pushmode", value = "automatic")})
On application start i will see the login page of our application. From this point each action that causes a server communication end with this error:
Caused by: javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation #SessionScoped does not exist within current thread
at org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:330) ~[openwebbeans-impl-1.2.7.jar:1.2.7]
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:88) ~[openwebbeans-impl-1.2.7.jar:1.2.7]
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.get(NormalScopedBeanInterceptorHandler.java:70) ~[openwebbeans-impl-1.2.7.jar:1.2.7]
at com.vaadin.cdi.internal.BeanStoreContainer$$OwbNormalScopeProxy0.getUIBeanStore(com/vaadin/cdi/internal/BeanStoreContainer.java) ~[na:1.0.3]
at com.vaadin.cdi.internal.UIScopedContext.get(UIScopedContext.java:97) ~[vaadin-cdi-1.0.0.alpha2.jar:1.0.3]
at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:754) ~[openwebbeans-impl-1.2.7.jar:1.2.7]
at org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:139) ~[openwebbeans-impl-1.2.7.jar:1.2.7]
Everything works fine, when i remove the push parameter from the servlet configuration. Is there something wrong with my push configuration?
your problem is likely caused by the VaadinUI attempting an asynchronous push to the client while the session context is not active. Try switching to async-supported false to use polling rather than true async push.
This is a limitation of the Vaadin CDI plugin unfortunately, the async push wasn't designed with scope implementations in mind.
-Juuso

grails 2.4.4 integration test not using the test datasource

Help!
Our plugin project integration tests should hit the database specified in the datasource.groovy, but for some reason they ignore it, and do it in memory.
Its a plugin which provides the core services (i.e. DB access) to several grails apps which are each a grails application.
Datasource.groovy looks like this:
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
}
environments {
development {
dataSource {
dbCreate = "create-drop"
url = "jdbc:mysql://127.0.0.1:3306/db"
username = "someuser"
password = "somepass"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://127.0.0.1:3306/db"
username = "someuser"
password = "somepass"
}
}
production {
dataSource {
}
}
}
The test (SiteIntegrationSpec.goovy)
import grails.test.mixin.TestFor
import grails.test.spock.IntegrationSpec
#TestFor(Site)
class SiteIntegrationSpec extends IntegrationSpec {
static transactional = false
def setup() {
}
def cleanup() {
}
void "test something"() {
when:
Site site
site = new Site(name: "asdf", description: "asdfsd").save(failOnError: true)
then:
site.id == 3
when:
Site site2 = Site.get(1L)
then:
site2.name == "root"
}
}
Data already existing in the site table:
ID name description
1 root root
2 test test
The first test should insert a record which will happen to have an ID of 3. It actually inserts with an ID of 1, i.e. its not seeing or hitting the test database, its using some mock or internal db which is not defined anywhere.
The second test fails as instead of retrieving "root" it retrieves "asdf"
What I have tried:
creating a separate DB for test. Didn't help.
specifying -Dgrails.env=test when running tests. Didn't help
running the tests with the DB down. This correctly fails with cant create pool type exception.
changing the test datasource password to an incorrect one - this correctly throws an exception.
grails -Dgrails.env=test test-app com.me.myproject.SiteIntegrationSpec --stacktrace --verbose
So grails is connecting to the test datasource, but then the integration tests are not using it!
Any ideas?
Edit: Site is a domain object:
class Site {
String name
String description
}
Plugin DataSource.groovy files aren't included in the plugin zip, and if you somehow manually or programmatically include them, they'll be ignored. The same goes for Config.groovy, UrlMappings.groovy, and BootStrap.groovy. In general when something is usable from a plugin, if the application has a file with the same name and location, it overrides the plugin's file, so that would keep this from working also.
You could define a dataSource bean in your plugin's doWithSpring that replaces the one Grails creates based on DataSource.groovy that uses values from a file that exists in the plugin zip, or that is located in the application if that makes sense. Note that there are really 3 DataSource beans and two of them are proxies of the "real" one, so you need to define yours as dataSourceUnproxied so the other two proxy yours and retain the behavior that they add.
Another thing that you will need to fix once you resolve this is your use of unit test annotations in an integration test. Never use Mock, TestFor, or any unit test mixin annotation or base class, since their purpose is to establish a fairly realistic environment that makes up for Spring, Hibernate, installed plugins, and lots of Grails functionality not being available, but in an integration test they are available, and the unit test stuff will stomp on the real instances.
Also - why are you using static transactional = false? This disables an important integration test feature where all of your test methods run in a transaction that is rolled back at the end of the tests pass or fail. This ensures that nothing you do in a test influences other tests - everything is independent. If you disable this, you need to undo all of the changes, and it's easy to miss some and introduce false negatives or worse - false positives - into your tests.

Grails + CXF + secureServiceFactory

When I try run this script to secure my web services on Grails / CXF client I get
"Cannot invoke method getInInterceptors() on null object" on secureServiceFactory
Does secureServiceFactory need to be set somewhere else?
Any ideas:
Code :
class BootStrap {
def secureServiceFactory
def init = { servletContext ->
Map<String, Object> inProps = [:]
inProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
inProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
Map<QName, Validator> validatorMap = new HashMap<QName, Validator>();
validatorMap.put(WSSecurityEngine.USERNAME_TOKEN, new UsernameTokenValidator() {
#Override
protected void verifyPlaintextPassword(org.apache.ws.security.message.token.UsernameToken usernameToken, org.apache.ws.security.handler.RequestData data)
throws org.apache.ws.security.WSSecurityException {
if(data.username == "wsuser" && usernameToken.password == "secret") {
println "username and password are correct!"
} else {
println "username and password are NOT correct..."
throw new WSSecurityException("user and/or password mismatch")
}
}
});
inProps.put(WSS4JInInterceptor.VALIDATOR_MAP, validatorMap);
secureServiceFactory.getInInterceptors().add(new WSS4JInInterceptor(inProps))
}
Not sure this is a total answer, but, I receive the same errors and I understand that the cxf plugin is meant to wire up service factories that will match the name of your exposed service. I have verified that out of the box, running the grails-cxf plugin using grails run-app the application works. however, by executing grails war on the project creates a war that when deployed to tc server [vfabric-tc-server-developer-2.9.4.RELEASE] tomcat 7 [tomcat-7.0.47.A.RELEASE], this error occurs.
It is also useful to note that out of the box, as the plugin author has noted in other references [http://www.christianoestreich.com/2012/04/grails-cxf-interceptor-injection/] the generated war won't work unless you change test('org.apache.ws.security:wss4j:1.6.7') to compile('org.apache.ws.security:wss4j:1.6.7') and I note that I was unable to make that work, I had to use compile('org.apache.ws.security:wss4j:1.6.9')
Unfortunately, after surpassing this, I run into a third error when deploying the war that doesn't occur in grails run-app:
22-Aug-2014 11:46:05.062 SEVERE [tomcat-http--1] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet CxfServlet
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1159)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:282)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:273)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:979)
at org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:75)
I'll continue looking at it, but perhaps this war isn't meant to really deploy, but is more meant just for development of the plugin itself. however, if that is the case, it would still be better to work in TC because then we can leverage the code in our own projects with confidence.

Timeout for Futures in Akka

We have a server that processes portfolio and securities (inside it) in different actors. For portfolio with smaller number of securities (<20) this works fine. When i increase the number of security count to 1000, encountered following issues:
akka.dispatch.FutureTimeoutException: Futures timed out after [5000] milliseconds
I could bypass this error by increasing timeout inside akka config, is that the right thing to do? In akka versions earlier than 1.2 i could set self.timeout inside the actor but that is deprecated.
The other issue I faced (intermittently) is that the entire server hangs while joining in futures.map code inside my portfolio actor:
//fork out for each security
val listOfFutures = new ListBuffer[Future[Security]]()
for (security <- portfolio.getSecurities.toList) {
val securityProcessor = actorOf[SecurityProcessor].start()
listOfFutures += (securityProcessor ? security) map {
_.asInstanceOf[Security]
}
}
EventHandler.info(this,"joining results from security processors")
//join for each security
val futures = Future.sequence(listOfFutures.toList)
futures.map {
listOfSecurities =>
portfolioResponse = MergeHelper.merge(portfolio, listOfSecurities)
}.get
You do not state which version of Akka you're on, and given my limited time with the crystal ball I'll assume that you're on 1.2.
You can specify a Timeout when you call ask/?
(Also, your code is a bit convoluted, but that I have already solved in your other question.)
Cheers,
√

Resources