Index: MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java
===================================================================
--- MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java	(revision 1508)
+++ MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java	(revision 1509)
@@ -39,5 +39,5 @@
  *
  */
-public class MDRepoProxyAction extends GenericProxyAction {
+public class MDRepoProxyAction extends RepoProxyAction {
 
 	private static final long serialVersionUID = 1L;
Index: MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/Pz2ProxyAction.java
===================================================================
--- MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/Pz2ProxyAction.java	(revision 1508)
+++ MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/Pz2ProxyAction.java	(revision 1509)
@@ -39,5 +39,5 @@
  
  */
-public class Pz2ProxyAction extends GenericProxyAction {
+public class Pz2ProxyAction extends RepoProxyAction {
 
 	private static final long serialVersionUID = 1L;
@@ -136,5 +136,10 @@
 	}
 	
-/*
+/**
+ * Overrides the default implementation for the case, when the Service shall act as "collector",
+ * waiting for the final result (implemented in getSourcePz2
+ * The distinction is based on the command parameter: if it is given, the Class(Service) acts as a basic proxy
+ * transparently passing the communication between client and target repository.  
+ */
 	@Override
 	public InputStream getSourceStream() throws IOException, NoStylesheetException {
@@ -151,4 +156,9 @@
 	}
 	
+/**
+ * TODO: move to Utils
+ * @param is
+ * @return
+ */
 	public Document getDocument(InputStream is){
 		Document doc = null;
@@ -170,4 +180,11 @@
 		return doc;
 	}
+	
+/**
+ * TODO: move to Utils
+ * @param is
+ * @param expression
+ * @return
+ */
 	public String getDocumentData(InputStream is, String expression){
 		String sessionid = "";
@@ -187,6 +204,11 @@
 		
 	}
-	*/
-	/*
+
+/**
+ * This function wraps the session-based communication with a Pazpar2-target, waiting until all the responses were returned (or timeout occured)
+ * returning the full result at the end.   
+ * @return returns the collected final result as a stream
+ * @throws Exception
+ */
 	public InputStream getSourcePz2() throws Exception {
 		
@@ -227,5 +249,4 @@
 		return is;
 	}
-*/
 	
 }
Index: MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/RepoProxyAction.java
===================================================================
--- MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/RepoProxyAction.java	(revision 1508)
+++ MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/RepoProxyAction.java	(revision 1509)
@@ -44,8 +44,52 @@
 
 	private String proxy_key = "repository";
-	
+	private RepoProxyAction target_proxy;
+	private RepoProxyAction source_action;
+	
+/**
+ * Based on the repository type - we create a typed Proxy, that will do the work.
+ * If the type is not recognized <this> will be also the target_proxy - 
+ * TODO: check if it is sane, to work without a typed target_proxy   
+ */
+	protected void  initialize(){
+		
+		switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
+		{		
+		    case PAZPAR: 
+		    	target_proxy = new Pz2ProxyAction();
+		    case SRU:
+		    	target_proxy = new SRUProxyAction();
+		    case MD:
+		    	target_proxy = new MDRepoProxyAction();
+		    default:
+		    	target_proxy = this;
+		}
+		target_proxy.setSourceAction(this);
+		
+	}
+	
+	public RepoProxyAction getTargetProxy() {
+		return target_proxy;
+	}
+
+	public RepoProxyAction getSourceAction() {
+		return source_action;
+	}
+	
+	public void setSourceAction(RepoProxyAction p_source_action) {
+		source_action = p_source_action;
+	}
+	
+/** 
+ * Pass the proxy_key of the actual target_proxy,
+ * or the basic "repository" if the target_proxy is identical  
+ */
 	@Override
 	public String getProxyKey() {
-		return proxy_key;
+		if (target_proxy.equals(this)) {
+		  return proxy_key;
+		} else {		
+			return getTargetProxy().getProxyKey();
+		}
 	}
 
@@ -60,18 +104,4 @@
 	}
 	
-	/**
-	 * A mapping between the actionkeys in the request and the operation-parameter expected by the MD!Repository 
-	 * FIXME: This is taken from MDRepoProxyAction - so it will not work for SRU and Pazpar2
-	 */
-	private final static HashMap<String,String> urls = new HashMap<String,String>();
-	 static
-	 {	 urls.put("collection", "?operation=getCollections&collection=");
-	  	 urls.put("model", "?operation=queryModel&q=");
-	  	 urls.put("values", "?operation=scanIndex&q=");
-	 	 urls.put("search", "?operation=searchRetrieve&query=");
-	 	 urls.put("record", "?operation=searchRetrieve&query=");
-	 } 
-
-	
 	//TODO remove - just for tests
 	@Override
@@ -106,65 +136,9 @@
 	}
 	
