public static void main(String[] args) throws Exception {
final BasicAuthentication authentication = new BasicAuthentication("foo", "bar");
// GET
final GetQuery getQuery = new GetQuery(HOSTNAME, PORT, PATH, SECURE);
getQuery.getParameters().put("a", "b");
getQuery.setSerializer(new BinarySerializer());
getQuery.getRequestHeaders().add("bar", "hello");
getQuery.getRequestHeaders().add("bar", "world");
authentication.authenticate(getQuery);
getQuery.execute(new TaskListener<Object>() {
@SuppressWarnings("unchecked")
public void taskExecuted(Task<Object> task) {
GetQuery getQuery = (GetQuery)task;
Dictionary<String, Object> result = (Dictionary<String, Object>)getQuery.getResult();
System.out.println("GET result: "
+ "username: " + result.get("username") + ", "
+ "pathInfo: " + result.get("pathInfo") + ", "
+ "queryString: " + result.get("queryString") + ", "
+ "status: " + getQuery.getStatus());
QueryDictionary responseHeaders = getQuery.getResponseHeaders();
for (String headerName : responseHeaders) {
System.out.print(headerName + "=");
for (int i = 0, n = responseHeaders.getLength(headerName); i < n; i++) {
System.out.print(responseHeaders.get(headerName, i) + ";");