Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Error running a Spring Integration using spring boot/groovy dsl #6

Open
ledzepu2 opened this issue Mar 25, 2014 · 9 comments
Open

Error running a Spring Integration using spring boot/groovy dsl #6

ledzepu2 opened this issue Mar 25, 2014 · 9 comments

Comments

@ledzepu2
Copy link

I have created a Spring Boot project where i included Spring Integration starter/Spring Integration dsl groovy/dsl-groovy http.

This is the snippet from my build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'groovy'
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'application'

mainClassName = 'hello.Application'

war {
baseName = 'gs-integration'
version = '0.1.0'
}

repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-web:1.0.0.RC5') {
exclude group:'org.springframework.boot', module:'spring-boot-starter-tomcat'
}
compile 'org.springframework.boot:spring-boot-starter-actuator:1.0.0.RC5'
compile 'org.springframework.boot:spring-boot-starter-jetty:1.0.0.RC5'
compile 'org.springframework:spring-context-support:4.0.0.M3'
compile("org.codehaus.groovy:groovy-all:2.1.6")
compile("org.springframework.boot:spring-boot-starter-integration")
compile("org.springframework.integration:spring-integration-dsl-groovy-core:1.0.0.M1")
{
exclude group:'org.springframework.integration', module:'spring-integration-http'
}
compile("org.springframework.integration:spring-integration-dsl-groovy-http:1.0.0.M1")
testCompile("junit:junit-dep:4.8.2")
}
When i do gradle clean run, i am getting a stacktrace
Caused by: java.lang.ClassNotFoundException: org.springframework.integration.http.inbound.UriPathHandlerMapping
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:236)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:392)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319)
... 94 more
This is my dsl which i have used
doWithSpringIntegration {
namespaces('int-http')
springXml {
bean(id:'uriPathHandlerMapping','class':'org.springframework.integration.http.inbound.UriPathHandlerMapping')

    'int-http:inbound-gateway'(id:'events-inbound-gateway',
    'request-channel':'events-request-inbound-channel',
    'reply-channel':'events-response-inbound-channel',
    'path':'/examples/eventsFlow',
    'supported-methods':'GET'
    )

    'si:channel'(id:'events-request-inbound-channel')
    'si:channel'(id:'events-response-inbound-channel')
}

flow = messageFlow{
    httpGet(url:{"http://www.google.com/finance/info?q=$it"},responseType:String,requestChannel:'events-request-inbound-channel')

// httpGet(responseType:String,requestChannel:'events-request-inbound-channel')
}
}

@garyrussell
Copy link
Contributor

The UriPathHandlerMapping class no longer exists in Spring Integration, the DSL needs to be updated to be compatible with version 3.0.

Please open a JIRA Issue.

@ledzepu2
Copy link
Author

I commented out the bean and was able to run the application. However i am still not able to hit the path which i specified in my int-http-gateway. I see that the path /examples/eventsFlow is mapped properly. Sending the snippet from the log
20:22:20.336 [main] INFO o.s.i.h.i.IntegrationRequestMappingHandlerMapping - Mapped "{[/examples/eventsFlow],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException

When i try 2 hit the endpoint i am redirected to whitelabel error page. This is what the error page says..
There was an unexpected error (type=Not Found, status=404).
Not Found

@garyrussell
Copy link
Contributor

Can you show your hello.Application ?

I am curious as to how you are getting the DSL generated beans into boot's root context.

@garyrussell
Copy link
Contributor

I was able to kludge it to get it to work. The mapping you saw was happening in the DSL's context and so not available to the Boot app.

I had to declare a dummy adapter at the boot level in order to get the path mapping in the root context. With Spring Integration 4.0, we now have @EnableIntegration which avoids that, but the DSL is not currently compatible with SI 4.0.

I also had to "promote" the endpoint up to the root context so it's available to boot as an endpoint.

Like I said; a bit of a kluge; but it works; here is a Gist with my code.

@ledzepu2
Copy link
Author

I was able to run the example.Thanks for that.I am however facing some more issues. My use case is that i listen for requests on my http inbound gateway, parse the request, and call an http outbound gateway taking that data . I need to send the data back 2 the user.

Sending u the snippet which i was working on . I added an explicit declaration for http outbound gateway as the httpGet (mentioned in docs) was not getting recognized. I want to know how i can pass control from the inbound gateway to the outbound gateway. When i wired it this way shown below, the flow doesnot register anything. I also wanted to use spel for which i wanted to created a uri-variable. The dsl probably was not able to register and gave an errror.

