Friday, April 23, 2010

The Holy Grail of rapid application development

Lately I've been toying with the concept of rapid application development with little to no code-writing.

  1. Gather your business requirements
  2. Model your business objects
  3. Diagram/design your use-case flow
  4. Press the big green "win" button
  5. Deploy and profit
I'm aware of IBM tools (and others) that have attempted this concept with very limited success, but if I can pull this off on a pilot project via my own tools, I'd like to bring this notion to fruition and train my developer unit to begin developing applications this way.

Okay, allow me to refine the list above. Here's how I've been making this happen:
  1. Gather your business requirements
  2. Define and model your business objects via UML Class Diagram
  3. Design the rest of your app via detailed and complete UML Class Diagram
  4. Use an IDE such as MyEclipse or Netbeans to generate Java code directly from your class diagram
  5. Use Hibernate's JPA implementation and annotations to allow Hibernate to generate your database schema entirely from the POJOs generated in step 4
  6. Use MyEclipse & Hibernate's Reverse Engineering to generate all of your Data Access Objects (DAO).
  7. Fill in the blanks, implement business algorithms where necessary
  8. Deploy, test, refine.
In combination with an MVC framework like JSF, it seems that the only blanks you'd need to fill in (step 7) are the backing-bean action methods. What happens when each button is clicked is up to you, but at that point in time, all you'll be doing is tying together business objects and passing them back and forth between DAO methods, which you didn't need to take the time to write either.

Strap some rich PrimeFaces components into the view and you've got yourself a rich business application with little to no Java code writing at all.

In my fantasy world, where I've yet brought this concept to life, I imagine 6 months development projects taking 3 to 4 months tops. You'll still have all the same testing and bug-fixing as ever, but an increased level of design will leverage exponential gains in development time. If you're a seasoned developer, you've seen design pay off during development over and over again.

If I can find the time to run a pilot project behind the scenes and pull this off, I'll check back in and write up a conclusion!

-Lance

Monday, July 27, 2009

Getting Image Dimensions with Java

Retrieving the dimensions of an image file is a pretty common requirement for a web application. My current project is no exception, and needed to run a validation on uploaded images to ensure their width and height are not too big.

First, I tasked myself with learning to use the javax.imageio api to read through the metadata of an image file. Although this was doable... it was cumbersome. If all you'd like to do is find the image dimensions, you need to iterate through an awful lot of irrelevant information just to find it. After about 80 lines of code, I decided that was not the way to go.

The solution was this:
Image img = new ImageIcon("C:\\prototype.jpg").getImage();
System.out.println("width is "+ img.getWidth(null) );
System.out.println("height is "+ img.getHeight(null) );

Wow. Three lines of code. I think we've got a winner. You'll only need two imports to make this happen:
import java.awt.Image;
import javax.swing.ImageIcon;

This does, obviously, depend on you having the file written to local disk. If you don't (perhaps the file has come through the HTTP Request and is only in RAM), then I'd suggest writing it to the system's temporary file directory, so that you may get the dimensions while it's on the file system, but it will be deleted later. You may get the system's temporary directory like this:
String tempDir = System.getProperty("java.io.tmpdir");

Good luck. =)

Thursday, May 21, 2009

WebScarab and WebGoat - learning security!

Application Development: the funnest job in the world, right? But how do you feel about that fun when early in your career you first encounter the classic adage: "80% of your code will run only 20% of the time?" Bullet-proofing your code can be a real buzz kill for the wonder lusted developer.

Well fret no more. Securing an application isn't a tedious bore - it's an opportunity to step into the exciting shoes of a web hacker/cracker and have yourself a truly fun learning experience. I've spent the last two days using WebScarab and WebGoat, both open and free software provided by OWASP, as reliable (and awesome) learning tools to hack legitimate applications:
  • Tamper with request parameters on the fly
  • Embed Cross Site Scripting (XSS) attacks and Injection attacks to hijack sessions and elevate application authorization (make me an admin, please... woot. )
  • Manipulate requests to take advantage of vulnerabilities in Web Services.
the list goes on, but honestly I had the most fun just tampering with hidden input fields, altering drop down, and adding parameters to a request. I was able to do some amazing stuff, including hack into admin accounts and cause my own application to kick off emails in a malicious manner... A true learning experience.

Enough gab Here's the deal:

WebGoat:
This is a well designed application that is built to contain vulnerabilities on purpose. It is ready for you to do some Cross Site scripting and other common hacks on it, and feel the thrill of hacking into a system! It downloads and runs on its own servlet container right out of the box.
->Download here: http://code.google.com/p/webgoat/downloads/list
->Install Instructions here: http://www.owasp.org/index.php/WebGoat_Installation
At this time, version 5.2 is the latest release. Download the zip, run the batch file, and access the app at your localhost domain, running on either port 80 or 8080 depending on which batch file you ran. It's that easy. Linux users may want to check out the documentation I just linked above.

WebScarab:
This is a tool which will intercept your outgoing HTTP Requests and incoming HTTP Responses, giving you a chance to change them any way you like as you go. You just filled in a username and password? Let's see what happens when you decide to add onto the request a cookie that you stole from someone else's session, logging you in as them...
->Download here: http://www.owasp.org/index.php/Category:OWASP_WebScarab_Project#Download

