my2cents

27. June, 2007

Why ServletRequest#getRemoteAddr() returns 127.0.0.1

Filed under: Java,Software Development — frightanic @ 00:39

When I found the reason why my Servlet container returns the “wrong” remote address I had to smite my forehead – long and hard. As so often the container is right and I was simply on the wrong track. It’s soooo obvious, Jesus…

If you access your application using the URL

http://localhost:port/

, you will get the remote address as 127.0.0.1 (local host address i.e. loop back address). Instead, try accessing the URL using your system/server name to get the desired output

http://systemname:port/

Yet another lesson learned I’ll never forget.

26. June, 2007

Sunspotting at Jazoon

Filed under: Jazoon,Sun SPOT — frightanic @ 13:12

Sun SPOTs are incredibly cool sensor devices produced by, well, Sun Microsystems. They seem to have a real momentum right now.

At Jazoon in Zurich Sun’s Simon Ritter gave a top presentation about the SPOTs in general an fed us with some background info. Since I’m working on my own SPOT application it didn’t come as a surprise that much of it wasn’t new to me. Nonetheless, I learned that the Sun Squawk J2ME implementation was started as a totally independent project and that it should be easily portable to different mobile devices as its native layer is very thin. Also, I knew it but wasn’t fully aware that I can have several applications running on one and the same SPOT in parallel. The fact that a SPOT contains several boards that serve separate purposes underline that they were built with extensibility in mind. Simon demonstrated how to control a Looking Glass user interface with a P5 Data Glove. It wasn’t quite like what you might know from the “Minority Report” movie, yet.
What I don’t get though, is why Sun stresses that SPOTs can (and should) be used for real-world applications. Yet, all they ever present and demonstrate are toy-related “fun products”. Good for nerds, but not so good for management making decisions.

Ergon had a dual-player Arkanoid application with the two bars controlled by Sun SPOTs tilted left/right. It’s fun to play, but takes some time to get accustomed to the responsiveness of the sensor application. I want to build that, too! It shouldn’t take too long to turn a regular mouse-controlled Arkanoid implementation into a SPOT-controlled toy.

25. June, 2007

I jog, therefore I am

Filed under: Life — frightanic @ 20:54

You see, Descartes’ famous dictum “Cogito ergo sum” can be transformed into whatever expression suits you best.

I hate jogging. I find it boring and only jog from time to time because it’s one of the easiest and cheapest ways to stay fit with outdoor sports. Sometimes though I feel I have to go jogging. Certain conditions virtually drag me outside. Tonight it’s pouring like hell, and yes, it’s one of those conditions. I didn’t go jogging despite the heavy rain, but rather because of it. I makes me feel special. It’s that “what the hell…” feeling.

After five minutes my shoes are wet. So what! Then my Asics jacket. So what! Then my socks. Whatever! Finally, my underwear is soaking wet. Yuck, but what the f…! I keep running, feeling free. Warm rain (rain or water?) is runningĀ  down my back and it feels good. The summer rain is so heavy it feels like in a car wash or natural shower.

Never done that? You should try!

Jazoon: Model-driven architecture with AndroMDA

Filed under: Jazoon — frightanic @ 15:38

Yes folks, I’m at Jazoon currently. And while at it I thought I could persist my impressions in this blog. Why not share my notes with the world? After all, this is what blogging is all about – in a way at least.

