Friday, March 18, 2011
Get text from java mail
If you don't want to dig javamail structures and mime types, there is easy way to extract text from Message object described in javamail official docs (I wonder why they didn't put it directly into specification).
Friday, February 25, 2011
Spring Integration namespaces in resources.groovy
Spring Integration relies heavily on namespaces usage, so if you need to use it, this can be easily defined in Grails Spring DSL:
After that you can define your channels like:
beans = {
xmlns integration:"http://www.springframework.org/schema/integration"
xmlns mail:"http://www.springframework.org/schema/integration/mail"
xmlns jms:"http://www.springframework.org/schema/integration/jms"
}
After that you can define your channels like:
integration.channel(id:'inboundEmailChannel')
Thursday, February 24, 2011
Processing incoming emails with Spring Integration
Recently, I had a task to automatically process emails that come to specified address. Trivial solution is to create some periodic task with Quartz or Timer and pull new emails and process them. I googled if there is ready lib to do this and found that this can be done with Spring; or more specifically with Spring Integration. I heard about this project, but didn't payed a lot of attention to it. Main idea behind it is - this is small local ESB, so basically if you need to act on some incoming event or send some outgoing event to some system, this is nice place to look at. Another good thing is that it provides easy and out-of-the-box ready interface to many different systems, which is exactly what I was looking for email processing.
So with Spring Integration, reading email is just few beans definition (in Grails Spring DSL):
So, with this, when you have incoming email, it will call
So with Spring Integration, reading email is just few beans definition (in Grails Spring DSL):
integration.channel(id:'inboundEmailChannel')
mail.'inbound-channel-adapter'(id:"imapAdapter",
'store-uri':"imaps://${CH.config.logging.imap.credentials}@imap.gmail.com/INBOX",
'java-mail-properties':['mail.imap.socketFactory.class':'javax.net.ssl.SSLSocketFactory',
'mail.imap.socketFactory.fallback':false,
'mail.store.protocol':'imaps', 'mail.debug':false],
channel:"inboundEmailChannel",
'should-delete-messages':true,
'should-mark-messages-as-read':true,
'auto-startup':true) {
integration.poller('max-messages-per-poll':"1", 'fixed-rate':"5000")
}
integration.'service-activator'( 'input-channel':"inboundEmailChannel",
ref:"emailService", method:"inboundEmail")
So, with this, when you have incoming email, it will call
inboundEmail method of emailService.
Tuesday, January 11, 2011
Configuration properties in resources.groovy
In Grails there is support for property placeholders in resources.xml, but for resources.groovy you should do it manually. Fortunately, it is quite easy, here is example:
import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH
beans = {
integration.channel(id:'channel', host:'imaps://user:${CH.config.imap.password}@imap.gmail.com/INBOX')
}
Monday, December 27, 2010
Check XPath in Firefox with Firebug
There is easy way to check any XPath expression in Firefox if you have Firebug plugin. Just type:
with your XPath expression and it will output list of matched elements, so you can click it and see on the page. Very handy to check Selenium XPath selectors.
$x('//a')
with your XPath expression and it will output list of matched elements, so you can click it and see on the page. Very handy to check Selenium XPath selectors.
Monday, November 15, 2010
Debugging grails in Netbeans
Grails plugin for Netbeans lacks some must have features like test launching from IDE and so on. Fortunately, Grails debugging is still super-simple with Netbeans. All you have to do is to run Grails from console with
Just type command in command console:
One thing to notice is that if you want to evaluate some expression in debug mode, you should use Java, but not Groovy, at least now.
grails-debug instead of simply grails. For example, you want to debug test SeleniumTest.Just type command in command console:
grails-debug test-app functional: SeleniumTest
Then go to Netbeans and select from menu Debug > Attach Debugger..., by default there is JPDA debugger, connector - SocketAttach, just enter your host and port (default is 5005, you can see yours in Grails console). Press OK. And it should connect to Grails process, so it will stop on breakpoints. Easy. One thing to notice is that if you want to evaluate some expression in debug mode, you should use Java, but not Groovy, at least now.
Saturday, August 7, 2010
Local git setup error
Recently I decided to check GIT. I am old fan of Tortoise tools and I decided to start with TortoiseGit. It is nice tool with familiar interface.
I am a little familiar with Mercurial and heard that they are quite similar in concepts. So I started by creating repository by command “Git create repository here”.
Then I created “Git Clone” of my repository in new folder. Then I started to play and created new files and commited changes. But then, when I tried to push my changes to master repository I got big ugly error:
This was quite confusing and error is not helping much. Also this scenario was working nicely with Mercurial, so I was really confused. But after some googling I found really nice article about git at http://cworth.org/hgbook-git/tour/, and it is explained nicely how to create repository that can be used with “push”. You just have to create it with
It is really strange that there is no any option that can be set while creating repository and you still have to do it command line way. But issue was solved.
I am a little familiar with Mercurial and heard that they are quite similar in concepts. So I started by creating repository by command “Git create repository here”.
Then I created “Git Clone” of my repository in new folder. Then I started to play and created new files and commited changes. But then, when I tried to push my changes to master repository I got big ugly error:
git.exe push "origin" master:master
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To C:\########
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'C:\########'
This was quite confusing and error is not helping much. Also this scenario was working nicely with Mercurial, so I was really confused. But after some googling I found really nice article about git at http://cworth.org/hgbook-git/tour/, and it is explained nicely how to create repository that can be used with “push”. You just have to create it with
git --bare init --shared
It is really strange that there is no any option that can be set while creating repository and you still have to do it command line way. But issue was solved.
Subscribe to:
Posts (Atom)