My Daily Conversations with Eclipse

Having now converted my development environment to Eclipse, I’m going through the normal growing pains associated with going from a total command line “edit, save, exit, compile, look at error, re-edit…” cycle to a totally integrated interactive IDE. The last immersion I did in this type of environment was using Turbo Pascal 7 somewhere back in the mid 90’s.
Mostly it’s going okay, but I’m sort of entertained at the ‘compile on the fly’ functionality that Eclipse has. Errors are shown immediately, not at compile-time, so you can see the state of your app at any moment. I just find some of my conversations with Eclipse amusing. The ‘Problems’ pane at the bottom of the screen shows the current state, and I feel like I see this sort of convo happening all the time:
dbs – typeitytypetyptyp type type. think. typetype
eclipse – Warning: variable foobar is never used.
dbs – yes yes, i know. I’m still working on it.
eclipse – Warning: you type too slow.
dbs – You’re not helping.
I’m sure it’s only a matter of time before the “Dave. Your code is absolute garbage.” HAL-like plugin will be available.

What I do…

In the midst of hyper-geekery today, Barb msgs me and asks what I’m working on.
So I answer…

publishing WSDL-driven servlets into an Axis environment to expose J2EE stateless session beans’ methods via webservices – then i don’t have to have the client apps deal with JNDI and RMI calls directly to the jboss server, they can just use SOAP calls, browsing via wsdl.

And just realized how much that looks like total gobbledygook. No wonder I sometimes feel like I’m in my own little world.

Mambo patching – a brief interlude

So one of my many hats involves helping out running the Arisia website. We changed the site over to being managed by Mambo several months ago, and have been ‘mostly’ happy with it, though it has its quirks.
One quirk raised its head today. We couldn’t upload files via the media manager other than graphics and pdfs. One of the users wanted to punch up a preformatted HTML page, and the system was not allowing it.
After digging around the code, I found the culprit. The system was hardcoded to only accept certain extensions, and I have to admit, the code that did it was… er… painful:

