Who’s On Phirst

Official blog of Phurnace Software.

Category >> Open Source

Posted by: Wesley Willard on

At this year's No Fluff Just Stuff conference, presenter Matthew McCullough, the managing partner of Ambient Ideas, LLC, gave an interesting talk on Open Source Debugging Tools, which touched on usage of freely-available tools such as cURL. cURL is a command-line tool which supports file transfer operations for a variety of protocols (HTTP, HTTPS, FTP, SFTP, SCP, etc.) and can be used for a variety of useful tasks, such as retrieving the real source page of a web site:
curl -i -H Accept:text/xml http://www.phurnace.com

You can also determine your public IP (useful for those running behind a firewall/router) with the command:
curl -q http://checkip.dyndns.org

This command will return an HTML page with your public IP address embedded.

Okay, here's an example of how you can use cURL to take advantage of Google's mail feed to obtain information about your unread e-mail, without ever using the web browser. In this example, I will show how to take the output from the mail feed, parse it with a Groovy script, and then send a text message to your cell phone number.

First the script:


#!/bin/sh
rm -f /tmp/unread.txt

export PHONE_NUMBER=5555555555
export JAVA_HOME=/usr/lib/jvm/java-6-sun

curl -K .pwd https://mail.google.com/mail/feed/atom/unread > /tmp/unread.xml 

groovy -classpath /home/admin/jars/postgresql-8.4-701.jdbc4.jar \
    /home/admin/bin/Feed.groovy /tmp/unread.xml if [ -e /tmp/unread.txt ]; then echo "Sending notification of unread mail " `date` cat /tmp/unread.txt | mail -s "Unread" $PHONE_NUMBER@txt.att.net fi
This shell script uses a script written in Groovy to parse the curl output. There is nothing particularly fancy about it. It does depend on the -K option to curl to pass in the username and password credentials. This is a more secure method than passing them directly on the command line, or worse, including them in the script itself. If the output file from the Groovy script exists after its execution, the contents are emailed to the cell phone number's text message address. Ideally, this script will run as a cron job, checking the mail feed at a specified interval.

Before you run the script, set up a database called 'mail', with one table 'processed_mail'. The table schema is:

 Column  |          Type          | Modifiers 
---------+------------------------+-----------
 issued  | character varying(100) | not null
 author  | character varying(100) | 
 summary | character varying(255) | 
Indexes:

    "processed_mail_pkey" PRIMARY KEY, btree (issued)

The Groovy script is documented, but in a nutshell, here's what it does:
  • Connect to the database. I am using PostgreSQL in this case, but any database will do.
  • Set up a namespace for accessing the XML elements
  • Create an output file
  • Process each entry the XML file that is passed in as the first argument
  • For each entry, check to see if it has been processed, i.e. it is in the database
  • If it has not been processed, add an entry to the database, and output to the file
  • After processing the unread entries, delete any entries in the database which were not in the unread list
  • Delete the output file if it is empty

import groovy.util.*
import groovy.sql.*;

//
// Setup a database connection
// using Postgres
//
def DB='jdbc:postgresql://localhost/mail'
def USER='postgres'
def PASSWORD='mypassword'
def DRIVER='org.postgresql.Driver'

Class.forName(DRIVER)
def sql = Sql.newInstance(DB,USER,PASSWORD)
assert sql

//
// The XML that comes back needs a namespace
//
def ns = new groovy.xml.Namespace("http://purl.org/atom/ns#")

//
// Process each unread email
// If the unread email has not been processed then
// add an entry to the database
//
def processEntry = { it, outputFile ->
    //
    // Look for an aleady processed entry
    // If found then get out
    //
    def found = false
    def issued = it[ns.issued].text()
    sql.eachRow("select * from processed_mail where issued=${issued}") {
        found = true 
    }
    if (found) {
       return
    }

    //
    // Add the entry and output for the email text
    // 
    println "Issued on " + issued
    def author = it[ns.author][ns.name].text()
    def summary = it[ns.summary].text()
    println "Date: " + issued
    println "From: " + author 
    println summary 
    sql.execute(
    "insert into processed_mail (issued, author, summary) values(${issued}, ${author}, ${summary})")
    outputFile.append("From:  " + author + "\n")
    outputFile.append("Date:  " + issued + "\n")
    outputFile.append("Summary: " + summary  + "\n")
}

//
// Search in the list of entries for the 
// issued date passed in
//
def searchUnread = { dbIssued, entries ->
    def itFound = false
    entries.each {
        def xmlIssued = it[ns.issued].text()
        if (dbIssued.equals(xmlIssued)) {
            itFound = true
            return
        }
    }
    itFound;
}

//
// Process each row in the processed table
// If there is no entry in the list of unread email
// then delete the database row to prevent further processing
//
def cleanupDatabase = { dbIt, entries ->
    def dbIssued = dbIt.issued
    def entryFound = searchUnread(dbIssued, entries)
    if (! entryFound) {
        println "Deleting entry for " + dbIssued
        sql.execute("delete from processed_mail where issued=${dbIssued}")
    }
}

//
// Main body of code
//
def newFile = new File(args[0])
if (newFile.length() == 0) {
   println "Empty new file"
   System.exit(0)
}

//
// Create the output file
//
def output=new File("/tmp/unread.txt")

//
// Parse the input file
//
def parser = new XmlParser()
def feed = parser.parse(newFile)

//
// Gather the entries 
//
def xmlEntries = feed[ns.entry]

//
// Process each entry and output if 
// it has not already been processed
//
xmlEntries.each { processEntry(it, output) }

//
// Clean up the database
//
sql.eachRow("select * from processed_mail") { cleanupDatabase(it, xmlEntries) } 

//
// If the output file is empty then delete
//
if (output.length() == 0) {
   output.delete()
   println "Deleted empty file"
}

This mail feed utility illustrates the usefulness of the combination of a common system utility and a modern script language. This script could be modified to include finer-grained decisions about the destinations of the mail notifications.

Both cURL and Groovy are available on Windows, Linux, and other platforms, so this example can be tried out in almost any environment.

In Untagged 
Comment (0) Read More...


Posted by: Casey Marshall on

Summer is here, which means it's time to cool off in the San Marcos river and escape the Texas heat. It's also time to download a new Eclipse -- Eclipse Galileo (3.5) released today. Phurnace Deliver builds on Eclipse technology, so I follow the latest developments in the community.

I want to highlight just a few of the features that have impressed me the most so far in Galileo, which has much general appeal for Java & web developers.

Eclipse Memory Analyzer
I've been using the Eclipse Memory Analyzer (MAT) for several months now, and it's helped me through some tricky memory leaks. MAT provides detailed memory usage reports and charts from a Java heap dump (created with jmap, for example). In the latest MAT release for Galileo, MAT has added stack frame information to the memory analysis -- you can more easily find where the leaks are, in addition to what's leaking. The new support for IBM JVM heap dumps could prove useful for diagnosing leaks, even in a live WebSphere instance. Once you get Galileo installed, here is a guide on getting started with the latest MAT, with some nice screenshots of the new stuff!

XML Tooling
If you muck around at all in large XML files (IBM WebSphere Portal snapshots come to mind), the new Web Tools Platform (WTP) release is reason enough to download Galileo. You can now test XPath queries directly on XML documents open in the editor and jump to the matching nodes. This has all sorts of potential for XSLT and custom XML parser development, but most importantly, it can be a powerful navigation tool. Read more in Eclipse Galileo: XML gets some love!

And More...
There are over 33 projects included in the Galileo release. For an overview of what else is included in Galileo, check out Eclipse Galileo - A Quick Glance on DZone and Eclipse Galileo Feature Top 10 List on EclipseSource.

In Eclipse GalileoEclipse
Comment (0) Read More...


Posted by: Nate Dillard on

If you're like me and like to keep up with that latest mobile phone buzz, then you've probably heard the Sept. 23 announcement of the first Android phone called the G1 to be released on T-Mobile on October 22nd. If not, Android is Google's mobile phone operating system, based on the Linux kernel which will run on a phone by HTC called the Dream. What makes Android special is that its software platform is open source! Granted there are some criticisms that it is not, currently, completely open source, but Google announced that part of the OS will be released under the Apache and GPL license.

I've been able to emulate Android on my current device, an AT&T Tilt (aka HTC Kaiser), thanks to developers on the xda-developers forums in order to get a taste of what will soon come to be. I recently installed the Android 1.0 SDK and eagerly look forward to coding some applications. I have high hopes for Android as I'm a fan of both Linux and open source software, but only time will tell.

In Open Source
Comment (0) Read More...


Posted by: Wesley Willard on

