diff --git a/intermediate/monitoring/.gitignore b/intermediate/monitoring/.gitignore new file mode 100644 index 00000000..d84084b8 --- /dev/null +++ b/intermediate/monitoring/.gitignore @@ -0,0 +1 @@ +src/main/resources/oauth.properties.* diff --git a/intermediate/monitoring/README.md b/intermediate/monitoring/README.md index 0d40a230..b4d4018e 100644 --- a/intermediate/monitoring/README.md +++ b/intermediate/monitoring/README.md @@ -22,6 +22,8 @@ and then use [VisualVM][]/JConsole to explore the [MBeans][]. The twitter search results can be examined at `http://localhost:8080/monitoring`. +Alternatively, there is a simple `main` class `SpringIntegrationTest`. + ## 2.2 Updates: The application context now includes an example of <int-jmx:notification-publishing-channel-adapter/>, to which the tweets are published. You can navigate to the MBean - **spring.application:type=TweetPublisher,name=tweeter**, click the _Notifications_ tab and then subscribe. You will then see the notifications. @@ -39,6 +41,41 @@ You should observe log output of the notifications as well as polling the channe These changes show how you can create a sophisticated monitoring application using Spring Integration - it is important to understand that the application being monitored doesn't have to be a Spring or Spring Integration application - any application that exports MBeans can be monitored in this way. +## Note: + +Twitter now requires an authenticated user to perform searches. By default, this project now uses a dummy adapter to avoid having +to configure the credentials. To use a real +adapter, uncomment the __spring.profiles.active__ `context-param` element in the `web.xml`. + +To run the `SpringIntegrationTest` command-line application, use `-Dspring.profiles.active=twitter` command line argument in the launch configuration. + +However, you will need to configure OAuth and set the values in the OAuth properties. + +To use OAuth authentication/authorization with Twitter you must create a new Application on the Twitter Developer's site. +Follow the directions below to create a new application and obtain the consumer keys and the access token: + +* Go to [http://dev.twitter.com/](http://dev.twitter.com/) +* Log in to your account +* Go to *My applications*. +* Click on 'Create a new application' link and fill out all required fields on the form provided; +* Submit the form. +* If everything is successful you'll be presented with the 'Consumer Key' and 'Consumer Secret'. +* Copy both values to a safe place. +* On the same page you should see 'My Access Token' button on bottom of the page. +* Click on it and you'll be presented with two more values: 'Access Token' and 'Access Token Secret'. +* Copy these values to a safe place as well. + +When done, fill out **oauth.properties** file so it looks similar to this. + + twitter.oauth.consumerKey=4XzBPabcJQxyBzzzH3TrRQ + twitter.oauth.consumerSecret=ab2piKdMfPu8bVa3ab6DAIvIWEVZyMDL0RSEN2I8 + twitter.oauth.accessToken=21691649-4XYZY5iJEOfz2A9qCFd9SjBRGb3HLmIm4HNE6AMv4 + twitter.oauth.accessTokenSecret=AbRxUAvyNCtqQtvxFK8w5ZMtMj20KFhB6oEfTA0 + +NOTE: the above values are samples only. + + + -------------------------------------------------------------------------------- For help please see the Spring Integration documentation: diff --git a/intermediate/monitoring/src/main/java/org/springframework/integration/service/impl/DummyTwitter.java b/intermediate/monitoring/src/main/java/org/springframework/integration/service/impl/DummyTwitter.java index 0cf9f5a2..19c56d67 100644 --- a/intermediate/monitoring/src/main/java/org/springframework/integration/service/impl/DummyTwitter.java +++ b/intermediate/monitoring/src/main/java/org/springframework/integration/service/impl/DummyTwitter.java @@ -33,7 +33,7 @@ public class DummyTwitter { "Spring Integration is the coolest Enterprise Integration project", new Date(), "SomeUser", - "http://a0.twimg.com/profile_images/1598911687/ICO_S2_Bug_normal.png", + "https://pbs.twimg.com/profile_images/378800000502646541/992d3596458fca87741b8e93e7df0860_normal.png", 0L, 0L, null, diff --git a/intermediate/monitoring/src/main/resources/META-INF/spring/integration/spring-integration-context.xml b/intermediate/monitoring/src/main/resources/META-INF/spring/integration/spring-integration-context.xml index 65e4b1b1..1800b2f2 100644 --- a/intermediate/monitoring/src/main/resources/META-INF/spring/integration/spring-integration-context.xml +++ b/intermediate/monitoring/src/main/resources/META-INF/spring/integration/spring-integration-context.xml @@ -23,12 +23,19 @@ - - - + - + + + + + + + + @@ -66,7 +73,7 @@ + expression="'Id:' + payload.id + '; Date:' + payload.createdAt + '; FromUser: ' + payload.fromUser + '; Content: ' + payload.text" /> @@ -78,7 +85,7 @@ + expression="'Id:' + payload.id + '; Date:' + payload.createdAt + '; FromUser: ' + payload.fromUser + '; Content: ' + payload.text"/> @@ -91,4 +98,27 @@ + + + + + + + + + + + + + + + + + + + diff --git a/intermediate/monitoring/src/main/resources/oauth.properties b/intermediate/monitoring/src/main/resources/oauth.properties new file mode 100644 index 00000000..651e61ff --- /dev/null +++ b/intermediate/monitoring/src/main/resources/oauth.properties @@ -0,0 +1,4 @@ +twitter.oauth.consumerKey= +twitter.oauth.consumerSecret= +twitter.oauth.accessToken= +twitter.oauth.accessTokenSecret= diff --git a/intermediate/monitoring/src/main/webapp/WEB-INF/web.xml b/intermediate/monitoring/src/main/webapp/WEB-INF/web.xml index 46208d6f..5b14b27a 100644 --- a/intermediate/monitoring/src/main/webapp/WEB-INF/web.xml +++ b/intermediate/monitoring/src/main/webapp/WEB-INF/web.xml @@ -9,6 +9,14 @@ classpath:META-INF/spring/integration/spring-integration-context.xml + + + org.springframework.web.context.ContextLoaderListener