if ((strcasecmp(substr($file['name'],-4),".gif")) && (strcasecmp(substr($file['name'],-4),".jpg")) && (strcasecmp(substr($file['name'],-4),".png")) && (strcasecmp(substr($file['name'],-4),".bmp")) &&(strcasecmp(substr($file['name'],-4),".doc")) && (strcasecmp(substr($file['name'],-4),".xls")) && (strcasecmp(substr($file['name'],-4),".ppt")) && (strcasecmp(substr($file['name'],-4),".swf")) && (strcasecmp(substr($file['name'],-4),".pdf"))) {

Ew. Just. Ew. Bleah. Ick. In the immortal words of Tim Allen… “So I rewired it!” :

# The valid file extension list is:
$validList="fluff|gif|jpg|png|bmp|doc|xls|ppt|swf|html|htm|rtf|";
$fileInfo = pathinfo($file['name']);
if (! strpos($validList,$fileInfo['extension'] . '|')) {

Muuuuch better. This patch goes around line 139 of admin.media.php, if folks are looking for an update.

Does this make ANY sense?

I’m not a computer scientist. I didn’t go to school to get letters by my name to learn how languages are built and designed, and I never wrote a compiler in my life. I’m just a fairly high end programmer who writes in high level languages, and builds large applications.
I’m certainly a big user of PHP – less so recently, but since Claimit is written in it, I’ve been getting my wheels back on it.
But, occasionally I run across design decisions that just don’t seem to make sense. Case in point, the ‘asort()‘ function. It sorts an array, in this case backwards (as opposed to sort). One would assume you’d use it like this:

$sortedArray = asort($oldarray);

Not so! This function works, does not throw any errors, but the resulting value in $sortedArray is ‘true’ (or ‘1’). The asort function returns a BOOLEAN value (successful completion of a sort??) What actually happens is the asort() function reorders an existing array. So in order to have a new version of the array sorted, or to sort the result of a function call, you use this tortured syntax:

asort($sortedArray = $oldarray);

In my case, I’m actually sorting the returned array from a function call, so we have:

asort($sortedArray = getFiles())

I understand this is a Perl-ism. That doesn’t mean it has to be perpetuated further on the masses. Ick.

Java JBoss Geek Trick du jour

I’m doing a lot of work in JBoss, and one of the bugs I’ve run into is that if an applications initial deployment fails, JBoss refuses to un-deploy it. It throws this error when you try to redeploy the app (in this case, the app is called ‘app1’ and is deployed as an EAR file) :

23:19:23,054 ERROR [MainDeployer] Could not initialise deployment: file:/home/dbs/jboss/jboss-4.0.1sp1/server/default/deploy/app1.ear
org.jboss.deployment.DeploymentException: Error in accessing application metadata: ; - nested throwable: (javax.management.InstanceAlreadyExistsException: jboss.j2ee:service=EARDeployment,url='app1.ear' already registered.)

Sometimes restarting JBoss appserver from scratch will fix it, but only if you’ve remembered to delete the .ear file before restart.
JBoss comes with a great little tool called ‘twiddle’. It sends commands via JMX right into the appserver. You can force an app to unregister right from the command line:

twiddle.sh unregister jboss.j2ee:service=EARDeployment,url='app1.ear'

Voila 🙂

The J2EE vs .NET argument

I’ve had a couple conversations with people regarding .NET vs J2EE as a choice for application development and deployment. From a purely technical standpoint, the two technologies are very similar. The tools are powerful and detailed in both environments, and the end result is a distributed, object-based application platform.
But to me, taking the ‘C# is just like Java’ argument doesn’t actually address the underlying problem of a Microsoft vs Not-Microsoft solution. It took me a bit, but I think the best way to summarize it is thus:

The purpose of C# and .NET is to make money for Microsoft in tools, platform, and training sales. The purpose of J2EE is to get the job done. No one automatically gets rich when you decide to use J2EE as a platform. Which would you rather invest your time and money in, something where everything from the operating system on up to the deployment tools cost money, primarily to Microsoft, or a platform where the entire system can be designed, developed, distributed, and deployed on free software with the same level of stability and functionality? If support and training is important to you, then pay the people who know best to train you and support you, but you should not be charged just for your choice in platform.

So there.

Web Developer Firefox Plugin

I do a fair amount of ‘web development’, meaning I tend to write things that are viewable via a web browser. Whether they’re posted on my blog, or on other sites I sometimes maintain, generally my preferred ‘user interface’ is a web browser.
I’ve been using a plugin for quite a while called “Web Developer Extension“. It’s a set of tools that integrates tightly with Firefox and lets you do all the things a web developer needs to do to make sure his or her application is displaying properly.
The most useful feature I’ve found is ‘Outline block elements’ and ‘Display ID and Class Detail’ – these functions change your displayed page and draw lines around all your block level elements (such as ‘div’ and ‘table’ and ‘span’), and can also label them with what class and ID they are.
When dealing with multiple nested CSS elements, this sort of display can save HOURS trying to track down what element belongs to what container, particularly when working with content management systems like Movable Type.
The plugin is non-intrusive, and is only triggered when you select it off the menu. I can’t imagine doing web development without it.

CSS noodling, PHP coding, and other geek fun.

I’ve just arisen from my death-like existence for the past 2 days, and it appears I’ve just about shaken off the evil cold that has had me in it’s grips since Sunday night. I wasn’t even able to read email for more than 5 minutes without getting woozy. Talk about tragic.
So, in a burst of “I’M BACK!” I’ve done a bunch of LONG needed updates to Planet-Geek and the MT Comments Counter:

  • Fixed the Comments preview function so it actually renders properly.
  • Revamped the color scheme in the individual archive view – so comments and their authors are no longer in that weird green tint. Not sure what I was thinking there.
  • CSS layout on individual archives and the main page were blocked wrong so it was very easy to have the ‘links’ sidebar disappear, relegated to the bottom of the page. This should be fixed so that sidebar will only move if you make your browser VERY narrow (comments on this please, I’m only evaluating with Firefox).
  • We still don’t have TypeKey support enabled, but we’re still working on it! Anyone who has suggestions on how to get it working properly in MT 3.14 I’d love to hear it.
  • On the MTC counter, I’ve changed from a single-image stream function to generating the graphic totally on the fly. This allows multiple-digit displays for very comment-heavy postings, as well as removing the need for a directory full of graphic images.

A good few hours of noodling. Check it out, let me know if anything needs tweaking, or if things just Look Terrible [tm].

Java+Jboss+Hibernate rant

Warning. This is a rant. This is the result of several weeks clawing up the learning cliff on this environment, and it’s really wearing me down. You have been warned.
I’m have a Hard Time [tm] [reg us pat off] implementing stuff in this environment. The complexity level is enormous, and no one really has a good clue on how to do it properly. The level of knowledge needed to implement even a basic application is astronomical, and the number of ways it can possibly go wrong are mind boggling.
The simple thing is, this shouldn’t be that hard. I have a JBoss J2EE server. That’s an application server environment, you’re suposed to be able to deploy your applications into it, and they’re in a managed, hosted mechanism. Sounds simple, right?
Well Jboss (as well as other J2EE containers) provide various hooks and services for the applications they host. The problem is, those hooks and services are not well documented, and are so generic trying to fix a specific problem is maddening.
In this case, I’m using the persistent object engine that JBoss supports (Hibernate), and I can’t even get a a simple “Create this row in that table” working. Why? Because here’s what has to happen to run an application that creates One. Count ’em. One row in a SQL table managed by hibernate.

  1. The sessionbean needs to be created
  2. The Hibernate mappings definitions need to be written
  3. The baseline object for the row needs to be written
  4. The Hibernate configuration XML file needs to be put in place.
  5. The MySQL JDBC connection has be implemented
  6. Jboss needs to be told to provide that JDBC session as a service, and mapped into JNDI
  7. The application archive (EAR) file needs to contain all components of the application, including the deployment descriptors, the servlet definitions for client access, and all the EJB pieces, which are plentiful in their own right
  8. The database has to have the schema configured
  9. The app has to be deployed and you PRAY that that all works when it’s dropped into the appserver. Watch the logs for all the errors.

Once that’s all deployed, you try it. The servlet is the ‘easiest’ way to access an EJB, so hit the servlet. The servlet has to call the EJB, which in this case is a Stateless Sessionbean, by far the EASIEST (COUGH) type of J2EE object to work with. The bean in turn is supposed to ask Hibernate for configuation information, session details, and talk to the managed datasource connection in JBoss.
But lo! There’s a problem! This is a MANAGED environment. That means it must have transactions. JBoss has it’s own transaction manager (JTA), which has to manage all commit/rollback actions. But, since JTA is acting as the manager between Hibernate and the database, certain things can’t work. Like, oh, the basic “auto-increment the primary key” id that every database on the planet uses. Hibernate keys data based on a unique key. It comes iwht a simple ‘hilo’ mechanism that will generate those keys whenever you create a new instance of the persistent object, but THESE DONT WORK IN JBOSS. You have to MANUALLY write your own key generator for every type of object you need to instantiate.
This is INSANE. Now I have to deploy a whole new EJB just to manage the persistent object keys in Hibernate.
“Gosh Dave. That sounds silly. Why doesn’t someone write that into the system?”
Why? Because every webpage I find either says “oh, this is easy, just whip up XYZ to manage it.” or says “Use XDoclet to create this” (yet another system I’d have to learn just to generate the code to manage the objects i’m creating).
While I understand that huge flexibility in Java is a good thing, this level of abstraction and complexity really is driving me absolutely batshit. I just want to settle down and write my code, but finally, after getting Hibernate to actually CONNECT to the database and show that things are ready, I’m faced with the unhelpful error that looks like this:

12:36:50,522 INFO  [SessionFactoryObjectFactory] Bound factory to JNDI name: java:comp/env/hibernate/SessionFactory
12:36:50,522 WARN  [SessionFactoryObjectFactory] InitialContext did not implement EventContext
12:36:50,532 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
12:36:50,533 ERROR [JDBCExceptionReporter] You cannot commit during a managed transaction!
12:36:50,534 ERROR [JDBCExceptionReporter] Could not save object
java.sql.SQLException: You cannot commit during a managed transaction!
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:499)
at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:451)
at net.sf.hibernate.id.TableGenerator.generate(TableGenerator.java:126)

It’s enough to make you cry.
Update, 1/2 hour later – there’s a little-documented function in the Hibernate XML spec. Click through for details.

Continue reading “Java+Jboss+Hibernate rant”

Java Geek Trick du Jour

I’m trying to compile some sample classes to learn how to use Apache Axis the Java webservices system. Part of Java is that it needs to know where to load class libraries from. This is normally set by the CLASSPATH environment variable.
Java stores class libaries in ‘jar’ files, (java archive). Unfortunately, some apps need dozens of jar files to compile / run, and the CLASSPATH variable can only point to individual JAR files, not say “This directory full of jar files”.
So a fellow on #java suggested this:

export CLASSPATH=`echo mydir/*.jar | tr " " ":"`

Cute. Loads up the CLASSPATH variable with all the jars in a directory.

Snapshot of a coder’s brain while working…

Setting: headphones on, listening to Radio Paradise. The entire office is now empty, boss has left with a ‘lock up’ tossed back over his shoulder.
Said programmer is locked in a deep conversation with ‘hunter’, the laptop, which is at the moment doing many things, one of which is attempting to run a small program that asks the local webserver for a simple answer. P is the programmer, H is the anthropomorphized (only slightly) answers from the program.
P “Connect”
H “Error”
P “Connect”
H “Error!”
P “Why is that showing a null?”
H “Error.”
P “But you should have gotten an answer.”
H “Error.”
P “Well, what was in the response?”
H “null”
P “What? But you should have thrown an error.”
H “”
P “Owait, you were calling a servlet on a webserver. what was the HTTP response code?”
H “404”
P “Ah… HAH!”
H “Error.”
Such is the mental processes after 10 hours of Java hacking. Liberal delivery of nummy food to said programmer has been scheduled.

Slowly I learn… Step by step…

I’m learning again. I mean, really learning stuff. Working with the folks down in NJ and learning things that I really want to learn. Things that not only make it easier for me to represent my ideas to my temporary employers, but also make me more marketable and give me a broader base.
In the last 2 weeks, I’ve increased my knowledge on the following topics a hundred fold:
J2EE, JSP, Hibernate, EJB, Object Persistence in Databases, Rich clients, DotNet, Eclipse, JBoss, WebSphere, Ant, Servlets, RMI, JNI, JMS, SOAP, WSDL, and general XML concepts.
Man this is cool

Moving into the next age of geekery.

For quite a while I’ve been wanting to move into some of the more widely used methods for writing and deploying large-scale apps, particularly in Java. Sun developed a system called J2EE a while back that provides an environment where Java apps can scale to incredibly large installations. Up until now, I haven’t had the opportunity to really explore it

I recently started a 4 month project with a company in NJ to explore the feasibility of porting their applications from a Visual Foxpro base into J2EE. This is really a fantastic opportunity. I’m not only helping a great project move into an exciting new environment, but I’m also getting the chance to learn something I’ve been interested in for ages

One drawback though is that the J2EE environment is huge and fairly complex, and therefore there’s not ‘one way’ to do things. J2EE provides an object-based application server that’s designed to let you design and implement virtually any system and do it big. The steps I’m taking now are determining what aspects of this system are appropriate for us to use, and how to use them

This process is not helped by the fact that I don’t KNOW J2EE at all. I’ve never used these technologies myself for my own application development, and I’ve only brushed up against some of their technologies at a previous job. My work on CONGO used a hyper-simplified version of this concept, so there’s a heck of a learning curve here.

I am making progress though. Part of this project really requires the environment to be workable from someone who has traditionally been using Microsoft Visual Studio applications. That means a clean IDE, object editor and browser, etc. Tonight I successfully configured Eclipse to use a plugin to manage the JBoss application server I’m running on my laptop. Following some tutorials, I built and deployed a servlet to the server, and, via an Apache module used to connect Java servlet containers to web servers, I successully ran the servlet, and got those wonderful words… “Hello World”.

Seems like a lot of work to get 2 words on the screen, eh? But that’s the joy of learning a whole new environment. It doesn’t look like much, but it represents a big step down the road to understanding how I (and my client in NJ) may use this system to write and deploy applications. Personally, I’m okay as long as I don’t get stuck, and continue moving forward.

This coming week I hope to have enough in place to get a full JSP->Servlet->database process working, so that I’m familiar enough with the environment that I can start looking at designing how things REALLY work inside the appserver

An ‘Ah HAH!’ moment

I don’t talk much about what I do. Basically, I’m an application programmer. I write user-level apps that help folks do a specific task – that task generally being something non-geeky. (as opposed to system programmers who write things for other programs to use, or the like).

Today I was hung up on an annoying SQL problem where a task to update a ‘state’ table with all the registration, badging, checkedin information, etc – was acting wonky. It would look like it would work, then later it would show the wrong data.

It turns out a second instantiation of the call would -alter- the results set up by the first. So, one run would do the right thing. A second run on a different event would alter the data from the first run. The issue was I wasn’t constraining the update enough to limit the scope of the changes, so it was running roughshod over previously existing data.

The corrected query:

153     sql = "UPDATE reg_state,reg_history SET " +
154             "reg_state.state_badged = 1 WHERE " +
155             "state_registered=1 AND state_rid=hist_rid AND hist_actcode='BADGED' AND " +
156             "hist_cid=" + cid + " AND " +
157             "hist_rid=" + rid ;

This problem has been banging around in my head for 2 days now, I’m ecstatic that I finally nailed it down. Now I can go to lunch.

This brief snapshot into Dave’s Brain has been brought to you by…