-public URL getTargetRequestSRU() throws IOException, NoStylesheetException{
-	
-	SRUProxyAction sruaction = new SRUProxyAction();
-	// TODO MD to SRU params
-	// missing collections, columns...
-	sruaction.setOperation("searchRetrieve");
-	//TODO what version
-	sruaction.setVersion("1.2");
-	sruaction.setStartRecord(Integer.parseInt(this.getStartItem()));
-	sruaction.setMaximumRecords(Integer.parseInt(this.getMaximumItems()));
-	sruaction.setRepository(getRepository());
-	sruaction.setQuery(this.fullQueryString());
-	
-	return sruaction.getTargetRequest();
-	
-}
-public InputStream getSourcePz2() throws Exception {
-		
-		InputStream is = null;
-		Pz2ProxyAction pzaction = new Pz2ProxyAction();
-		// TODO param settings
-		//init
-		pzaction.setRepository(getRepository());
-		pzaction.setCommand("init");
-		String sessionID = Helpers.getDocumentData(pzaction.getSourceStream(), "//init/session");
-		// get result
-		pzaction.setCommand("search");
-		pzaction.setSessionID(sessionID);
-		pzaction.setQuery(this.fullQueryString());
-		String ok = Helpers.getDocumentData(pzaction.getSourceStream(),"//search/status");
-		
-		String activeclients = "1";
-		pzaction.setCommand("show");
-		pzaction.setSort("relevance");
-		pzaction.setBlock("1");
-		//TODO timeout  settings
-		long startMillis = System.currentTimeMillis();
-		long timeout = 0;
-		if (WorkspaceProfile.getOption("pazpartimeout") == null){
-			timeout = 1000;
-		} else {
-			timeout = Integer.parseInt(WorkspaceProfile.getOption("pazpartimeout"));
-		}
-		while (Integer.parseInt(activeclients) > 0){
-			//activeclients = getDocumentData(this.getSourceStream(), "//show/activeclients");
-			is = pzaction.getSourceStream();
-			activeclients = Helpers.getDocumentData(is, "//show/activeclients");
-			Thread.sleep(1000); 
-			Admin.notifyUser("ActiveClients: " + activeclients, Admin.DEBUG);
-			if ((System.currentTimeMillis() - startMillis)/1000 > timeout) {
-				break;
-			}
-		}
-		is = pzaction.getSourceStream();
-		return is;
-	}
-		
 	@Override
 	public InputStream getSourceStream() throws IOException, NoStylesheetException {
-		
-		
+	
+		return getTargetProxy().getSourceStream();
+		/*
 		switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
 		{
@@ -183,5 +157,5 @@
 		    	return super.getSourceStream();
 		}
-		
+		*/
 	}
  
Index: MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java
===================================================================
--- MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java	(revision 1508)
+++ MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java	(revision 1509)
@@ -54,5 +54,5 @@
 
 
-public class SRUProxyAction extends GenericProxyAction//ActionSupport
+public class SRUProxyAction extends RepoProxyAction//ActionSupport
 //implements ServletRequestAware 
 {
@@ -386,6 +386,5 @@
 	public void sru2MD() throws UnsupportedEncodingException{
 		// special handling of parameter setting, x-cmd-... not alowed in java
-		this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections"));
-		
+		this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections"));		
 		// root call own SRU SERVER
 		//operation
@@ -560,5 +559,23 @@
 		return targetURL;
 	}
-	
+
+
+	public URL getTargetRequestSRU() throws IOException, NoStylesheetException{
+		
+		SRUProxyAction sruaction = new SRUProxyAction();
+		// TODO MD to SRU params
+		// missing collections, columns...
+		sruaction.setOperation("searchRetrieve");
+		//TODO what version
+		sruaction.setVersion("1.2");
+		sruaction.setStartRecord(Integer.parseInt(this.getStartItem()));
+		sruaction.setMaximumRecords(Integer.parseInt(this.getMaximumItems()));
+		sruaction.setRepository(getRepository());
+		sruaction.setQuery(this.fullQueryString());
+		
+		return sruaction.getTargetRequest();
+		
+	}
+
 	@Override 
 	public void prepare() throws Exception{
