Reputation: 147
I need to create Restful APIs in Spring Integration.I found a example for the same in https://github.com/spring-projects/spring-integration-samples/tree/master/intermediate/rest-http But somehow this example is not working for me. I was wondering if there is any way to create a Restful API in Spring Integration using STS. As STS provides graphs for Spring Integration, how can we create a REST API using STS graphs directly.
Thanks in Advance.
Upvotes: 1
Views: 6545
Reputation: 11
I discover something that might help you, try this link: https://dzilengine.wordpress.com/2015/08/02/seraphim/ it is a presetted Rest engine, hope it might help you
Upvotes: 1
Reputation: 174729
I don't know why you are having trouble with the sample, I just tested it and it worked ok.
However, probably the simplest way to get started with STS is (using a recent version >= 3.7)...
rest
Web
, Integration
(under IO)demo.RestApplication
(where Rest
is capitalized name from #2)@ImportResource("classpath:context.xml")
context.xml
in src/main/resourceshttp://localhost:8080/foo/bar
in your browser - it will output BAR
.RestApplication:
@SpringBootApplication
@ImportResource("classpath:context.xml")
public class RestApplication {
public static void main(String[] args) {
SpringApplication.run(RestApplication.class, args);
}
}
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
<int-http:inbound-gateway request-channel="in"
path="/foo/{id}"
supported-methods="GET"
request-payload-type="java.lang.String">
<int-http:header name="requestedId" expression="#pathVariables.id" />
</int-http:inbound-gateway>
<int:transformer input-channel="in" expression="headers['requestedId'].toUpperCase()" />
</beans>
EDIT
To make a deployable war, follow the Spring Boot instructions 'Create a deployable war' here.
But see the note about old servlet containers that don't support servlet 3.x.
Here's the updated RestApplication
class...
@SpringBootApplication
@ImportResource("classpath:context.xml")
public class RestApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(RestApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(RestApplication.class, args);
}
}
Upvotes: 1