Friday, July 8, 2011

URL Classloader

Recently I needed to supply a CXF WS client with a URL of the WSDL, but I needed to load it locally, from my classpath.  I found a nifty solution on Stackoverflow to load classpath resources with a URL:

public static class Handler extends URLStreamHandler {
     /** The classloader to find resources from. */
     private final ClassLoader classLoader;

     public Handler(ClassLoader classLoader) {
         this.classLoader = classLoader;
     }

     @Override
     protected URLConnection openConnection(URL u) throws IOException {
         final URL resourceUrl = classLoader.getResource(u.getPath());
         return resourceUrl.openConnection();
     }
 }

Then create the URL object and hand off to the CXF Proxy

url = new URL(null, "classpath:my.wsdl", new Handler(this.getClass().getClassLoader()));
MyService service = new MyService(url);

Credit goes to Stephen for this awesome trick:
http://stackoverflow.com/questions/861500/url-to-load-resources-from-the-classpath-in-java

Saturday, July 2, 2011

Sheevaplug Wifi USB Adapter

I recently added a Wifi adapter to my Sheevaplug since I don't have ethernet in my office. I purchased the Rosewill wifi adapter from Newegg, after reviews seemed to indicate it plays well with Linux. After some searching I learned that there are two main Linux tools for wireless configuration: wireless-tools and wpasupplicant.  I installed wpasupplicant since my wifi access point uses WPA-PSK security.  You can use wireless-tools if you only need WEP (lesser security).

apt-get install wpasupplicant

Then generate the config

wpa_passphrase <essid> <passphrase>

This will generate something like

network={
ssid="rawr"
#psk="foofoofoo"
psk=4a06c8003af16578addc1400cb3fed969dfa94a07164236b886301d20d05fb74
}

I added

proto=WPA
key_mgmt=WPA-PSK

Save the config in /etc/wpa_supplicant.conf

Scan for networks

iwlist scan

Hopefully your wireless network appears.

Test wpasupplicant

wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf -Dwext

and run ifconfig to see if it gets an ip address

If it's working, add to /etc/network/interfaces

auto wlan0
iface wlan0 inet dhcp
wpa-driver wext
wpa-conf /etc/wpa_supplicant.conf

And restart

/etc/init.d/networking restart

And you should have a wireless Sheevaplug.

Sheevaplug Power Supply Failure and Repair

My Sheevaplug's power supply failed recently, after less than a year of operation.  Unfortunately this is a common occurrence with GlobalScales Sheevaplug, and with only a 30 warranty it's leaving many owners a bit peeved.  Instead of purchasing a replacement power supply, which will likely fail again, I opted for an external (wall wart) power supply.  I'm currently using a 5V/2A supply, which works, however the original power supply is 5V/3A.  I ordered this 5V/3A power supply off Ebay. Beware this will take 3 or so weeks to arrive from China, but you can also order from US suppliers and pay just a bit more.  You'll notice this adapter has a 2.1/5.5mm barrel connector but the Sheevaplug uses a Molex, so you'll need to cut the Molex wires and solder on a barrel adapter.  I had one of these on hand, so I used it instead -- not exactly ideal as it is designed to mount on a pcb.  To compensate for the poor choice in parts, I slathered it with hot glue to insulate the contacts.  Be sure to identify the positive and negative connecters on the power supply, with a multimeter (mixing this up will probably destroy your plug).



I unscrewed the original power port and fed the barrel connector through and into the metal box where I connected it to the Molex wire.


I powered it on and the plug came back to life.  Unfortunately my SD card seemed to have gotten corrupted, which I was booting off of, so I had to fallback to boot off the flash.  The plug is working great now and hopefully it's even more reliable.