Skip to content

Commit

Permalink
Update README.md with using the WAR file
Browse files Browse the repository at this point in the history
  • Loading branch information
karasaj committed Sep 3, 2014
1 parent 6ecd8a1 commit 29f696b
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 43 deletions.
78 changes: 50 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,34 @@ Next, you will need to import the project into [**Eclipse**](https://www.eclipse

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

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

-OR-

Option A. Import the Eclipse project by following these instructions:
1. Start by cloning the repository, as described above
2. Open Eclipse
3. Select File->Import
4. Under the header labeled "General", click "Existing Projects Into Workspace" and click Next
5. Click "Browse" next to the first text field, and navigate to the cloned repository and find the folder labeled "app" and click ok.
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
7. You should now see the "twitter_influence_analyzer" project in your list of projects in Eclipse.
Option B. Import the Eclipse project by following these instructions: (Only if you want to modify the source code.)
1. Open Eclipse
2. Select File->Import
3. Under the header labeled "Git", click "Projects from Git" and click `Next`
4. Select `Clone URI` and click `Next`
5. Copy paste the clone URL into the next page. Hit `Next`

![image](images/clone_url.png)
6. Select the Branch to clone (you should only need Master). Click `Next`
7. Name the destination directory. click `Next`
8. Check `Import Existing Projects` and click `Next`
9. Check the project, and click `Finish`

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

**Your app will not work if you do not add your Twitter API keys and access Tokens to your environment variable.**

This app uses some external APIs. You need to register the app with Twitter and Klout to get the keys and tokens.

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

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.


### Step 4. Configuring the Project Files###

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.

| Filenames | Path |
|----------------------------------------------|-----------------------------------------------------------------|
| `twitter4j.properties` | Local: `.../bluemix-java-sample-twitter-influence-app/app/src/` |
| `twitter4j.properties` | Eclipse: `Project_Name > Java Resources > src` |

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.

### Step 5. Deploying the app ###
### Step 4. Deploying the app ###

#### • Set up Bluemix Server ####

Expand All @@ -108,13 +103,28 @@ Make sure you are in the Java EE [perspective](http://help.eclipse.org/juno/inde
3. Select your Twitter Influence Analyzer project from the window on the left and click: `Add >`
4. Click: `Finish`
5. Enter a Name for your app and select: `Next`
6. Enter THE SAME subdomain that you used to register with Twitter. (e.g. `https://`**`myTwitterApp`**`.mybluemix.net`)
7. Click: Finish
6. Enter THE SAME subdomain that you used to register with Twitter. (e.g. `https://`**`myTwitterApp`**`.mybluemix.net`) Click `Next`
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`
8. **IMPORTANT:** Add your Twitter API credentials under environment variables. Right click, and select `Add`. Provide this information:


| Variable Name | Variable Value |
|---------------------------|-------------------------------- |
| TWITTER_CONSUMER_KEY | `{Your Twitter API Key}` |
| TWITTER_CONSUMER_SECRET | `{Your Twitter API Secret}` |
| TWITTER_ACCESS_TOKEN | `{Your Twitter Access Token}` |
| TWITTER_ACCESS_KEY | `{Your Twitter Access Token Secret}` |

![image](images/environment_variables.png)

You may do this step later, but your application will fail without it.

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

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

### Step 6. Create a Cloudant service ###
### Step 5. Create a Cloudant service ###

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

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

Option B. Using the Eclipse plugin for Bluemix
1. Double click your application under the IBM Bluemix server.
2. Under the services selection, select the "add a service icon" in the top right.
2. Under the services selection, select the "add a service icon" in the top right. (It is just an icon)
3. Search for cloudantNoSQLDB, and select the first option. Give it a name and pick the shared plan.
![image](images/cloudant_service.png)
4. Select `Finish`. This will create the service in your Bluemix organization.
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.)
![image](images/bluemix_plugin_dashboard_small.png)
6. Click `Update and Restart` to restart your app with the new service.


### Step 6. Adding Environment Variables through ACE ###

Another option is to add the environment variables through ACE.
1. Go to Bluemix, and navigate to your dashboard.
2. Select the application that you deployed earlier on eclipse.
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.
![image](images/app_dashboard.png)
4. Under Environment Variables, select `USER_DEFINED` and enter the same information specified in the table under Step 4.
5. Select `Save`. Restart your app. It may take a few minutes for the changes to be recorded.

### Step 7. Explore your app ####

1. Navigate to the main dashboard view in Bluemix
Expand Down
14 changes: 13 additions & 1 deletion app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>twitter_influence_analyzer</groupId>
<artifactId>twitter_influence_analyzer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.2</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
Expand All @@ -15,6 +15,18 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${build.sourceDirectory}</directory>
<targetPath>WEB-INF/src</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
Expand Down
30 changes: 23 additions & 7 deletions app/src/com/sampleapp/web/DispCalc.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.servlet.ServletException;
Expand All @@ -21,14 +22,18 @@
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.User;
import wrapper.Klout;
import twitter4j.auth.AccessToken;

/**
* Servlet implementation class DispCalc
*/
public class DispCalc extends HttpServlet {
private static final long serialVersionUID = 1L;

private Map<String, String> env;
private String consumer_key;
private String consumer_secret;
private String access_token;
private String access_key;

/**
* @see HttpServlet#HttpServlet()
Expand All @@ -50,8 +55,18 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
String twitterUsername = request.getParameter("twitter_name");
// The factory instance is re-useable and thread safe.
Twitter twitter = new TwitterFactory().getInstance();

env = System.getenv();
consumer_key = env.get("TWITTER_CONSUMER_KEY");
consumer_secret = env.get("TWITTER_CONSUMER_SECRET");
access_token = env.get("TWITTER_ACCESS_TOKEN");
access_key = env.get("TWITTER_ACCESS_KEY");

AccessToken accessToken= new AccessToken(access_token, access_key);

try {
twitter.setOAuthConsumer(consumer_key, consumer_secret);
twitter.setOAuthAccessToken(accessToken);

twitter4j.User a_name = twitter.showUser(twitterUsername);
int followerCount = a_name.getFollowersCount();
List<Status> retweets = twitter.getUserTimeline(twitterUsername, new Paging(1, 10)); // get the first ten tweets
Expand Down Expand Up @@ -123,13 +138,14 @@ else if (followerCount >= 10)
query.setResultType(Query.RECENT);
QueryResult result1 = twitter.search(query1);

//TODO: Add Klout API back in using user defined variables.
// Klout API calls
Properties prop = new Properties();
// Properties prop = new Properties();
//load a properties file from the classpath
prop.load(getClass().getClassLoader().getResourceAsStream("klout.properties"));
String kloutKey = prop.getProperty("kloutkey");
// prop.load(getClass().getClassLoader().getResourceAsStream("klout.properties"));
// String kloutKey = prop.getProperty("kloutkey");

Klout klout = new Klout(kloutKey);
// Klout klout = new Klout(kloutKey);

String kloutScore = "";

Expand Down
1 change: 0 additions & 1 deletion app/src/klout.properties

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/twitter4j.properties

This file was deleted.

Binary file added images/app_dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/clone_url.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/environment_variables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 29f696b

Please sign in to comment.