In the last 10 years, Open Source software has provided an incredible benefit to the software development process. Most open source software projects present quality, well-tested APIs and libraries that can be quickly integrated into a product, providing much-needed functionality that does not have to be developed in-house. While there are too many projects to even begin to mention, the software produced by the Apache Project, and SpringSource provide frameworks and utilities that would take companies man man-years to develop on their own.

There are, however, a few issues that every organization should consider before choosing to include open source software in their commercial products. While these issues are usually not show-stoppers in the decision process, but should be viewed as risk factors. Failure to consider these issues can leave a company with problems that cause development and maintenance nightmares.

First, I would take the time to consider the involvement of the project's community of users and developers. Is work on the project ongoing, or does it seem to be stagnant? Are there discussion forums for the project, and do the developers post to the forum? An active Open Source project community enables you to resolve usage issues, obtain patches, and generally integrate the project more quickly into your product. A less active community can be an indicator that the project has not been well-received, perhaps because of stability, or even issues with its usefulness.

Licensing is a potential Pandora's Box of issues for anyone wishing to include Open Source software in their product. In general, software which fall under BSD or Apache licenses are the safest to use. For example, the Apache License allows free use, modification, and distribution of their software, provided that the appropriate notice is included. A great source of information concerning Open Source licensing issues is the Open Source Initiative. This group maintains the definition of open source software, and vets licenses in order to certify that the license adheres to it. In this litigative age that we live in, no one needs the hassle of a potential lawsuit involving their product.

In my opinion, while there are issues involved in the choice to include open source software in a commercial software product, the benefits far outweigh the drawbacks.

In Open Source
Comment (0) Read More...


Posted by: Shawn Spiars on

When I started working with Eclipse in 2003 I would just download the plug-ins I needed from the Eclipse website, unzip them into my plugins directory, and restart Eclipse. Sometime later, the Eclipse Update Manager was introduced to help you configure your Eclipse development environment providing the ability to update your existing features and plug-ins and search for new features. I have always found the Update Manager dialogs difficult to understand and use. Customizing the Update Manager to work with my Rich Client Platform (RCP) applications has also been very difficult.

When I heard about the new Equinox p2 provisioning system at EclipseCon this year I was excited that the Update Manager was finally being replaced. However, one thing I have learned when working with Eclipse is to take a “wait and see” approach before adopting the newest and improved APIs and methodologies. So, I have been reading various blogs to see what experiences developers are having implementing p2 in their products. Here are a couple of postings that make me think that p2 may not be quite ready for prime time:

Why Eclipse Equinox P2 Update Manager Sucks

Why Eclipse Equinox P2 Update Manager is not good enough for me yet #2

If you have had a positive experience replacing Update Manager functionality with p2 in your software product I would love to hear about it.

-Shawn

 

In Eclipse
Comment (0) Read More...


Posted by: Shawn Spiars on

 Last week I attended the EclipseCon 2008 conference in Santa Clara, CA.  This was my third EclipseCon and by far my best experience.  ThisEclipseCon year there were a lot more technical sessions to choose from and overall the presentations seemed more professional than in the previous years.  I also liked that the Monday tutorials were included in the overall conference registration fee, rather than an extra charge.

I think the highlight of the conference was the key note speech of Dan Lyon (Fake Steve Jobs).   Here's a quote about Dan from the EclipseCon website.

"At his blog, fakesteve.blogspot.com, Lyons has captured the Zeitgeist, from perhaps the one place it is clearest-the point of view of Steve Jobs. In the tradition of Jonathan Swift and The Onion, he uses a pitch-perfect satirical style to deliver trenchant social commentary, reflecting on everything from the Cult of Steve and the rise of Apple ("Dude, I invented the friggin' iPhone. Perhaps you've heard of it!") to the ubiquitous influence of the tech industry on our everyday lives."

Another key note speaker was Sam Ramji, Director of Platform Strategy at Microsoft.   I think of Microsoft as the Borg and their presence at EclipseCon as another strategy to assimilate the Eclipse Community and open source.

The sessions that I found most interesting were those discussing the Rich AJAX Platform (RAP), The Rich Client Platform (RCP), and the Web Tools Platform (WTP).  I particularly enjoyed the "GWT vs RAP" presentation by Mark Russell and Dan Rubel, discussing the differences between Google Web Toolkit (GWT) and Eclipse Rich AJAX Platform (RAP) development.

If you are a software developer I would highly recommend you check out next year's EclipseCon.                 

In Open SourceEclipse
Comment (1) Read More...