Skip to content

Commit 29f696b

Browse files
author
AUSTIN A. HAMILTON
committed
Update README.md with using the WAR file
1 parent 6ecd8a1 commit 29f696b

8 files changed

Lines changed: 86 additions & 43 deletions

File tree

README.md

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,34 @@ Next, you will need to import the project into [**Eclipse**](https://www.eclipse
4242

4343
There are two ways you can get the source into Eclipse:
4444

45-
Option B. Import the WAR File
45+
Option A. Import the WAR File (Preferred)
4646
1. Navigate to https://github.com/ibmjstart/bluemix-java-sample-twitter-influence-app/releases
47-
2. Click the green button labeled "twitter_influence_analyzer.war" and that will download the WAR file.
47+
2. Click the green button labeled "twitter_influence_analyzer-1.2.war" and that will download the WAR file.
4848
3. Open Eclipse
4949
4. Then File->Import
5050
5. Scroll down to the "Web" section, expand that section and click WAR File then click Next.
51-
6. Click next and then Finish and the project should be imported into Eclipse
51+
6. Select the war file from where it was downloaded. Ensure that `Target Runtime` is targeting IBM Bluemix.
52+
7. Click `Next` and then `Finish` and the project should be imported into Eclipse
5253

5354
-OR-
5455

55-
Option A. Import the Eclipse project by following these instructions:
56-
1. Start by cloning the repository, as described above
57-
2. Open Eclipse
58-
3. Select File->Import
59-
4. Under the header labeled "General", click "Existing Projects Into Workspace" and click Next
60-
5. Click "Browse" next to the first text field, and navigate to the cloned repository and find the folder labeled "app" and click ok.
61-
6. Under Projects you should now see a project called "twitter_influence_analyzer", make sure the checkbox next to the "twitter_influence_analyzer" project is checked and then click Finish
62-
7. You should now see the "twitter_influence_analyzer" project in your list of projects in Eclipse.
56+
Option B. Import the Eclipse project by following these instructions: (Only if you want to modify the source code.)
57+
1. Open Eclipse
58+
2. Select File->Import
59+
3. Under the header labeled "Git", click "Projects from Git" and click `Next`
60+
4. Select `Clone URI` and click `Next`
61+
5. Copy paste the clone URL into the next page. Hit `Next`
62+
63+
![image](images/clone_url.png)
64+
6. Select the Branch to clone (you should only need Master). Click `Next`
65+
7. Name the destination directory. click `Next`
66+
8. Check `Import Existing Projects` and click `Next`
67+
9. Check the project, and click `Finish`
6368

6469
### Step 3. Acquiring External and Public APIs ###
6570

71+
**Your app will not work if you do not add your Twitter API keys and access Tokens to your environment variable.**
72+
6673
This app uses some external APIs. You need to register the app with Twitter and Klout to get the keys and tokens.
6774

6875
#### • Twitter v1.1 API ####
@@ -75,19 +82,7 @@ To access the Twitter API you need the consumer keys and access tokens, so you m
7582

7683
This app uses the Google Maps v3 APIs. Google APIs are open for the developers and you do not need to register the app with Google. Here's the [link](https://developers.google.com/maps/documentation/javascript/tutorial) for the Google Maps APIs.
7784

78-
79-
### Step 4. Configuring the Project Files###
80-
81-
Edit the twitter4j.properties file with your API and access token credentials. You can do this directly in Eclipse or using your favorite text editor.
82-
83-
| Filenames | Path |
84-
|----------------------------------------------|-----------------------------------------------------------------|
85-
| `twitter4j.properties` | Local: `.../bluemix-java-sample-twitter-influence-app/app/src/` |
86-
| `twitter4j.properties` | Eclipse: `Project_Name > Java Resources > src` |
87-
88-
The twitter credentials are entered in the file called `twitter4j.properties`. Simply copy and paste the credentials from your new app on twitter into the appropriate categories in the file.
89-
90-
### Step 5. Deploying the app ###
85+
### Step 4. Deploying the app ###
9186

9287
#### • Set up Bluemix Server ####
9388

@@ -108,13 +103,28 @@ Make sure you are in the Java EE [perspective](http://help.eclipse.org/juno/inde
108103
3. Select your Twitter Influence Analyzer project from the window on the left and click: `Add >`
109104
4. Click: `Finish`
110105
5. Enter a Name for your app and select: `Next`
111-
6. Enter THE SAME subdomain that you used to register with Twitter. (e.g. `https://`**`myTwitterApp`**`.mybluemix.net`)
112-
7. Click: Finish
106+
6. Enter THE SAME subdomain that you used to register with Twitter. (e.g. `https://`**`myTwitterApp`**`.mybluemix.net`) Click `Next`
107+
7. (Optional) Bind the Cloudant NoSQLDB service. If it is not already created, select the icon in the top right. (Refer to Option B of Creating a Cloudant Service for how to search and create the service.) Hit `Next`
108+
8. **IMPORTANT:** Add your Twitter API credentials under environment variables. Right click, and select `Add`. Provide this information:
109+
110+
111+
| Variable Name | Variable Value |
112+
|---------------------------|-------------------------------- |
113+
| TWITTER_CONSUMER_KEY | `{Your Twitter API Key}` |
114+
| TWITTER_CONSUMER_SECRET | `{Your Twitter API Secret}` |
115+
| TWITTER_ACCESS_TOKEN | `{Your Twitter Access Token}` |
116+
| TWITTER_ACCESS_KEY | `{Your Twitter Access Token Secret}` |
117+
118+
![image](images/environment_variables.png)
119+
120+
You may do this step later, but your application will fail without it.
121+
122+
9. Click: Finish. Your app will deploy to Bluemix. If you haven't already created and bound your cloudant service, please refer to Step 5: Create a Cloudant Service
113123

114124
**CONGRATS!** Your app is now published to Bluemix.
115125
(Note: It can take a few minutes to upload everything and deploy all of the services.)
116126

117-
### Step 6. Create a Cloudant service ###
127+
### Step 5. Create a Cloudant service ###
118128

119129
There are two ways to create and bind the cloudant service to your application.
120130

@@ -130,13 +140,25 @@ Option A. Using the ACE UI:
130140

131141
Option B. Using the Eclipse plugin for Bluemix
132142
1. Double click your application under the IBM Bluemix server.
133-
2. Under the services selection, select the "add a service icon" in the top right.
143+
2. Under the services selection, select the "add a service icon" in the top right. (It is just an icon)
134144
3. Search for cloudantNoSQLDB, and select the first option. Give it a name and pick the shared plan.
135145
![image](images/cloudant_service.png)
136146
4. Select `Finish`. This will create the service in your Bluemix organization.
137147
5. Under services, where your new service (with the name you specified) shows, drag the new service to "Application Services" on the right side of Eclipse. (Verify that you have the right application with the application name.)
148+
![image](images/bluemix_plugin_dashboard_small.png)
138149
6. Click `Update and Restart` to restart your app with the new service.
139150

151+
152+
### Step 6. Adding Environment Variables through ACE ###
153+
154+
Another option is to add the environment variables through ACE.
155+
1. Go to Bluemix, and navigate to your dashboard.
156+
2. Select the application that you deployed earlier on eclipse.
157+
3. On the app information page, click the buildpack, LIBERTY-WAR (IBMJDK)... either on the left side under your app name, or in the middle.
158+
![image](images/app_dashboard.png)
159+
4. Under Environment Variables, select `USER_DEFINED` and enter the same information specified in the table under Step 4.
160+
5. Select `Save`. Restart your app. It may take a few minutes for the changes to be recorded.
161+
140162
### Step 7. Explore your app ####
141163

142164
1. Navigate to the main dashboard view in Bluemix

app/pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>twitter_influence_analyzer</groupId>
44
<artifactId>twitter_influence_analyzer</artifactId>
5-
<version>0.0.1-SNAPSHOT</version>
5+
<version>1.2</version>
66
<packaging>war</packaging>
77
<build>
88
<sourceDirectory>src</sourceDirectory>
@@ -15,6 +15,18 @@
1515
<failOnMissingWebXml>false</failOnMissingWebXml>
1616
</configuration>
1717
</plugin>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-war-plugin</artifactId>
21+
<configuration>
22+
<webResources>
23+
<resource>
24+
<directory>${build.sourceDirectory}</directory>
25+
<targetPath>WEB-INF/src</targetPath>
26+
</resource>
27+
</webResources>
28+
</configuration>
29+
</plugin>
1830
<plugin>
1931
<artifactId>maven-compiler-plugin</artifactId>
2032
<version>3.1</version>

app/src/com/sampleapp/web/DispCalc.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.io.IOException;
88
import java.util.List;
9+
import java.util.Map;
910
import java.util.Properties;
1011

1112
import javax.servlet.ServletException;
@@ -21,14 +22,18 @@
2122
import twitter4j.TwitterException;
2223
import twitter4j.TwitterFactory;
2324
import twitter4j.User;
24-
import wrapper.Klout;
25+
import twitter4j.auth.AccessToken;
2526

2627
/**
2728
* Servlet implementation class DispCalc
2829
*/
2930
public class DispCalc extends HttpServlet {
3031
private static final long serialVersionUID = 1L;
31-
32+
private Map<String, String> env;
33+
private String consumer_key;
34+
private String consumer_secret;
35+
private String access_token;
36+
private String access_key;
3237

3338
/**
3439
* @see HttpServlet#HttpServlet()
@@ -50,8 +55,18 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
5055
String twitterUsername = request.getParameter("twitter_name");
5156
// The factory instance is re-useable and thread safe.
5257
Twitter twitter = new TwitterFactory().getInstance();
53-
58+
env = System.getenv();
59+
consumer_key = env.get("TWITTER_CONSUMER_KEY");
60+
consumer_secret = env.get("TWITTER_CONSUMER_SECRET");
61+
access_token = env.get("TWITTER_ACCESS_TOKEN");
62+
access_key = env.get("TWITTER_ACCESS_KEY");
63+
64+
AccessToken accessToken= new AccessToken(access_token, access_key);
65+
5466
try {
67+
twitter.setOAuthConsumer(consumer_key, consumer_secret);
68+
twitter.setOAuthAccessToken(accessToken);
69+
5570
twitter4j.User a_name = twitter.showUser(twitterUsername);
5671
int followerCount = a_name.getFollowersCount();
5772
List<Status> retweets = twitter.getUserTimeline(twitterUsername, new Paging(1, 10)); // get the first ten tweets
@@ -123,13 +138,14 @@ else if (followerCount >= 10)
123138
query.setResultType(Query.RECENT);
124139
QueryResult result1 = twitter.search(query1);
125140

141+
//TODO: Add Klout API back in using user defined variables.
126142
// Klout API calls
127-
Properties prop = new Properties();
143+
// Properties prop = new Properties();
128144
//load a properties file from the classpath
129-
prop.load(getClass().getClassLoader().getResourceAsStream("klout.properties"));
130-
String kloutKey = prop.getProperty("kloutkey");
145+
// prop.load(getClass().getClassLoader().getResourceAsStream("klout.properties"));
146+
// String kloutKey = prop.getProperty("kloutkey");
131147

132-
Klout klout = new Klout(kloutKey);
148+
// Klout klout = new Klout(kloutKey);
133149

134150
String kloutScore = "";
135151

app/src/klout.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/src/twitter4j.properties

Lines changed: 0 additions & 6 deletions
This file was deleted.

images/app_dashboard.png

210 KB
Loading

images/clone_url.png

14.2 KB
Loading

images/environment_variables.png

50.8 KB
Loading

0 commit comments

Comments
 (0)