Tuesday 10 July 2012

iPhone app that uses a web service

It took me many months of naps, but I created an iPhone app that uses the web service I created in a previous blog entry.  It took me a while to learn the language since I could only devote 20 - 30 minutes at a time here and there.  However, I did it and got a simple app working!

I used the following resources:


It's been fun doing this and I'm happy I reached my goal of a creating an iPhone app that interacts with a restful web service running on ec2.  I learned a lot from all of this, but still have lots to learn!

Monday 9 July 2012

Running the Jersey web service on AWS with Elastic Beanstalk

In a previous blog entry, I created a web-service using Jersey that calculates the area of various shapes. In this entry, I deploy the web-service to AWS using Elastic Beanstalk.

Running the Jersey web service on Elastic Beanstalk was fairly straight forward.  I followed the instructions for creating a new application.  However, I did come across an issue with the health check, that required some slight tweaking.

Health Check

Beanstalk will send a health check to your application.  By default, the application health check URL is the application root (e.g., http://myapp.elasticbeanstalk.com/) and it expects a response of 200 OK for the application to be considered healthy.

With my application, the root will return a 405 response.  However, Beanstalk will let you configure the health check url.  So, I decided to implement a health check method for Beanstalk to call.  I could have setup the health check url to call one of the existing methods (i.e. call the square method), but I figured a health check method would be better.  I added the following method to the "CalculateAreaResource" class

 @Path("/healthcheck")
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String healthCheck() {
        return Response.Status.OK.name();
    }
I then set the url health check in Elastic Beanstalk to "/calculate/area/healthcheck". However, my beanstalk environment failed to build with the error:
Your health check URL may be misconfigured. If your application does not respond to requests at http://calculate.elasticbeanstalk.com:80/calculate/area/healthcheck, modify the health check URL to a valid path.

Fixing the Health Check URL

I knew from running locally that http://localhost:8080/calculate/area/healthcheck worked, so I ssh'd into the ec2 instance.  Checking the tomcat log files and web-app directory, I noticed that my war was deployed as the ROOT web-app and not into the "calculate" context as I had been using locally.  (Note: the tomcat directory is in /opt/tomcat7)

I modified the url health check in the Elastic Beanstalk settings from "/calculate/area/healthcheck" to
"/area/healthcheck" and restarted the environment. It loaded properly and I could access my web service!

For details on how to ssh into your instance, please see the reference links below.

References: