Join 3,512 readers in helping fund MetaFilter (Hide)


How to create a custom Java protocol handler?
April 3, 2008 4:36 AM   Subscribe

Is there an easy (no programming!) way to create a custom protocol handler for Java on XP?

I'm using the Java-based mindmapping application FreeMind, and I want to create hyperlinks within it to notes in EverNote. EverNote supplies links to notes that can be used in other applications, but when I click on one of these links in FreeMind, I get the following Java error message: This URL is malformed! java.net.MalformedURLException: unknown protocol: evernote

I've spent a lot of time Googling "protocol handler", and it seems as if there should be some way to simply register a custom protocol handler for an application like EverNote - but I can't find instructions to do this non-programmatically anywhere.

Ideally I could simply edit a Java registry somewhere, and add a custom protocol handler for EverNote that would point to the EverNote executable.

Can anyone help me with this?
posted by worldshift to Computers & Internet (5 answers total) 1 user marked this as a favorite
 
wait, so do you type in something like evernote://to/the/note to get there? if so, i would assume that java's http link handler does not, in fact, support this protocol. this is not something you're gonna change in the registry, its within the source code of java itself. the only way you're not gonna solve this programmatically is to set up a webserver on your box that redirects http requests to evernote.
posted by Mach5 at 5:29 AM on April 3, 2008


Most windows applications don't deal with URLs, they just hand them to windows and say "here, you deal with it". Java doesn't, since it's cross platform. So you're right that Java has to change.

Here's the bad news. It requires at least a code change. I haven't looked into it enough to know exactly what the code change is, but this isn't a configurable option somewhere. It'll be a custom piece of code which says "ok, that is an evernote link, fire up evernote".

Here's the good news. It's open source. You can download the FreeMind source, and tinker with it.

More bad news. That's a pain.
posted by cschneid at 5:39 AM on April 3, 2008


As suggested, you'll need to make some custom "server" to map the evernotes "protocol" to something acceptable to java.net.URL . Otherwise you'll have to crack open the source of freemind and change or augment the protocol handling.
posted by Artful Codger at 6:20 AM on April 3, 2008


Consider asking the developers to implement this feature.

What follows isn't the answer you want, it involves programing.

I haven't seen a way to say "map this URL protocol to this executable," but in Java you can register custom protocol handlers.

You can write
a Class that extends URLConnection, let's call it ENoteURLConnection.
a Class that extends URLStreamHandler, let's call it ENoteURLStreamHandler.
a Class that extends URLStreamHandlerFactory, let's call it ENoteURLStreamHandlerFactory.

Then you have to call
URL.setStreamHandlerFactory(new ENoteURLStreamHandlerFactory());

Then anytime the JVM hit a URL like "EverNote://bob/greatideas/23rd" it executes your code.

ENoteURLStreamHandlerFactory need to return a ENoteURLStreamHandler
and ENoteURLStreamHandler needs to return a return a
ENoteURLConnection. ENoteURLConnection needs to be able to do all
its work with only the requested URL.

Or if you want to open an external application you could use Runtime.getRuntime().exec()
to kick off your external application from ENoteURLStreamHandler.openConnection().
Then you could forget ENoteURLConnection and return a dummy URLConnection since
all of the action is external to the JVM.

Here is an example from Google cache.
posted by bdc34 at 10:40 AM on April 3, 2008


Thanks everyone so much for all the information and ideas!

Hopefully when FreeMind eventually come out with a new release (it's been what, two years now?), they'll put in some code for Windows to automatically drop any unknown protocol out to the system, which will know what to do with it - something I'll suggest.

In the meanwhile it's back to using clunky MindManager (you need a registry fix to get it to work with EverNote, contact me if anyone needs this), or perhaps XMIND which is starting to grow on me.
posted by worldshift at 10:09 AM on April 4, 2008


« Older how can I ship my books from t...   |  I have a photo of an ancestor ... Newer »
This thread is closed to new comments.