Tuesday Jun 12, 2007

Chapter 1 - A Standalone Dean Edell Downloader

This chapter can be downloaded here.

This zip file has the entire Chapter1 NetBeans project in it. I highly recommend using NetBeans 5.51 for this tutorial. And of course you are going to need GlassFish

The first thing that we need to get working is the automatic downloading of the Dean Edell mp3 files. We're going to make a simple stand-alone Java SE application to do the downloading. We will then create a simple script to run the java application. After testing it to make sure all is well we'll get the operating system to call it every Monday through Friday night at 11:30 PM PDT.

The Java Technology Portion

The source consists of two files:
  • HTTPDownloader.javaA simple class that takes a URL string and a filename string. It fetches the file that the URL is pointing to and writes it to the filename. This is where Jaca Technology really pays off. It's ridiculously easy to do.
  • DeanEdellDownloader.javaThis class is also pretty simple. The most difficult part is assembling a distinctive filename based on the date.
DeanEdellDownloader uses HTTPDownloader to fetch the current Dean Edell mp3 file. It refuses to run on weekends. The URL and the location to write the mp3 files is hard-coded here. That's OK in this scenario because we are going to build it once and forget about it.

You will need to change the value of one variable in DeanEdellDownloader. The last line of the file contains the target directory from my GlassFish installation. Replace it with your path:

private final static String DEFAULT_DIR_HTTP = "C:/as/domains/domain1/docroot/DeanEdellFiles";

The Script

NetBeans automatically put a manifest file pointing to the correct main in the jar file. On my Windows system I put a script in DeanEdell.bat in a scripts directory. The command in the script is:

java -jar path-of-jar-file

Run the script. A 10.5 MB mp3 file should appear in [domain]/docroot/DeanEdellFiles (unless it is the weekend!)

Calling the Script Automatically Forever

If you are on UNIX or Linux you are on your own here. You need to create a chron job that runs the script Monday through Friday around 11:30 PM PDT. It's OK to run it on weekends too -- it won't do anything.

On Windows this is super easy to do: Go to Control Panel and then run Scheduled Tasks. It will take you by the hand and guide you in making a chron job. Just have it call the batch file every Monday through Friday around 11:30 PM PDT. Make sure you enter your account password.

And that's all there is to Chapter 1. We now have DeanEdell mp3's appearing automatically in a folder under docroot inour domain.

Next Installment: Chapter 2 - Create a Web Application to serve up the files

Monday Jun 11, 2007

Let's Get This Glassfish Party Going!

This is the first chapter in a n-chapter tutorial on how to exploit Glassfish capabilities. I learned long ago that the only way I can really cement into my head a hunk of technology is to just do it. I came up with a useful application for web technology. In this series we will be building an application that will slowly but surely use these areas of javaee. They are in the approximate order that we will tackle in the project.
  • HTTP File downloading (HyperText Transfer Protocol)
  • Servlets
  • JSPs (Java Server Pages)
  • User Authentication - Basic, then File Realms, then JDBC Realms
  • Derby Database
  • JNI (Java Naming Interface)
  • EJB 3.0 (Enterprise Java Beans)
  • JPA (Java Persistence API)
  • EJB Timer Service
  • Struts
  • JSP Tag Libraries
  • MDB (Message Driven Beans)

Chapter 0: The Application Description

Dr. Dean Edell has an interesting radio talk show on KGO radio in San Francisco. His show is from 1 to 2 PM Monday through Friday. KGO posts an mp3 file for the show once a day. KGO takes it down, forever, after 24 hours. KGO does not maintain an archive of old shows. I like to burn the shows onto CDs and listen to them in my car. What this application will do is:
  • Automatically download the mp3 at 11:38 PM every night, Monday through Friday and save them to a subdirectory of docroot on my Glassfish Application Server.
  • Maintain user accounts for people that wish to download the files. New accounts will be accepted and added to the list on demand.
  • The application will persist which files have been downloaded for each user. When a user is authenticated he will see his own custom list of programs he has yet to download.
  • A list of all available programs will also be available in case of trouble (like the dog eating the Dean Edell CDs)

This sounds like a lot of overkill for such modest sounding requirements. But making it 100% automatic is a bit challenging. Besides, the whole point of this is to create an application - any application -- in order to learn how to do all this stuff. We will start simple but thorough and correct. We will constantly change and modify it to use the cutting edge Java EE technology as the tutorial progresses.

Stay Tuned for the next installment, Chapter 1:

Write a stand alone Java application that will download the mp3 file. The OS will be in charge of running this application via a chron/at job.

About

ByronNevins

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today