Reputation: 2877
I need to have my Spring application poll a given URL every X
minutes and then publish an application event based on the HTTP status code returned by the remote server. I'm interested in some specific status codes: 200 (then handle the content), 404 (then raise error message) and 301 (then do nothing.)
I do not want to reinvent the wheel, so...
What would be the best way to achieve this ? Is there anything available out of the box (for instance in spring-integration, but any other library is welcome) or do I have to write it myself ?
Thanks in advance for your help.
Upvotes: 1
Views: 634
Reputation: 941
Spring Integration is the best choice for this.
Here's a sample integration route:
<int:inbound-channel-adapter channel="quakeinfotrigger.channel" expression="''">
<int:poller fixed-delay="60000"></int:poller>
</int:inbound-channel-adapter>
<int:channel id="quakeinfo.channel">
<int:queue capacity="10"/>
</int:channel>
<int:channel id="quakeinfotrigger.channel"></int:channel>
<int-http:outbound-gateway id="quakerHttpGateway"
request-channel="quakeinfotrigger.channel"
url="http://earthquake.usgs.gov/earthquakes/feed/geojson/all/hour"
http-method="GET"
expected-response-type="java.lang.String"
charset="UTF-8"
reply-timeout="5000"
reply-channel="quakeinfo.channel">
</int-http:outbound-gateway>
Gist of the full source : Refer : Link
Upvotes: 1