The talk “Model-driven architecture with MDA was presented by two engineers from ergon AG. They presented their accumulated experiences from a real world project. While one can find loads of information about MDA as such, it was interesting to hear about hands-on experience. Since I got my own fair share of MDA stories and since those experiences made me somewhat reluctant to howl with the MDA-is-so-great wolves, I was keen to learn if it can be done right easily. A few things that I picked up:

  • AndroMDA seems to like certain UML tools better than others. Magic Draw was used in the project presented because it was recommended by AndroMDA. I learned the same the hard way when we migrated from one modeling tool to the other. The XMI dialects can be quite different. Watch out for that! There’s a fair chance that you’ll have vendor lock-in there.
  • Since AndroMDA uses the concept of “cartridges” (that’s what they call their plugins) the generated code can be based on any application framework. ergon generated code for Spring and Hibernate for example with the respective cartridges. Since those cartridges are extensible it should be easy, the said, to write your own.
  • One major aspect of generating code is protecting those code sections you augmented yourself after generation. You don’t want that a subsequent generation run overwrites your own code. We used to have specially marked protected code sections the generator would not touch. According to the presenters AndroMDA seems to have an issue with this. It generates abstract superclass and dummy implementations for each abstract class. You’re then expected to fully implement the generated subclass. AndroMDA won’t touch those again. However, if your interface changes (resulting in a new abstract class) you have to push down those changes to the implementation class yourself. Or throw away the implementation class and have AndroMDA generate a new dummy implementation that satisfies the interface. Ugly and error-prone.
  • ergon seem to advocate to “breed” a new kind of developer. They call them “modelers”. Hard-core code junkies like myself are likely to get bored with their job if they rarely need to touch code anymore – as promised with the MDA approach. At ergon the same developers that would have hand coded the application were used to model and generate the application. It was said that they (only?) still had fun because everything was so new to them.

16. June, 2007

No sun spot basestation found

Filed under: Sun SPOT — frightanic @ 23:59

While deploying an application to a remote SunSPOT over the base station I get a “No sun spot basestation found” error every now and then. In the Sun SPOT forum are a few hints about that “problem”, but none really helped in my case. I’m currently developing on a Windows 2000 machine (once the new Sun SPOT beta release is installed I’ll switch to my MacBook).

Usually the base station is found automatically and you shouldn’t have to set the port explicitly. However, there are two parameters which allow you to point the “find spots” application into the right direction: sunport=COMn and port=COMn as explained in chapter 4 of the Developer’s Guide. So, whenever the base station apparently cannot be found I simply activate port=COM3 in my .sunspot.properties. That does the trick usually. Of course, I disable the parameter afterwards.

If that doesn’t help I go to my Windows Device Manager, open up the COM & LPT item and reinstall the Sun SPOT entry. Sometimes I need to restart my PC after that procedure.

“Content is not allowed in prolog” for XML in Eclipse

Filed under: Java,Software Development — frightanic @ 23:19

This blog now resides at http://www.frightanic.com/. It will be discontinued hereā€¦

Sometimes life as a software developer is almost too painful for me to bear. It’s ok to debug a piece of code for hours or to rack one’s brains over a problem instead of getting a good night’s rest; that’s part of the deal. What I can’t stand is solving a problem after hours and realizing that I had been barking up the wrong tree all the time.

While working on my first Sun SPOT project (blog posts on that are ahead) with Eclipse, the ANT editor all of a sudden reported an error on an XML build file: “content is not allowed in prolog”. While I was vaguely familiar with the meaning of it I could not see what was wrong with the XML file. For hours I searched the Internet, played around with my Eclipse preferences, and studied the first few lines of my build file. I loaded the file into the XML editor to confirm that it was valid indeed. I also loaded it into XmlSpy to double check. I did the right thing but missed to draw the right conclusions. As an XML document the file was ok, but as an ANT file it obviously wasn’t.

It was only after too many hours that I started stripping down the file, removing everything that wasn’t absolutely necessary. The error disappeared. So, I started removing individual lines to find the hot spot. When I stumbled upon an ANT <import> tag it finally dawned on me: the error was absolutely correct, but it simply referred to a different file. It was the imported file that couldn’t be parsed.

Yes, lesson learned. Indeed. I’ll never make that mistake again.

8. June, 2007

Regex: match last occurrence

Filed under: Software Development — frightanic @ 22:33

Today, I found myself looking for a regular expression that matches only the last occurrence of a given expression. As I’m still not a regex mastermind I couldn’t come up with it just like that.

The key to the solution is a so called “negative lookahead“. A lookahead doesn’t consume characters in the string, but only asserts whether a match is possible or not. So if you wanted to extract the last “foo” in the text “foo bar foo bar foo” your regex would look like this:

foo(?!.*foo)

If you used the DOTALL option the above expression would even work correctly on a multi-line text such as

foo
bar
foo
bar
foo

Of course the example is not taken from a real life scenario as it doesn’t matter which “foo” is matched as they’re all the same anyway. The expression would with no doubt be more complicated, but I hope you get the point.

Blog at WordPress.com.