2013-09-11

Step 12 : Add BlogController

Next create a new class called BlogController as shown below.

The code shown above does the following :

When a user makes GET request to "/blogs" then it will render form to create a blog.

When a user submits the form, a post request will be made and blog will be saved to Redis using BlogRepository save method. After save, user will be redirected to the blog.

When user makes GET request to view the blog, blog is fetched from BlogRepository and shown to user using show velocity template.

Step 13 : Deploy to OpenShift

Install JBoss Tools OpenShift plugin as mentioned my earlier blog.

Create a new OpenShift application by going to File > New > Other > OpenShift Application and entering details as shown below.

Next you will be asked to set up a blog and configure server adapter settings. Choose the default and click Next as shown below. We already have a project that we want to use so we will use existing project as shown below.

The next screen will ask you to specify the location where you want to clone the git repository and name of the git remote.Choose the default options.

Finally, press the Finish button and you are done. This will create an application container for us, called a gear, and setup all of the required SELinux policies and cgroup configuration.

Next open pom.xml and change the openshift profile as shown below. The profile added by JBoss tools has a bug that it uses outputDirectory as deployments. This works with JBoss EAP and JBoss AS7 cartridges but with Tomcat 6 and Tomcat 7 cartridges output directory should be webapps.

Go to servers view , then right click on blog OpenShift server, and click Publish as shown below.

This will not work as we have not added Redis cartridge to the application.

Step 14 : Install Redis Cartridge

To install Redis cartridge to our blog application , run the command shown below. This command assumes you already have installed OpenShift rhc command line client tool.

This will add Redis support to our application.

Now just open up your favorite browser and go to http://blog-{domain-name}.rhcloud.com. You will see your application running. To create a new blog go to http://blog-{domain-name}.rhcloud.com/blogs.

Conclusion

In this blog we covered how you can develop Java based Redis applications using Spring Redis project and deploy them to OpenShift. You are now fully equipped to use Redis on OpenShift even though it is still not officially supported. It's fully functional and you can use you it for building your applications. So, if you are a Java (EE) or Spring developer looking for a deployment platform then give OpenShift a try.

What's Next?

Sign up for OpenShift Online

Get your own private Platform As a Service (PaaS)
by evaluating OpenShift Enterprise

Need Help? Ask the OpenShift Community your questions in the forums

Showcase your awesome app in the OpenShift Developer Spotlight.
Get in the OpenShift Application Gallery today.

Show more