package hello
doWithSpringIntegration {
    namespaces('int-http')
    springXml {

        'si:channel'(id:'events-request-inbound-channel')
        'si:channel'(id:'events-response-inbound-channel')
        'si:channel'(id:'events-flow-request-channel')

        'int-http:inbound-gateway'(id:'events-inbound-gateway',
        'request-channel':'events-request-inbound-channel',
        'reply-channel':'events-response-inbound-channel',
        'path':'/examples/eventsFlow',
        'supported-methods':'GET'
        )
        'int-http:outbound-gateway'(id:'events-outbound-gateway',
        'request-channel':'events-flow-request-channel',
        'url':'http://www.google.com/finance/info?q=GOOG',
        'reply-channel':'events-response-inbound-channel',
        'expected-response-type':'java.lang.String',
        'http-method':'GET',
        )

        'si:service-activator'('input-channel':'events-request-inbound-channel','output-channel':'events-flow-request-channel',
            'expression':'42')
    }


}

@garyrussell
Copy link
Contributor

This (including SpEL url construction) works for me...

doWithSpringIntegration {
    namespaces('int-http')
    springXml {

        'int-http:inbound-gateway'(id:'events-inbound-gateway',
        'request-channel':'events-request-inbound-channel',
        path:'/examples/eventsFlow',
        'supported-methods':'GET'
        )

        'si:channel'(id:'events-request-inbound-channel')

        'si:transformer'('input-channel':'events-request-inbound-channel',
            'expression':"'GOOG'", 'output-channel':'events-flow-request-channel')

        'si:channel'(id:'events-flow-request-channel')

        'int-http:outbound-gateway'(id:'events-outbound-gateway',
            'request-channel':'events-flow-request-channel',
            url:'http://www.google.com/finance/info?q={ticker}',
            'expected-response-type':'java.lang.String',
            'http-method':'GET') {
                'int-http:uri-variable'('name':'ticker', 'expression':'payload')
            }

    }

}

...but not from a browser (Chrome) because google gzips the content. It works fine from wget though...

$ wget localhost:8080/examples/eventsFlow
--2014-03-26 11:03:24--  http://localhost:8080/examples/eventsFlow
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:8080... connected.
HTTP request sent, awaiting response... 200 OK
Cookie coming from localhost attempted to set domain to localhost
Cookie coming from localhost attempted to set domain to localhost
Length: 289 [text/html]
Saving to: `eventsFlow'

100%[=======================================================================================================================================>] 289         --.-K/s   in 0s      

2014-03-26 11:03:35 (31.9 MB/s) - `eventsFlow' saved [289/289]

$ cat eventsFlow 

// [
{
"id": "694653"
,"t" : "GOOG"
,"e" : "NASDAQ"
,"l" : "1,157.98"
,"l_fix" : "1157.98"
,"l_cur" : "1,157.98"
,"s": "0"
,"ltt":"11:03AM EDT"
,"lt" : "Mar 26, 11:03AM EDT"
,"c" : "-0.74"
,"c_fix" : "-0.74"
,"cp" : "-0.06"
,"cp_fix" : "-0.06"
,"ccol" : "chr"
,"pcls_fix" : "1158.72"
}
]

You would need to change the accept-encoding header to prevent google from gzipping when proxying a browser.

@razazaran
Copy link

I have a question here. I am trying to access spring configuration file using junit, but it is failing before setUp() method with following errror:
10:33:21.494 INFO [main][org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping] Mapped "{[/getBillServiceImplReq],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}"
onto public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException

@razazaran
Copy link

here is my Junit:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/WEB-INF/upperSI/http/servlet-config.xml" })
@WebAppConfiguration
public class RestGetServiceImplTest{
@Autowired
private WebApplicationContext webApplicationContext;
private MockMvc mockMvc;

/**
 * Set variables and Objects which are need to execute the test-case.
 * @throws IOException 
 */
@Before
public void setUp() throws Exception{
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
        }
.......................................

@razazaran
Copy link

and servlet-config code im trying to access/load is :
<int-http:inbound-gateway request-channel="getBillServiceImplChannel"
supported-methods="POST" path="/getBillServiceImplReq" mapped-request-headers="HttpHeaders.REQUEST_URL"/>

<!-- this is require to enrich the header to handle the content-type of 
    type "application/json" -->
<int:header-enricher input-channel="getBillServiceImplChannel"
    output-channel="getBillServiceReqJsonImplChannel">
    <int:header name="content-type" value="application/json"></int:header>
</int:header-enricher>

<int:chain input-channel="getBillServiceReqJsonImplChannel">
<!-- Transformer is required to map the JSON payload in the Java object 
    format which can be processed in the eChannel framework -->
<int:json-to-object-transformer type="com.nbad.echannel.common.model.GetBillType" object-mapper="jackson2JsonObjectMapper" />
 <!-- <int:transformer ref="loggingJSONRequest" method="logJSONRequest" /> -->
<int:service-activator>
    <bean class="com.nbad.echannel.service.account.impl.GetBillServiceImpl"><constructor-arg ref="getDepositType"></constructor-arg></bean>
</int:service-activator>    
<int:object-to-json-transformer content-type="application/json" />
/int:chain

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants