The Source for Java Technology Collaboration
User: Password:



Joshua Marinacci's Blog

Community: Java Web Services and XML Archives


A Mapping Christmas Present

Posted by joshy on December 22, 2006 at 10:32 AM | Permalink | Comments (16)

You may get several Christmas presents this year so I'd like to give you all mine first. Best to be early than late and forgotten. :) You can scroll down to the screenshot and link if you want, but if you prefer some delightful Christmas suspense begin reading here. You might want to grab some egg nog first. In fact, adding a splash of rum might help too. We've got a lot to go through.

As you may know from reading my previous blogs we have been working to move the mapping component from our Aerith demo into the new SwingX-WS project. Our goal has been to make mapping easy; so easy that you can drag and drop a component into your Swing app and have something that works with no extra configuration. Sadly.. reality often diverges from our wishes.

Our Christmas Wishes

The JXMapViewer, our new mapping component, is still to hard to use. You still have to build too much of your own code and configuration to get it to run. For many applications you just need a map of the world. Right now, when you create a new map component, you get nothing at all. Nada. Zip. Zilch. Nil! Surely we can do something useful by default!

We need a stable data source. The WMS server from my previous examples has been up and down a lot, so we could never guarantee that it would be there when you need it. I've had some trouble finding a reliable server that would give us good performance. Something stable enough that we would feel comfortable setting that server as the default. That's asking a lot.

It would also be nice to have a prefab application or applet with no Java coding required. One of the great strengths of Google's AJAX offerings is that you merely need to paste a snippet of HTML and Javascript into your webpage to get started. We really need to be that easy!

Three Christmas Presents

So for Christmas we wanted to solve all three of these problems. They aren't perfect yet but you can see where we are going and maybe even help out.

JXMapKit. We've recently added the JXMapKit class. It's a composite component that bundles up a JXMapViewer class with common things you are likely to want such as zoom buttons, a zoom slider, and a mini map. It also pre-configures the map component to use a known stable map server. Which brings us to..

maps.swinglabs.org. We need a stable map server. Nothing I've found so far fits the bill, so we thought: why not make our own! For serving up satellite data it's actually quite easy. We took one of NASA's large Blue Marble images and chopped it up into little 256 pixel square tiles. Currently the server is set to maps.joshy.net, but it will be renamed to swinglabs.org soon. We are using a relatively low resolution bitmap right now (a mere 5600x2700 pixels) but we will upgrade to higher rez soon.

Of course our own server can only deliver so much bandwidth and we don't have the disk space for a full set of ground level satellite photographs. That's why we've been talking to some engineers at NASA. They are very interested in working with us and sometime soon we hope to have direct access to the same map servers that power NASA's super-awesome 3D WorldWind client.

JXMapViewerApplet: The only thing better than writing no Java code is not having to compile it either. We have put together an applet that embeds the JXMapViewer right into your webpage without needing to write anything at all. You will be able to drop an APPLET tag into your webpage, hit reload, and have maps immediately available.

So here it is. Our first mapping applet from Swing Labs.

Merry Christmas!

Run the JXMapViewerApplet
requires Java 1.5
Screenshot of the JXMapViewerApplet

A word of warning: This applet is not optimized in the slightest and the JXMapKit itself still has many bugs. This means it takes longer to download than it should (much longer because I haven't stripped the jars yet) and there are several problems with repainting and keeping the map views in sync.

New features coming next year:

We've got more plans for the JXMapViewer in 2007 and we need your help. Here are just a couple of the things we want to work on in the new year

Applet features. While it's not currently working, we plan to let you add waypoints and configure the applet using PARAM tags or Javascript. No Java coding or compilation required. We'd like to hear from you what kinds of things you'd like to do and what sort of API would help.

Get rid of the jar signing. If at all possible we will make the applet load from the same host as the tile server so the applet won't need to be signed. You won't need to host the jars any more. Just link to our jars and go

Performance, performance, jingle bells, and performance: Stripping the jars will help with loading time but the real improvements will come from completely rewriting the image loading / threading / caching routines.

New data sets NASA has a variety of map sets we could use. What would be most useful to you?

New features that you want!. Ultimately we write code that you want to use. What cool things would you like to do with maps?

Happy Holidays

That's it for me for 2006. I'm having my entire family in town for Christmas and then three days later getting married. It's going to be a busy and fun week. Have a Merry Christmas and a Happy New Year everyone. See you soon!

Josh and Jen in front of their Christmas Tree



Free Projects Part 1: a Screen Capture Uploader

Posted by joshy on November 20, 2006 at 01:09 PM | Permalink | Comments (15)

Screen Capture Uploader

The Screen Capture Uploader, released under the ominous name of Big Brother, is a simple program that runs on your desktop taking screenshots every few seconds, then uploading them to a server. The server then allows you to embed the screenshot, or a thumbnail, in your homepage.

I originally wrote this application and posted it on my weblog about a year and a half ago. It showed some promise but had some security issues (namely that it had no security). The idea behind this app was to demonstrate the sorts of things you could do with Desktop Java that you can't do with AJAX. It also showed how web services and desktop apps can work together to do something interesting.

The code contains the JNLP launched desktop application written in Swing, plus a servlet for receiving uploaded images and a servlet for viewing those images in a webpage. The application itself runs and works, though undoubtedly with many bugs. I built Big Brother on top of an early proprietary application framework called GAF (Grand Application Framework). I don't work on this framework anymore now that we have JSR 296, so the first order of business is to rewrite those parts of it. The framework only provided a prefab Application class and an (very bad) XML layout language, both of which would be quite easy to replace.

This application would be quite good for learning about screen capturing, Swing -> server communication, and how to work with images in a servlet.

If this is something you are interested in, let me know.


Daily Czech Photos

DSC_0061.NEF DSC_0135.NEF DSC_0109.NEF

Total Photo Count:1215!

Secret Project Update

secret-clock-01.png

A quick intro to HttpClient

Posted by joshy on November 01, 2006 at 12:50 AM | Permalink | Comments (13)

The following is a techtip I wrote which wasn't used. Since I turned out pretty well I thought I'd post it here. Let me know what you think. Would you like more of these small self-contained tips?

A Quick Introduction to HttpClient

Java is great because it has classes for almost everything. For example, if you want to open a webpage you can do it with the java.net.URL class. But what if you want to use a POST instead of a GET request? What if you have a bunch of parameters that need to be properly parsed? What if you want to deal with cookies? The URL class simply isn't up to the task. However, in Java, you are always just a single jar away from the solution. In this case, you can use the HTTP Client library from the Apache commons project here. You will need to put the commons-httpclient.jar and commons-logging.jar files in your path.

To use the HTTP Client import the org.apache.commons.httpclient package and get started:

This is how to do a simple POST request

import org.apache.commons.httpclient.*;
...
// initialize the POST method
PostMethod post = new PostMethod("http://myserver/page.jsp");
post.addParameter("parameter1", "value1");
post.addParameter("parameter2", "value2");

// execute the POST
HttpClient client = new HttpClient();
int status = client.executeMethod(post); 
String response = post.getResponseBodyAsString();

You can set up all of your parameters using the PostMethod class and then execute the POST with the executeMethod() on the post object. After the post has completed you can read the body of the response into a string or look at the HTTP status code. The classic 404 error is an example of an HTTP status code. The example above posted with a set of parameters. If instead you want to just post an entire document, say an XML document or SOAP request, then you could do something like this:

StringBuffer content = new StringBuffer();
content.append("");
content.append("information");
content.append("");
post.setRequestBody(content.toString());
client.executeMethod(post);

Now lets say you need to list the cookies set by a website. That's also very easy to do. The HttpClient object acts as a miniature browser. It will preserve all state about the current HTTP session, including cookies, in an HttpState object. After you have connected to the website through a get or post you can look at the cookies set by the webserver like this:

        int status = client.executeMethod(get);

        HttpState state = client.getState();
        for(Cookie c : state.getCookies()) {
            System.out.println("cookie = " + c.getName() + "=" + c.getValue());
        }

Since HttpClient maintains state about the HTTP session you can also use it to log into secure sites. For example, if I wanted to show the file listing my secure webdav server, the same way a real browser would see it, I could log in like this:

	// create credentials to log in
        Credentials cred = new UsernamePasswordCredentials("myusername","mypassword");
	// set the realm to null, meaning use these credentials for all websites
        client.getState().setCredentials(null,cred);

	// get the html doc
        GetMethod get = new GetMethod("http://files.myserver.com/secretprojects/");
        int ret = client.executeMethod(get);
        System.out.printlin("a browser sees = " + get.getResponseBodyAsString());

The HttpClient library is very powerful, enabling you to perform almost any HTTP task such as GETs, POSTs, getting and setting cookies, handling redirects, going through HTTP proxies, and even HTTPS authentication. And best of all, it is freely available under Apache License. You can download the HttpClient library at

http://jakarta.apache.org/commons/httpclient/



The Power of the Desktop Java Stack

Posted by joshy on May 17, 2005 at 08:20 AM | Permalink | Comments (7)

Big Brother, a screenshot client + webservice

The last year or so has seen a lot of growth for Java on the Desktop. The peformance, features, and deployment story is getting a lot better, but to what end? So we have a killer platform that lets you build cool desktop applications. So what? What can you do with it? More importantly, what can you do with it that you can't do (or can't do as easily) with another client solution like .Net, C++. What about webapps? What can we do with Java that we couldn't do easily with Perl, ASPs, PHP, Javascript and HTML? Well, this is sort of a trick question. I've asked: what can we do that is better than other client side or server side technologies allow. The answer is to be on both sides at once.

I've built an example application to show you what I mean. It's called Big Brother and it watches you. More specifically it takes captures of your screen, generates thumbnails, then uploads the images to a webservice that lets you link to the image from another webpage. It contains a webservice with a simple REST-y API (basically one POST and one GET) and a JNLP launched application to take the screenshots and do basic configuration. Here is a live view of my own desktop, updated every 10 seconds. When I'm not logged in then the thumbnail is still there (on the webserver), but won't be updated until I log in again.

A live view of my desktop

Easy for Developers

My goal was to make it as simple as possible for both programmers and end users. As a programmer you get a simple API that you could call from any language, not just Java. However I've provided a Java client that looks pretty good and will cover most needs. You can retrieve images using another GET call and submit then with a POST (with the image Base64 encoded). There are usernames but no passwords since I wanted to make this as open as possible. It's just a technology demonstration so it should be easy for new developers to get started. There's a great set of posts on O'Reilly, here and here about how to make APIs as open (and sucessful) as possible. I highly recommend you read them if you plan to make your own publically accessible web service.

Easy for End Users

For the end user, it's an auto-launched application that has as few options as possible. It tells you where your thumbnails will be stored, allowing you to embed the image in your own homepage with just a link. The user doesn't need to know about programming or how the webservice works. Just drop a link in your homepage and you're done. Couldn't be easier!

Easy to develop

The most amazing thing about the app isn't what it does, but how easy it was to build. BigBrother took me four hours to make. The vast majority of this time was figuring out how to safely get a binary file to a servlet using a post (I found a single class implementation of Base64 encoding that did the trick very nicely). I have since spent time tweaking the UI, adding features, finding graphics, and making a website; but the app itself was up and running very quickly.

With Swing, Java Web Start, and Java2D on the client, Servlets and JSPs on the server, and great network classes inbetween, we have a complete development stack. Everything you need to build a killer app is right there. You don't need to use another language, and almost any missing feature can be found in an easily integrated 3rd party jar. And because the Java stack has such great standards support you aren't restricted to just Java either. You can write the client or server portion in another language that supports the usual webstandards of XML, HTTP, HTML, etc. I could even embed a scripting language into my app, letting other developers hack on it.

Application Ideas

If rich clients are going to replace (or, more likely, enhance) existing web applications then they need to do things that webapps can't. I've been thinking along these lines for a while, looking for interesting applications I could build which would leverage the strenghts of Java on both sides of the NIC and make something new. Some sort of a hybrid application. Here are some idea's I've come up with. These are just play things, but get us thinking in the right direction.

  • Control iTunes remotely from the web. We've got the hooks already.
  • Deploy a pre-configured VNC client with an SSH tunnel to let me fix my mom's computer.
  • make an iCal like app for ToDo lists. Publish the lists via FTP, WebDAV, etc. You can edit your lists using the rich client, and then share them using a web page or a rich client.

To find out more about Big Brother go to the home page. To Launch Big Brother right now using webstart (it's signed and needs system access to take the screen shots), then start it here.

The obligatory screenshots:





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds