Posts

Showing posts from December, 2012

A Simple Java Http Client

I recently needed to make an HTTP call from my AppEngine application, which uses the standard java.net classes for its urlFetch service.  Doing something as simple as an HTTP request in Java is a lot more complicated than one would hope.  Since I didn't find the process intuitive at all, I wrote this little Java HTTP client that works the way I think of HTTP.

Along the way I got to experiment with generics, which allowed me to make chained method calls so I can effectively make the whole HTTP request and get the response in one line of code (sort of).  The whole client consists of three classes and uses only core java classes, so no external libraries are needed (and it can run on AppEngine).

Message.java This class forms the basis for the Request and Response classes.  Message is an abstract class, and contains only those things that are common to both Requests and Responses, e.g. headers and a body.

Request.java This class does most of the heavy lifting.  It contains fields and …

Polymorphism in Objectify

I'm currently learning how to use Objectify with Google AppEngine (GAE).  I was tripped-up while trying to use the polymorphic capabilities of Objectify.  With the patient help of Jeff on the objectify-appengine group, I realized that I was confusing Objectify's polymorphic object hierarchy with my code's inheritance tree.

I put together a demo to illustrate the difference.  Consider an object hierarchy where Vehicle is extended by Car and Motorcycle:

Vehicle.java:@Entity public class Vehicle extends Foundation { @Id private String licensePlate; @Index int numWheels; @Index int numCylinders; public String getLicensePlate() { return licensePlate; } public void setLicensePlate(String licensePlate) { this.licensePlate = licensePlate; } }
Here are the meanings of the annotations on the Vehicle class:

@Entity - Makes the Vehicle class the root of a Objectify polymorphic hierarchy.  An application could have many roots …

Wearing the Golden Handcuffs

I've been working at the same job for the same company for over a decade. In my line of work as a Programmer/Analyst, that's an eternity.  I work for a great boss, at a great company, making good money, doing work that is more-or-less fulfilling, but somehow it is all just getting a little "old".  Ever since Carl showed up as a stockholder, things have been changing around the company. We're no longer obsessed with providing better services than our competitors, but instead we're worried about aligning our expense structure to be the same as everyone else in our industry.

I know I should be grateful to have reliable employment these days, but I can feel my skills becoming less and less relevant every day, and I long for the days when I could experiment and try new technologies without having to fight against deeply entrenched tools and philosophies.  I feel it is my duty to myself to keep my skills current and relevant to what's happening in the marketp…