February 26th, 2012 by Craig Schwarzwald

Creating a Facebook App with Java – Part 2 – Application, Hosting, and Basic Functionality

The first article in our series took care of setting up and installing an IDE, some tools, and signing up for your new app at Facebook. Now we’ll begin creating the Web application with a landing page and some basic Facebook API calls. We’ll be creating our web application using Forge – where we left off in the part one. Because Forge allows us to start our new application very easily, and streamlines things like adding persistence (and eventually Arquillian, the testing framework) with a single command.

Create a basic web project using JBoss Forge

JBoss Forge is an incredibly powerful tool for creating new applications; it’s possible to set up much functionality very quickly. We’re going to tap into only a small fraction of its extreme powers to jump start our Facebook app. If you don’t have your Forge console open, run Forge by opening a new terminal and typing forge. Once it’s is running, you can hit <TAB> at any time to see auto-completion suggestions.
If you get an error saying forge is not a recognized command, make sure you have correctly installed Forge. Re-run your profile, and try to open forge again.
It’s now time to create our project – we will ask forge to do this for us with the following command. Note how your project is automatically set up using the default Maven project format:
forge> new-project --named FBTutorialDemo --topLevelPackage com.example

Set up the database

Next, we will set up a persistence context so we can do things like handle user registrations and process game events. We’ll use JBoss’s Hibernate (via the standard Java Persistence API.) With Forge this is extremely easy to set up; otherwise, we would need to do a fair amount of XML configuration by hand. For now, the persistence context we set up will use an in-memory database, meaning it will only retain information during the time in which the application is deployed. In other words, every time you restart your server or redeploy, your application database will be wiped out and recreated on the next start up. Don’t worry though, we’ll set up a MySQL DB to store our data more permanently, later. In our Forge terminal, type the following command. Please note that if you are using GlassFish, you will need to use different parameters for both the provider and container arguments, but by pressing <TAB>, you will see a list of all available options:
persistence setup --provider HIBERNATE --container JBOSS_AS7
Forge will then ask you if you also want to install extended APIs, you can use the default of ‘No’ (just hit <ENTER>). You should then see confirmation that Forge wrote pom.xml and persistance.xml.
/src/main/resources/META-INF/persistence.xmlView complete file
<persistence>
  <persistence-unit name="forge-default" transaction-type="JTA">
    <description>Forge Persistence Unit</description>
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.format_sql" value="true"/>
      <property name="hibernate.transaction.flush_before_completion" value="true"/>
    </properties>
  </persistence-unit>
</persistence>

Create @Entity objects to describe our app’s database schema

We will now continue to create several @Entity objects to store Users having a facebookID:long, name:String, and imageURL:String. These will represent any/all basic Facebook Users; our players and each of their friends will be set up as a User. We’ll also create a Player object having a playerInfo:User, points:long, and friendList:ArrayList<Long> (to store FacebookIDs of all the friends of that User). In the Forge window type the commands to set up our User object, results should look something like this.
entity --named User --package ~.domain
field long --named facebookID
field string --named  name
field string --named imageURL
If you get stuck, remember to press <TAB> to get Forge to give you hints on what to type next.
Now create the Player object in the same fashion. Be aware that the playerInfo and friendList fields have to be set up a little differently because of their non-native types.
entity --named Player --package ~.domain
field oneToOne --named user --fieldType ~.domain.User.java
field long --named points
field custom --named friendList --type java.util.ArrayList
We are now ready to check our pulse. Make sure things work so far by using the build command. You should see this.

Setup CDI, EJB,and REST

If you are using Forge, you may perform this entire step by using the following command. Here we instruct forge to set up CDI, EJB, and JAX-RS (REST) and specify that we want to use /rest/* as the root URL from which REST Endpoints will handle requests.
forge> setup beans ejb rest
Forge may ask you to update the packaging to a [war] file which is what we want, so hit <ENTER> to accept the default. We also need to specify a REST endpoint. We again want the default of /rest/* (hit <ENTER> again).

Verify your web.xml

If you are not using Forge, or would like to know what the plugin has done for us, we need to make sure that the following lines are in web.xml. This configuration activates our JAX-RS WebService:
/src/main/webapp/WEB-INF/web.xmlView complete file
<web-app>

  <servlet-mapping>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>
Literally speaking, <url-pattern> tells our application that we want to use JAX-RS, and specifies which requests will get routed to our endpoints. In this case, any request with a URL like http://yourapp-yourdomain.rhcloud.com/rest/*anything* will get caught and routed to our REST services.

Verify your beans.xml

We’ve also created a new file called beans.xml, which is repsonsible for activating CDI in our project. This file can be empty, or if desired, you can include the minimal XML. (We won’t add anything to this configuration beyond the empty file, so you can do what you like.)
/src/main/webapp/WEB-INF/beans.xmlView complete file
<beans />

Verify your pom.xml

We may at this point wish to check our POM file (pom.xml) to ensure that we have all of the proper dependencies for our application. Our POM should look something like this:
<project>
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.example</groupId>
	<artifactId>FBTutorialDemo</artifactId>
	<version>1.0.0-SNAPSHOT</version>
	<packaging>war</packaging>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.jboss.spec</groupId>
				<artifactId>jboss-javaee-6.0</artifactId>
				<version>2.0.0.Final</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.jboss.spec.javax.servlet</groupId>
			<artifactId>jboss-servlet-api_3.0_spec</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.jboss.spec.javax.ws.rs</groupId>
			<artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.jboss.spec.javax.xml.bind</groupId>
			<artifactId>jboss-jaxb-api_2.2_spec</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.enterprise</groupId>
			<artifactId>cdi-api</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.jboss.spec.javax.annotation</groupId>
			<artifactId>jboss-annotations-api_1.1_spec</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.hibernate.javax.persistence</groupId>
			<artifactId>hibernate-jpa-2.0-api</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.jboss.spec.javax.ejb</groupId>
			<artifactId>jboss-ejb-api_3.1_spec</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.jboss.spec.javax.transaction</groupId>
			<artifactId>jboss-transaction-api_1.1_spec</artifactId>
			<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
		<finalName>FBTutorialDemo</finalName>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>
Your POM file may contain different dependencies depending on whether or not you used Forge to set up your project, and which Forge version you’ve used. But the key point is that you need to have the JAX-RS, JPA, and CDI API libraries available for your project to compile.
At present, the current configuration of JAX-RS is assuming (and requiring) that you have a class set up with a @Path defined. Since we need to define where we are going to route our requests when they hit our servlet-mapping of /rest/*. For now we can simply create a shell of our WebService class, but leave the implementation for a later article.
forge> entity --named MyWebService --package ~.domain
forge> edit
This will open the MyWebService.java file in your default editor. Clear out the entire file, and paste in the shell code below:
Exhibit 4
package com.example.domain;

import javax.ws.rs.Path;

@Path("/webService")
public class MyWebService {

}

Get caught up

If you had any trouble following along, simply grab the code to this point from github tag: v0.1.zip — Setup CDI, EJB, and REST.

Register with OpenShift and get your project hosted

Now that we have a few @Entity objects in our project (even if it doesn’t quite do much at the moment), our next step is to host it somewhere. If you’d like, you can simply host it on your local machine at http://localhost:8080/, but we’re going to take you through setting up an account and hosting at Red Hat’s OpenShift platform which is completely free. The huge benefit here is not having to worry about blackouts, or just needing to restart your machine for some reason, as well as giving your site more dedicated bandwidth. OpenShift also offers options to expand on size and bandwidth from their free version if/when your app takes off. Go to: https://openshift.redhat.com/app/ and click the button to “Sign up and try it”; make sure to provide all of the necessary fields. OpenShift will then send you an email to the address you provided them. You’ll have to click the link in the email to validate your email address with them, retype your password, and sign in. Once logged in, you’ll need to accept the legal terms.
You can continue to follow this guide which will show you how to deploy your newly created app to your OpenShift site. If you feel like doing things the complicated way, you can also follow OpenShift’s own quick start guide here, without Forge.
We need to install Git, and a few other things before we can upload our project to the cloud, but fortunately should take only a few seconds (except maybe for the Windows users.) This command must be run from a non-Forge command prompt (all others may be run within Forge:)
sudo apt-get install git
Now install the OpenShift Express Forge plugin. In Forge, type the following commands from any directory within your project:
forge install-plugin openshift
rhc-express setup
You will need to re-type your OpenShift account information into the Forge console. Also note that it may take several minutes to complete this process.
Once DNS resolution has finally completed and OpenShift is set up in our project, we can push our changes to Openshift with a simple set of commands. This is all we’ll need to do from now on:
git add –A
git commit –a –m “Comment Here”
rhc-express deploy
Make sure any time you are trying to save/upload changes that you are adding and commiting from the root of the .git repository (aka the project folder) to ensure all changes in the project get updated.
These commands will mark all files to be sent to the server, set the messages associated with this particular commit, and then upload the new git repository, build, and redeploy the application to the cloud for us in mere seconds! If you’d like, you can also store your code on GitHub as well, like I’ve done. Once you have created a GitHub account, and a new project to contain your code, you can push your code with just a few commands.
git remote add github https://MY_GITHUB_URL
git push github master
The repository, aka MY_GITHUB_URL can be found directly on the GitHub project page; fortunately, after this initial setup, you can upload your code to GitHub at any time simply by repeating the following commands from the root folder of your project:
git add –A	 
git commit –a –m "Description of change"	 
git push github

Test your cloud connection

We’re going to do some fine tuning, adding specific code blocks to our project, and while some of these things can be done within Forge, it’s easier to use a full graphical editor for this step. If you created your project using Forge from within Eclipse, you can skip this step; otherwise, we need to import our project into the Eclipse workspace before moving forward. Open Eclipse and Click File -> Import -> Maven -> Existing Maven Projects. Browse to the maven project, import it, and create a new file called index.html in the scr/main/webapp directory. (If the file already exists, you may simply delete its contents and replace them with the following HTML snippit.) This file will greet our users when they access our application.
<html>
	<body>
		<center>
		<H1>Welcome</H1>
		<P/>
		<H3>To Tutorial Demo</H3>
		</center>
	</body>
</html>
The above simply displays a heading welcoming you to the Tutorial Demo. We can now use this to confirm that our app is being loaded correctly.

Save point – don’t lose your work!

Lets rebuild and get this new code up to our OpenShift hosting service so we can check out our new landing page. Go back to the forge console and type:
git add –A
git commit –a –m “Initial Index html file”
rhc-express deploy
We can now go to the OpenShift site (http://yourapp-yourdomain.rhcloud.com/index.html) where our app is being hosted and test to make sure we see our Welcome header. (Mine is hosted here.)
Make sure to replace “yourapp” with your application name, and “yourdomain” with your OpenShift domain name.

Get caught up

If you had any trouble following along, simply grab the code to this point from github tag: v0.2.zip — Test your cloud connection.

Configure Facebook to use your new Domain

Go back to the Facebook app page at: https://developers.facebook.com/apps Click the “Edit Settings” link (near the top right), and enter your OpenShift application’s web address into the Canvas URL and Secure canvas URL.
OpenShift lets you use http:// or https:// to access your app through non-secure or secure respectively.
CONGRATULATIONS!!! You now have an official Facebook app (try not to laugh at the fact that it doesn’t yet do anything; now we’ll take care of adding functionality to it in part three.) From now on you’ll be able to access your site and updated code immediately after you upload it to OpenShift at any time by going to: https://apps.facebook.com/yourapp/index.html
In the URL, you will need to replace “yourapp” with your application name. (E.g: Mine is hosted here.)

Add Facebook connectivity using the Javascript API

This guide references the Facebook Javascript SDK. I highly recommend you install a JavaScript editor plugin for Eclipse. Without such a plugin, simple formatting and/or styling issues can be tough to catch if there are errors in the code. Plus it just makes viewing the code easier. You can use Aptana by going into Eclipse and clicking to Help -> Install New Software, and using the URL: http://update.aptana.com/update/studio/3.2 Many methods in many of the APIs haven’t been marked deprecated when Facebook wants to phase them out, they are just removed when made obsolete. Thus, code that would have worked when certain tutorials or blog/forum posts were written may not work anymore. This is just something to be wary of when taking code from online sources other than Facebook itself to try to get functionality working on your own app.
It is important to note that there have been many versions of all the different Facebook APIs, and some may be no longer be supported. Even if the API is supported, make sure to check Facebook to ensure the API method you’re trying to use still exists when taking code from forums and tutorials for help. I originally got caught using an old version number of the PHP API in my first attempt at writing a Facebook app. When I found and logged issues Facebook’s solution was to have me use the most recent version of the PHP API instead. However, when I simply updated the version number other functionality no longer worked the same way, I eventually gave up and started over to write this tutorial using JavaScript.

Update src/main/webapp/index.html

/src/main/webapp/index.htmlView complete file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:fb="http://www.facebook.com/2008/fbml">
   <head>
       <meta http-equiv="Content-Type"
             content="text/html; charset=UTF-8"/>
       <title>Welcome to Tutorial Demo</title>
   </head>
   <body>

       <!-- <fb:login-button autologoutlink="true" 
        perms="email,status_update,publish_stream">
            </fb:login-button></p>
        -->
       <fb:login-button autologoutlink="true">
       </fb:login-button>

       <div id="fb-root"></div>
       <script type="text/javascript">
           window.fbAsyncInit = function() {
               FB.init({appId: ' YOUR_APP_ID', 
                  status: true, 
                  cookie: true, 
                  xfbml: true});
            };
           (function() {
               var e = document.createElement('script');
               e.type = 'text/javascript';
               e.src = document.location.protocol +
                   '//connect.facebook.net/en_US/all.js';
               e.async = true;
               document.getElementById('fb-root')
                                      .appendChild(e);
           }());
       </script>
       
       <center>
       <H1>Welcome to Tutorial Demo</H1><P /><BR />
       <a href='myInfo.html'>Get Your Info Here</a><BR />
       <a href='friendsInfo.html'>
                Get Your Friends Info Here</a>
       </center>
       
</body>
</html>
Make sure to replace the YOUR_APP_ID with your own app’s actual appId (in this file, and all other html files throughout the tutorial.)
The <fb:login-button> tag will add a Facebook login/out button to the site. Facebook will handle all the logic around if the user is logged in or not, and all the credentials of valid username/password etc. The commented out version of the <fb:login-button> shows you how you can access more of the Facebook data model, however if you add additional permissions here, you will need to get each user to grant access for those permissions before you can access that type of data from their accounts. If the users do not want to allow the additional access, they can not enter your app at all, so be careful not to require permissions unless you really need them, as it could cost you some user base. The next block of code allows you to utilize the Facebook Javascript API library on our page. Lastly, we put links on the page for myInfo and friendsInfo where we will have our 2 API calls.

Create src/main/webapp/myInfo.html

/src/main/webapp/myInfo.htmlView complete file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
      <meta http-equiv="Content-Type" 
            content="text/html; charset=UTF-8"/>
      <title>Tutorial Demo - My Info</title>
  </head>
  <body>

      <div id="fb-root"></div>
      <center>
         <h2>Here is your Facebook Data:</h2><p/>
      <div id="user-info"></div>
      </center>
      <a href='index.html'>
           Go back to main page</a><br />
      <script type="text/javascript">
          window.fbAsyncInit = function() {
              FB.init({appId: 'YOUR_APP_ID', 
                 status: true, 
                 cookie: true, 
                 xfbml: true, 
                 oauth: true});

              FB.Event.subscribe('auth.login', 
                                function(response) {
                  getMyInfo();
              });

              FB.getLoginStatus(function(response) {
                  if (response.authResponse) {
                      getMyInfo();
                  }
              });
          };
          (function() {
              var e = document.createElement('script');
              e.src = document.location.protocol +
                  '//connect.facebook.net/en_US/all.js';
              e.async = true;
              document.getElementById('fb-root')
                                     .appendChild(e);
          }());

          function getMyInfo(){
             FB.api('/me', function(response) {
             var userInfoElem = 
                  document.getElementById('user-info');
             userInfoElem.innerHTML =
                  '<img src="https://graph.facebook.com/'
               + response.id 
               + '/picture" style="margin-right:5px"/><br />'
               + response.name;
             });
          }
      </script>
</body>
</html>
Here we do the same thing with <div id="fb-root"> to add the FB Javascript API access to our page. However, notice that this time we are also adding some code to the window.fbAsyncInit = function() method to call our custom function getMyInfo() when the user either; (a) logs on through our button via: FB.Event.subscribe('auth.login', function(response) {, or (b) Facebook has determined the user is already logged on via: if (response.authResponse) respectively. Then we get to the heart of this page, our custom function getMyInfo(). This method uses Javascript to make a GraphAPI call to FB for "/me" which returns the current logged in FB users info. The info gets returned to us from Facebook in the response object. In this case we have access to response.id and response.name being the FacebookID and name of the current person logged in.
We can get anyone’s FB profile image with their ID using the GraphAPI as the code does by using “https://graph.facebook.com/response.id/picture”.

Create src/main/webapp/friendsInfo.html

/src/main/webapp/friendsInfo.htmlView complete file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
      <meta http-equiv="Content-Type" 
            content="text/html; charset=UTF-8"/>
      <title>Tutorial Demo - Friends Info</title>
  </head>
  <body>

      <div id="fb-root"></div>
      <center>
         <h2>Here is the Facebook Data 
                for each of your friends:</h2></p>
      <div id="friend-info"></div>
      </center>
      <a href='index.html'>Go back to main page</a>
      <br />
      <script type="text/javascript">
          window.fbAsyncInit = function() {
                 FB.init({appId: 'YOUR_APP_ID', 
                 status: true, 
                 cookie: true, 
                 xfbml: true, 
                 oauth: true});

              FB.Event.subscribe('auth.login', 
                                function(response) {
                  getFriendsInfo();
              });

              FB.getLoginStatus(function(response) {
                  if (response.authResponse) {
                      getFriendsInfo();
                  }
              });
          };
          (function() {
              var e = document.createElement('script');
              e.src = document.location.protocol +
                  '//connect.facebook.net/en_US/all.js';
              e.async = true;
              document.getElementById('fb-root')
                                        .appendChild(e);
          }());

          function getFriendsInfo() {
               FB.api("/me/friends", function(response) 
               {
                   var allFriends = response.data;
                   var tableString = "<table>"
                   for(var i=0; i<allFriends.length; i++)
                   {
                       if(i % 5 == 0){
                           // Print out up to 5 friends 
                           // per table row, 
                           // then start a new row.

                           if(i==0){
                               // Begin the first TR
                               tableString = tableString 
                               + "<tr>";
                           }
                           else{
                               // End the last TR and 
                               // start a new one
                               tableString = tableString 
                               + "</tr><tr>";
                           }
                       }

                       tableString = tableString + "<td>" 
                  + "<img src='http://graph.facebook.com/" 
                  + allFriends[i].id + "/picture'> <br/>";

                       tableString = tableString 
                            + allFriends[i].name + '</td>';
                   }
                   tableString = tableString 
                            + '</tr></table>';
                   var friendInfoElem = 
                     document.getElementById('friend-info');

                     friendInfoElem.innerHTML = tableString;
               });
          }

      </script>
      
</body>
</html>
Here we use the same tactics as myInfo.html to get the API and Events added to the page (this time calling getFriendsInfo() instead of getMyInfo()). In our custom function for this page Facebook returns to us response.data which is a list of all the friends of the current user. We use this to loop through the list and print out their picture (from their id), and their full name (from their name). The loop creates a String with all the HTML tags necessary to print out this info to a table, with 5 friends per table row. If you haven’t noticed before, we are actually using AJAX with these FB Javascript calls, which means we need to put <div> tags and then populate them asyncronysly with the results of the FB API calls once we get the response back. We can set the innerHTML of a div to whatever we want, and the browser will build the page just as if whatever is in the innerHTML property of the div tag was written in the html file directly once we get our response data back from Facebook. The last 2 lines of our method get the div element for 'friend-info' and set it to the String we built in the loop containing the HTML for the table.
If you need more test-data, you can always register test users and friend them (all you need is an email address for each one which you can keep getting from gmail or other email providers).

Save point – don’t lose your work!

This is a good time to upload your changes to OpenShift and have it rebuild and redeploy these new files out to the facebook canvas site for us. Once you get the new index and 2 new pages working, you can move on.
git add –A
git commit -a -m "Description of change"
git push github

Get caught up

If you had any trouble following along, simply grab the code to this point from github tag: v0.3.zip — Add Facebook connectivity.

Conclusion

Now that we have some minimal Facebook functionality on our site, our next article will dive into some of the slightly more advanced topics such as setting up our game logic, handling players, and saving information to our database. Players will be rewarded points for correct answers, and deducted points for incorrect answers.
Please watch our RSS feed and follow us on Twitter @ocpsoft to receive notifications of new articles.

Posted in Facebook, OpenSource

21 Comments

  1. […] should look something like this, and we are almost ready to create our actual application. In the next article we’ll utilize JBoss Forge to help give us a jump start to creating our application with just […]

  2. Matt says:

    Incredible. I love the break down. Very organized and able to be understood. Hopefully more folks will start getting involved with the creation of apps on not only Facebook but the iPad and iMac’s too.

  3. mp says:

    hi, very nice tutorial, thanks!

    i think the forge command for creating the persistence.xml is wrong.

    you wrote

    persistance

    instead of

    persistence
  4. Squat says:

    persistance setup –provider HIBERNATE –container JBOSS_AS7

    persistEnce

  5. Updated, thank you both for catching this error 🙂

  6. Maarten says:

    Hi,

    I’m using windows XP and things work great untill i have to setup the openshift account through Forge (i have an account with which i can log on). I get:
    [OpenShiftUnknonwSSHKeyTypeException: OpenShift does not support keys of type “”]

    Any suggestions?

    I do get the following warning when installing openshift:
    [ould not find a Ref matching the current Forge version [1.0.2.Final], building Plugin from HEAD.]

    Thanks,
    Maarten

  7. Maarten says:

    Figured out some things, including addind a ssh key to the openshift account.

    Now i get the following message when running rhc-express setup:
    [$where function:\nJS Error: TypeError: this.domains has no properties nofile_a:0\”, code: 10071 }’; code]
    it has to do with mongodb being used but i don’t get the message.

    Thanks,
    Maarten

    1. Glad to hear you got the OpenShift ssh keys set up. OpenShift does support MySQL 5.1, PostgreSQL 8.4, and MongoDB 2.0 databases, so you should be ok there. I’m not all that familiar with MongoDB, but this does appear to be a Mongo error. Without seeing more of your code, there’s not much at all I can do for you here, and as I mention, I’m not really familiar with that technology anyway. I would recommend searching Google for the error, if you still need help, (or instead of google) search StackOverflow. The following article looks like he has the same error as you: StackOverflow entry. If that didn’t help, you can always create your own StackOverflow account and post some of your code and the question there. You should get someone more familiar with MongoDB to help you figure it out very quickly on that site.

      1. Maarten says:

        somehow it started to work. As a test i create another project through the openshift console.

        Now i have a problem that on creation i can see the project being created in OpenShift but then i get the following output
        [***INFO*** Exception caught java.net.UnknownHostException: -.rhcloud.com
        ***ERROR*** OpenShift did not propagate DNS properly]

  8. Johannes says:

    Hi, thanks for writing this great HowTo. I could follow each step as you described but got stuck when it came to rhc-express setup. When I enter the (correct) credentials (bad ones are recognised) there’s just no further output in the console and I’m taken back to the command prompt. After doing so, git won’t work because there was no repository created. Do you have any idea how to fix this problem?

    1. Try going directly to OpenShift and click SIGN IN TO MANAGE YOUR APPS in the upper right corner. Try those same credentials. If you’re not able to get on, you can try the forgot password link, and have OpenShift reset your password. If it doesn’t even recognize your Email as being registered, try re-registering with OpenShift again, and then try the rhc-express setup again after that.

      If you’re getting to the point where its asking for credentials after the setup command, then the OpenShift-Forge plugin should be installed correctly, from there it’s just up to OpenShift to validate you with the credentials you supply. You probably also want to check that it’s not one of the common pitfalls of capslock or numlock being set to something other than you expect, since you can’t actually see the password you’re entering.

  9. Johannes says:

    Hello Craig,

    thank you for your answer although it didn’t help me to proceed. This is what I get in the eclipse forge view.

    [PresentPerfect] PresentPerfect $ rhc-express setup
    ? Enter the application name [PresentPerfect] [PresentPerfect]
    ***INFO*** If you do not have a Red Hat login, visit http://openshift.com
    ? Enter your Red Hat Login [null] [null] johan…..mel@gmx.de
    ? Enter your Red Hat Login password *******
    [PresentPerfect] PresentPerfect $ rhc-express setup
    ? Enter the application name [PresentPerfect] [PresentPerfect]
    ? Enter your Red Hat Login password *******
    [PresentPerfect] PresentPerfect $

    I didn’t enter anything when it asks me for the application name and just pressed Enter. As you can see if I try it a second time it’s not asking for the username anymore but still no output and after those steps rhc-express destroy/deploy is not available.

    1. Hi. It’s possible that the openshift plugin needs to be updated. Try reinstalling it in Forge. I know that there was some work being done on it in the past few days. I’ll try to see if anyone else has been having similar issues.

  10. […] Creating a Facebook App with Java – Part 2 – Application, Hosting, and Basic Functionali… […]

  11. Droid says:

    Hi, i need help with Forge, that is not so well documented. I’m not able to reopen a project and continue the setup that i had to stop.

    Thank you for the help.

    1. Hi,

      Please ask this question in the Forge community forums, thanks:

      https://community.jboss.org/en/forge

      ~Lincoln

      1. Droid says:

        Ok, let’s head to the desert forum 😉

        Thanks anyway!

  12. Tam says:

    [FBTutorialDemo] FBTutorialDemo $ rhc-express setup
    ? Enter the application name [FBTutorialDemo] [FBTutorialDemo]

    What do I do for the two [FBTutorialDemo] [FBTutorialDemo] ?

    It’s all failed at this point!

    Thank you in advance.

  13. b@tu says:

    I got an error when i try to install openshift-express plugin
    Here is :
    Connecting to remote repository [https://raw.github.com/forge/plugin-repository/master/repository.yaml]… connected!
    Wrote /home/baturay/.forge/httpsrawgithubcomforgepluginrepositorymasterrepositoryyaml.yaml
    ***ERROR*** [forge install-plugin] no plugin found with name [openshift-express]

    1. Amanda says:

      Same problem

    2. I believe this plugin is now just called -openshift-

Leave a Comment




Please note: In order to submit code or special characters, wrap it in

[code lang="xml"][/code]
(for your language) - or your tags will be eaten.

Please note: Comment moderation is enabled and may delay your comment from appearing. There is no need to resubmit your comment.