I read from Davanum Srinivas’s tweet that the Apache Wink podling released 0.1. I didn’t know what Wink is offering, so I took a look. I read that Apache Wink 0.1 is a complete and TCK compliant implementation of the JAX-RS v1.0 specification. Also the documentation is quite large, I am impressed.
So, I gave it a try to post some status updates to Twitter. Here is a five to ten minute try/error hack by combining Apache Wink and Twitter:
package net.wessendorf.twitter.client.app;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import org.apache.wink.client.ClientConfig;
import org.apache.wink.client.Resource;
import org.apache.wink.client.RestClient;
import org.apache.wink.common.internal.MultivaluedMapImpl;
import sun.misc.BASE64Encoder;
public class App
{
public static void main( String[] args )
{
ClientConfig cc = new ClientConfig();
cc.proxyHost("iam-behind-a-proxy.com");
cc.proxyPort(80);
String logon = "username:password";
String encodedLogon = new BASE64Encoder().encode(logon.getBytes());
RestClient client = new RestClient(cc);
Resource twitter =
client.resource("http://twitter.com/statuses/update.json");
twitter.header("Authorization", "Basic " + encodedLogon);
twitter.contentType(MediaType.APPLICATION_FORM_URLENCODED_TYPE);
twitter.accept(MediaType.APPLICATION_JSON_TYPE);
MultivaluedMap<String, String> msg =
new MultivaluedMapImpl<String, String>();
msg.add("status", "Hello Apache Wink!");
twitter.post(String.class, msg);
}
}
This is really simple form but, heck it is just a try/error hack. Please note that this “programm” requires the SUN JDK, as I was using the BASE64Encoder class. By default Apache Wink uses the HttpURLConnection class (from your JDK) - but there is also a library for Apache Http Client 4.0.
The documentation is online.