package com.sixsq.slipstream.resource;

import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.Reference;
import org.restlet.routing.Redirector;

public class MeteringRedirector extends Redirector {

	public MeteringRedirector(Context context, String targetPattern, int mode) {
		super(context, targetPattern, mode);
	}

	protected void outboundServerRedirect(Reference targetRef, Request request,
			Response response) {
		String user = request.getClientInfo().getUser().getName();
		request = addUserToQuery(request, user);
		super.outboundServerRedirect(targetRef, request,
				response);
	}

	private Request addUserToQuery(Request request, String user) {
		String query = request.getResourceRef().getQuery();
		request.getResourceRef().setQuery(query + "&user_id=" + user);
		return request;
	}

}

@@ -536,40 +536,45 @@
 ;%0A%09%09
-request = addUserToQuery(request
+targetRef.addQueryParameter(%22user_id%22
 , us
@@ -629,16 +629,16 @@
 equest,%0A
+
 %09%09%09%09resp
@@ -652,211 +652,6 @@
 %09%7D%0A%0A
-%09private Request addUserToQuery(Request request, String user) %7B%0A%09%09String query = request.getResourceRef().getQuery();%0A%09%09request.getResourceRef().setQuery(query + %22&user_id=%22 + user);%0A%09%09return request;%0A%09%7D%0A%0A
 %7D%0A

Add query fragment to target