package org.aktin.broker.admin.standalone;

import java.io.InputStream;
import java.net.InetSocketAddress;

public class TestServer implements Configuration{
	@Override
	public InputStream readAPIKeyProperties() {
		return getClass().getResourceAsStream("/api-keys.properties");
	}

	@Override
	public String getDatabasePath() {
		return "target/broker";
	}

	@Override
	public String getAggregatorDataPath() {
		return "target/aggregator-data";
	}
	@Override
	public String getBrokerDataPath() {
		return "target/broker-data";
	}

	@Override
	public int getPort() {
		return 8080;
	}

	/**
	 * Run the test server with with the official i2b2
	 * webclient.
	 * @param args command line arguments: port can be specified optionally
	 * @throws Exception any error
	 */
	public static void main(String[] args) throws Exception{
		// use port if specified
		int port;
		if( args.length == 0 ){
			port = 8080;
		}else if( args.length == 1 ){
			port = Integer.parseInt(args[0]);
		}else{
			System.err.println("Too many command line arguments!");
			System.err.println("Usage: "+HttpServer.class.getCanonicalName()+" [port]");
			System.exit(-1);
			return;
		}

		
		// load hsql driver
		Class.forName("org.hsqldb.jdbcDriver");
		
		// start server
		HttpServer server = new HttpServer(new TestServer());
		try{
			server.start(new InetSocketAddress(port));
			System.err.println("Broker service at: "+server.getBrokerServiceURI());
			server.join();
		}finally{
			server.destroy();
		}
	}


}

@@ -101,16 +101,150 @@
 dress;%0A%0A
+import org.aktin.broker.ApiKeyAuth;%0Aimport org.aktin.broker.client.BrokerClient;%0Aimport org.aktin.broker.client.auth.HttpApiKeyAuth;%0A%0A
 public c
@@ -1559,16 +1559,355 @@
 URI());%0A
+%09%09%09// add some nodes%0A%09%09%09BrokerClient c = new BrokerClient(server.getBrokerServiceURI());%0A%09%09%09c.setClientAuthenticator(HttpApiKeyAuth.newBearer(%22xxxApiKey123%22));%0A%09%09%09c.putMyResource(%22dummy%22, %22text/plain%22, %22empty%22);%0A%09%09%09c.setClientAuthenticator(HttpApiKeyAuth.newBearer(%22xxxApiKey567%22));%0A%09%09%09c.putMyResource(%22dummy%22, %22text/plain%22, %22empty%22);%0A%09%09%09%0A
 %09%09%09serve

add two client nodes to example server