Bluemix.info is a news aggregator for IBM Bluemix developers and professionals covering news about everything related to IBM's platform as a service, including runtimes, services, events and much more. Bluemix.info reads information from various sources via feeds. However curators need to approve content first before it shows up on Bluemix.info. Curators can also add entries manually.
This project contains the source code of Bluemix.info which can easily also be used as news aggregator for other types of information.
The project is a good showcase of Bluemix functionality and services:
- Liberty for Java runtime
- Bluemix Cloudant service
- Bluemix single sign on service
- Bluemix data cache service
- Bluemix session cache service
- User provided service
- Bluemix workload scheduler
- Plus other open source libraries
Authors:
- Niklas Heidloff @nheidloff
- Ryan Baxter @ryanjbaxter
- Stephan Wissel @notessensei
Install Eclipse, the Java Runtime and Maven
Install Eclipse IDE for Java Developers
Find out more about Eclipse and Java Runtime installation
Install the Eclipse Maven plugin (M2Eclipse)
Install Liberty profile
Download and install Liberty profile
Get the Application Code from GitHub
You can either download the zip file or clone the project from Eclipse. Then import as Maven project.
Install WebSphere eXtreme Scale
In order to compile the code locally the project pulls in almost all dependencies via Maven.
The only exception is the library com.ibm.ws.xs.client_1.1.jar which is needed for the data cache service. In order to get this file you need to download and install "WebSphere eXtreme Scale for Developers Liberty Profile" and link to it in your project settings. To install this product, run the command:
java -jar wxs-wlp_8.6.0.5.jar
[NOTE] This product requires WebSphere Application Server for Developers Liberty Profile Version 8.5 to be installed first.
Download and install WebSphere eXtreme Scale
Download and install WebSphere Application Server for Developers Liberty Profile
Under Project Properties - Java Build Path - Libraries change the link of this file:
- com.ibm.ws.xs.client_1.1.jar (\liberty\dev\ibm-api)
[NOTE] You need to extract the com.ibm.ws.xs.client_1.1.jar from the previously downloaded wxs-wlp_8.6.0.5.jar (\liberty\dev\ibm-api) and copy it into your project folder.
Install Client Libraries for Workload Scheduler
Import the three jar files into the directory src/main/webapp/WEB-INF/lib/ (create lib if it doesn't exist):
- twaclient.jar
- tdwcsimpleui_public.jar
- tdwccronparser.jar
In your project properties under "Java Build Path" add the three libraries.
Configure the Liberty server (server.xml)
<server description="new server">
<featureManager>
<feature>jsp-2.2</feature>
<feature>localConnector-1.0</feature>
<feature>ssl-1.0</feature>
<feature>appSecurity-2.0</feature>
<feature>jaxrs-1.1</feature>
</featureManager>
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<applicationMonitor updateTrigger="mbean"/>
<sslDefault/>
<keyStore id="defaultKeyStore" password="yourPassword"/>
<webApplication id="news-aggregator"
location="news-aggregator.war"
name="news-aggregator"/>
</server>
To run the application on Bluemix you need to create an application and create and bind services.
Install the Cloud Foundry command line tool
Choose Liberty as runtime:
Then add the following services:
- Bluemix Cloudant service
- Bluemix single sign on service
- Bluemix data cache service
- Bluemix session cache service
- Bluemix workload scheduler
[NOTE] In its current version, the single sign on functionality is not supported due to a change to the sso service provider. To work around this problem you can define Cloud Directory as an authorization endoint for the sso service. In addition to that you may want to disable the method 'checkAuthorization(HttpServletRequest httpServletRequest)' in '/src/main/java/net/bluemix/newsaggregator/api/AuthenticationServlet.java'. Just comment the code and make the function always return true. Please keep in mind that this should only be considered for testing purposes.
Configure the Application and Services
When running on a server the application picks up the configuration from (most of) these services automatically. However some manual steps need to be done.
In order to use the single sign on service, you need to create a 'Single Sign On Client Configuration' in the Bluemix dashboard. The redirect URL needs to point to '/logon' e.g. https://www.bluemix.info/logon. You need to copy the generated client id and secret.
In order to pass additional configuration to the application running on Bluemix an user provided service is used.
cf cups news-aggregator-config -p "NA_SSO_REDIRECTURI, NA_SSO_CLIENT_IDENTIFIER, NA_SSO_CLIENT_SECRET, NA_CURATORS, NA_TW_ACCESS_TOKEN_SECRET, NA_TW_ACCESS_TOKEN, NA_TW_CONSUMER_SECRET, NA_TW_CONSUMER_KEY"
Single sign on service:
- NA_SSO_REDIRECTURI 'your redirect url' e.g. 'https://www.bluemix.info/logon'
- NA_SSO_CLIENT_IDENTIFIER 'your client id' e.g. 'nhMFIsHGMXuHAhaUCcZT'
- NA_SSO_CLIENT_SECRET 'your client secret' e.g. 'nhOIysMpRzQkiXzUXAfs'
List of curators:
- NA_CURATORS 'your comma separated list' e.g. 'http://www.ibm.com/[email protected],http://www.ibm.com/[email protected]'
Twitter configuration (you need to create a Twitter application)
- NA_TW_ACCESS_TOKEN_SECRET 'your access token secret' e.g. 'nhwcbJKRTE8Lf2ZJx7wpo8CIWXNJPOykRTxNhZH22W01Y'
- NA_TW_ACCESS_TOKEN 'your acess token' e.g. 'nh81184955-IH6g6NqA5s8apQs2q6DeqFcm9pUvNii7Du47qqP'
- NA_TW_CONSUMER_SECRET 'your consumer secret' e.g. 'nhcl3Uw7bm4qNhUpZ09wuEb8R7jykia9DKTmI2yMQUbczWCXlN'
- NA_TW_CONSUMER_KEY 'your consumer key' e.g. '8sq7PX3D5pwl7vPmAooPcD7fd'
The application can be run locally so that it can be tested and debugged before changes are deployed to Bluemix. When running locally no authentication and authorization check is done and the data cache service is not used.
To run it locally the following environment variables need to be set.
- NA_LOCAL true
Cloudant service (copy from Bluemix dashboard)
- NA_DB_HOST 'your cloudant host' e.g. '1234567890-bluemix.cloudant.com'
- NA_DB_PASSWORD 'your cloudant password' e.g. 'adfadsfa0b4d208e0e2452180e0db4132f3639bd8bbdae17355efc7eb24b68ae2ec'
- NA_DB_USERNAME 'your cloudant username' e.g. 'adfadsfdf984-bluemix'
Twitter configuration (you need to create a Twitter application)
- NA_TW_ACCESS_TOKEN_SECRET 'your access token secret' e.g. 'nhwcbJKRTE8Lf2ZJx7wpo8CIWXNJPOykRTxNhZH22W01Y'
- NA_TW_ACCESS_TOKEN 'your acess token' e.g. 'nh81184955-IH6g6NqA5s8apQs2q6DeqFcm9pUvNii7Du47qqP'
- NA_TW_CONSUMER_SECRET 'your consumer secret' e.g. 'nhcl3Uw7bm4qNhUpZ09wuEb8R7jykia9DKTmI2yMQUbczWCXlN'
- NA_TW_CONSUMER_KEY 'your consumer key' e.g. '8sq7PX3D5pwl7vPmAooPcD7fd'
After you've set these variables you can run the application:
Follow the following steps to deploy the application to Bluemix.
Build the sample (war file)
The sample is a Maven project. To generate the war file select the project in the Eclipse explorer and choose export war file.
Alternatively you can use the external build tool Maven. To build the app change to the project's directory in a command line window and run ...
mvn
Push app to Bluemix
In a command prompt run the following commands the same directory that contains the war file.
cf api https://api.ng.bluemix.net
cf login
You need to use your IBM id and password (Bluemix credentials)
cf push [yourappname] -p [news-aggregator.war] -m 512M
- [yourappname] - this is the name of your Bluemix app. needs to be unique
- [news-aggregator.war] - name of the exported/built war file
Alternatively you can use the Cloud Foundry Maven Plugin to build and push in one step. In this case you can deploy your application simply via ...
mvn -P deploy
Run the Application on Bluemix
Invoke the following URLs:
- Home: http://[yourappname].mybluemix.net
- API: https://[yourappname].mybluemix.net/swagger/index.html
- Curation: https://[yourappname].mybluemix.net/logon
[NOTE] There are a few minor code changes you should do in order to get the proper hyperlinking.
In the following places, change the hard coded url endpoints according to your application route:
./src/main/webapp/directives/bluemixNavbar.html:
./src/main/webapp/directives/bluemixNavbar.html:
./src/main/webapp/swagger/index.html:
url: "https://www.bluemix.info/api-docs",
./src/main/java/net/bluemix/newsaggregator/feeds/SchedulerUtilities.java: "http://www.bluemix.info/api/readfeedsscheduler"
Please note that these are just the essential parts to get your hyperlinking right.