I am failling to find good instructions for this tool, but it's not hard to figure out. It's most compatible with firefox, so don't waste your time with IE. Simply change your firefox proxy settings to point to localhost, port 8008 (and remember to clear out the NO PROXY FOR field!!), fire up WebScarab, and click the "intercept requests" checkbox within WebScarab. WebScarab will act as a proxy, but if you use a proxy to the internet anyhow, then you'll need to tell WebScarab which proxy to forward to... Simply click the Proxies toolbar at the top of WebScarab and punch in your proxy server address. Port 3128 is pretty standard for a proxy.

Have fun guys

Thursday, February 12, 2009

JavaFX: immature

If you're reading this now, you're one of two people:
  • A Flash advocate, wondering what competition JavaFX might be bringing to the table
  • A Java developer, looking to see how your existing skills might now make you capable of creating flash-like web RIA's.
Well, I am the latter.

In my web development with FreeLance Webs, my customers often desire "Flashy" and graphically intense websites, in order say to the potential customer, "We are amazing! We are serious! We know how to stun you graphically!" It's no secret that a customer won't take you serious if your website looks like a 1995 AOL Special.

This has led me to working with Adobe Flash much more than I'd ever have liked to. Ranging from full-flash sites, such as xpandinc.com, to little flash animations such as weberslandscaping.com and the animated limousine at motion-limo.com, my experiences have always been painful ones.

So when I heard about JavaFX, my interest was peeked. Can I now develop the same flashy interfaces for my customers, but with the ease of the Java environments I'm used to?

Well I don't have a conclusion yet. I intend to blog at a later date when JavaFX is a little more mature and some kinks are worked out. Here's some of the kinks I've hit so far:

  • All JavaFX demos I've found so far (that work) are essentially a runnable Java download, which then runs in its own window, outside of the browser. This is not what web developers are looking for.
  • JavaFX runs on your JRE plugin for your browser, and I'm hitting a lot of JavaFX demos which won't run for me. I'll get a message saying that I must download JRE 6.0, I'll then download and install the JRE, and then the JavaFX Demo will not run at all. I'll sit and watch some stupid "loading cycle" spin infinitely:
Hopefully I'll be reporting back with something a little more impressive from JavaFX. So far, it only seems to be a matter of distribution and deployment which thwarts them.

Monday, October 6, 2008

Get the Alphabet with Java!

This may be an embarrassing thing to admit, but I was momentarily stumped this morning when I had a need to iterate over the English alphabet with Java 1.5 ... I've been a Sun Microsystems Certified Java Programmer for 3 years now, yet this little thing got me!

Well, here's my solution, which I'm posting up now in hopes that someone with the same need may do a google search and find this post =)

char letter;
for (letter='a'; letter <= 'z'; letter++) { System.out.println( letter ); }


Simple, right!?

If you find this helpful, please leave a comment and let me know!

Wednesday, July 23, 2008

MyEclipse 6 HTML Editor!

My Adobe DreamWeaver CS3 subscription expired the other day, and only moments before having to deal with an urgent client request for a website change. This was nothing server-side related, just a static change to a page.

3 years ago, I would have popped open a MS Notepad and made the change within the archaic wall of text presented to me by an ancient ANSI editor... But I've grown enough since then to learn that being efficient with a tool is far more important than being cool enough to work without a tool.

So, in my limited amount of time, I scrambled for a quick way to make my change with a tool, but without DreamWeaver. I forgot I had installed MyEclipse 6.0.1 on my machine months ago, but noticed it when right clicking on the file needing editing...

"Edit with MyEclipse 6.0.1 HTML Editor" ... Hmmm... Sure, I'll try that.

BAH-DA-BING! An exact wysiwyg representation of my page popped up and displayed my page more accurately than DreamWeaver ever did. The wysiwyg lacked a lot of the common shortcomings which most suffer from. I was so impressed by how smooth this tool was, that I went on to develop my next client's entire website in ME 6. You can see that work at motion-limo.com.

In conclusion, I have found that ME6 makes a better Visual HTML Editor than DreamWeaver does, even if it does lack some of the easy FTP features and things which DreamWeaver offers. I'll be saving my money from here on out and sticking with ME6!

Friday, March 7, 2008

HIBERNATE!

You've got fictional objects, in an abstract world. It is these very abstract objects, conceptualized in your mind and painted onto your canvas known as RAM, which holds all the key data of your application.

What is your user? An OBJECT!
What is their car? An OBJECT!
What is their login date? An OBJECT!
Their address?? OBJECT!

But how do we turn these abstract thoughts in memory into persistant physical data?? KABLAMO - HIBERNATE! Hibernate says "Give Me You're object, I'll store it away, and you just let me know when you want it back."

Hibernate maps to any popular database, even if only remotely popular. So far I've mapped to Oracle, MySQL, and HSQL. Sometimes even simultaneously, although not in a managed environment.

Now I've got ambitions of using some reflection to develop my own ORM. It just sounds fun. If I were to developer my own ORM, I'd name it:
stORM