Post

Running the Simple Apache CXF Server Example on Red Hat Openshift

4 tags

Today I dedicated some time to educate myself about OpenShift, the Red Hat's Platform-As-A-Service offering.

Note: this is for a very old version of OpenShift and not applicable anymore.

Today I dedicated some time to educate myself about OpenShift, the Red Hat's Platform-As-A-Service offering. It allow us, developers, to quickly develop, deploy and provide scalable applications over the web.

To learn about it, I decided to deploy a really simple web application. I thought it would be a good idea to deploy the Simple CXF Server example on my free account. You can see it in action here. Because OpenShift documentation is quite extensive, it might be complicated for the beginner like me. So I decided to take notes of my steps while I deployed I simple Apache CXF-based application.

These are the steps I had to do:

  1. Build the Simple WS Types project as described here.

  2. Build the Simple CXF Server project as described here. This step will generate a tarball file named cxf-simple-ws-server-1.0.0-SNAPSHOT-bin.tar.gz. Don't remove it, we will need it soon.

  3. Create the application container:

rhc app create cxfexample diy-0.1

  1. Change directories:

cd cxfexample

  1. Unpack the tarball to the cxfexample directory

tar -xvf /path/to/cxf-simple-ws-server-1.0.0-SNAPSHOT-bin.tar.gz

  1. Rename the extracted directory

mv cxf-simple-ws-server-1.0.0-SNAPSHOT bin

  1. Switch to the hook directory:

cd .openshift/action_hooks

  1. Edit or create a file named start:
#!/bin/bash
# The logic to start up your application should be put in this
# script. The application will work only if it binds to
# $OPENSHIFT_DIY_IP:8080

cd $OPENSHIFT_REPO_DIR/bin
nohup java -jar cxf-simple-ws-server-1.0.0-SNAPSHOT.jar $OPENSHIFT_DIY_IP 8080 >${OPENSHIFT_DIY_LOG_DIR}/example.log 2>&1 &
  1. Edit or create a file named stop:
#!/bin/bash
source $OPENSHIFT_CARTRIDGE_SDK_BASH

# The logic to stop your application should be put in this script.
if [ -z "$(ps -ef | grep cxf-simple | grep -v grep)" ]
then
client_result "Application is already stopped"
else
kill `ps -ef | grep cxf-simple | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1
fi
  1. Adjust the permissions:

chmod +x start stop

  1. Go back to the project directory:

cd ..

  1. Add the files to the git repository:

git add -f bin && git commit -m "Install the CXF Server example"

  1. Push them to the remote repository:

git push

At this moment the application should have been deployed. If something goes wrong, you can try looking at the logs using the command:

rhc tail cxfexample

Note: although the application is set to launch at port 8080, it will actually be accessible via port 80. If you have also compiled the Simple CXF Client, you can point it to your access your newly installed cloud application:

% java -jar cxf-simple-ws-client-1.0.0-SNAPSHOT.jar cxfexample-orpiske.rhcloud.com
log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Ret = java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT-04:00",offset=-14400000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2013,MONTH=7,WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=26,DAY_OF_YEAR=1,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=17,MINUTE=37,SECOND=33,MILLISECOND=868,ZONE_OFFSET=-14400000,DST_OFFSET=0]

References:

  1. Accessing an server port running in OpenShift from another OpenShift image.

  2. How To Run ActiveMQ in the Cloud.

  3. Extending OpenShift.