spring-integration-dsl-groovy-http return null when i use httpGet method

153 Views Asked by At

I use spring integration 4.1.4 and spring integration dsl groovy 1.1.0

I included spring integration core, http in dependency.

When i am executing spring integration dsl groovy http sample, it throwing null value in console. I am not sure what i missed.

Here is my code looks like

IntegrationBuilder builder = new IntegrationBuilder("http");

def flow = builder.messageFlow {
        transform {"http://www.google.com/finance/info?q=$it"}          
        httpGet(url:{"${it}"},responseType:String)
    }

Object result = flow.sendAndReceive("vmw");

Can someone please help me?

3

There are 3 best solutions below

0
On BEST ANSWER

This has been fixed on the master branch. Meanwhile a simple work-around is

url:{"http://www.google.com/finance/info?q=$it".toString()}

or

url:{"http://www.google.com/finance/info?q=$it" as String}
1
On

What version of the DSL? You need to build from master to use with Spring Integration 4.1.x.

I will warn you that the groovy DSL has had little attention done for several years; it was never really gained any traction in the community.

The Java DSL is preferred; it is actively maintained and enhanced.

2
On

I've just tested your case and haven't seen any null value, but there was another error like this:

Caused by: java.lang.IllegalStateException: 'uriExpression' evaluation must result in a 'String' or 'URI' instance, not: class org.codehaus.groovy.runtime.GStringImpl

So, it is really a bug and feel free to raise a JIRA ticket and will take care soon.

From other side, please, let me ask the question to you: what is the reason to be on this non-stable, unmaintained stuff, when we have already Java DSL. From other side we can use any Spring Integration namespace from the regular Spring Groovy Configuration support, for example:

beans {
    xmlns([si: 'http://www.springframework.org/schema/integration'])

    def headers = environment.getProperty('headers')
    def parser = new JsonSlurper()
    def result = parser.parseText(headers)

    si.channel(id:'input')
    si.channel(id:'output')

    si.'header-enricher'('input-channel':'input','output-channel':'output') {
        result.each {k,v->
            si.'header'(name:k,expression:v)
        }
    }
}