1
votes

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.

2
Of course you can. What is your exact problem? - luboskrnac
I imported the Rest-http example in STS, ran Spring Tools->Update Maven dependencies and then Run As on Pivotal tc server. I am getting error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'integrationEvaluationContext':... I want to create a sample REST API using Spring Integration similar to given in this example. I have less time for development, can I implement same example using STS quickly. - pogo22
I suggest you edit your question to include this information. "...is not working for me..." is not a suitable question for stack overflow. - Gary Russell

2 Answers

1
votes

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)...

  1. File | New... | Spring Starter Project
  2. Set the name to, e.g. rest
  3. Click next
  4. Select Web, Integration (under IO)
  5. Click Finish
  6. Open demo.RestApplication (where Rest is capitalized name from #2)
  7. Add @ImportResource("classpath:context.xml")
  8. Create context.xml in src/main/resources
  9. Run the application and hit http://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);
    }

}
1
votes

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