Index: /trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/AbstractTC.java
===================================================================
--- /trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/AbstractTC.java	(revision 1990)
+++ /trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/AbstractTC.java	(revision 1991)
@@ -280,4 +280,8 @@
             System.err.println(exchange.getResponse().getContent().getData());
         }
+        
+        assertNotNull(exchange.getRequest().getOrderingId());
+        assertNotNull(exchange.getResponse().getOrderingId());
+        assertTrue(exchange.getRequest().getOrderingId() < exchange.getResponse().getOrderingId());
     }
 
Index: /trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorTest.java
===================================================================
--- /trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorTest.java	(revision 1990)
+++ /trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorTest.java	(revision 1991)
@@ -32,4 +32,6 @@
 
 import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.ContentType;
@@ -102,4 +104,27 @@
      */
     @Test
+    public void test_RetrievalOfId_MonitorOnly() throws Exception {
+        monitor = new HttpMonitor(new String[] { LOG_FILE_DIR, MONITOR_PORT + "" });
+
+        monitor.init();
+        monitor.start();
+        
+        long id = getId();
+        assertTrue(id > 0);
+        
+        for (int i = 0; i < 300; i++) {
+            long prevId = id;
+            id = getId();
+            assertTrue(id > prevId);
+        }
+        
+        monitor.stop();
+        monitor = null;
+    }
+    
+    /**
+     *
+     */
+    @Test
     public void test_SimulatedSession_MonitorOnly() throws Exception {
         monitor = new HttpMonitor(new String[] { LOG_FILE_DIR, MONITOR_PORT + "" });
@@ -138,4 +163,6 @@
         System.out.println("{");
         System.out.println("  {");
+        long prevId = 0;
+        
         for (int j = 0; j < sequence.size(); j++) {
             System.out.print("    ");
@@ -150,10 +177,19 @@
             assertTrue(sequence.get(j).getTarget() instanceof HTTPTarget);
 
+            HTTPEventType eventType = (HTTPEventType) sequence.get(j).getType();
+            
             HTTPTestUtils.assertExchangeEquals
-                (simulatedSession.getHttpExchange().get(j),
-                 ((HTTPEventType) sequence.get(j).getType()).getExchange());
+                (simulatedSession.getHttpExchange().get(j), eventType.getExchange());
 
             assertEquals(HTTPUtils.toString(simulatedSession.getHttpExchange().get(j).getReceiver()),
                          ((HTTPTarget) sequence.get(j).getTarget()).getStringIdentifier());
+            
+            assertNotNull(eventType.getExchange().getRequest().getOrderingId());
+            assertTrue(prevId < eventType.getExchange().getRequest().getOrderingId());
+            prevId = eventType.getExchange().getRequest().getOrderingId();
+            
+            assertNotNull(eventType.getExchange().getResponse().getOrderingId());
+            assertTrue(prevId < eventType.getExchange().getResponse().getOrderingId());
+            prevId = eventType.getExchange().getResponse().getOrderingId();
         }
         System.out.println("  }");
@@ -510,3 +546,20 @@
     }
 
+    /**
+     *
+     */
+    private long getId() throws Exception {
+        DefaultHttpClient httpclient = new DefaultHttpClient();
+        
+        HttpGet httpRequest = new HttpGet("http://localhost:" + MONITOR_PORT + "/");
+            
+        try {
+            HttpResponse response = httpclient.execute(httpRequest);
+            return Long.parseLong(response.getFirstHeader("X-AutoQUEST-OrderingId").getValue());
+        }
+        finally {
+            httpRequest.releaseConnection();
+        }
+    }
+
 }
Index: /trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitoringProxyTest.java
===================================================================
--- /trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitoringProxyTest.java	(revision 1990)
+++ /trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitoringProxyTest.java	(revision 1991)
@@ -65,4 +65,9 @@
      */
     private Server dummyMonitor;
+
+    /**
+     * the id generator used by the dummy
+     */
+    private IdGenerator idGenerator;
     
     /**
@@ -77,4 +82,8 @@
         // setup a simple HTTP server
         messages = new LinkedList<String>();
+        
+        idGenerator = new SimpleIdGenerator();
+        idGenerator.init();
+        idGenerator.start();
         
         dummyMonitor = new Server(MONITOR_PORT);
@@ -99,4 +108,5 @@
             }
         }
+        
         if (dummyMonitor != null) {
             try {
@@ -105,4 +115,13 @@
             finally {
                 dummyMonitor = null;
+            }
+        }
+        
+        if (idGenerator != null) {
+            try {
+                idGenerator.stop();
+            }
+            finally {
+                idGenerator = null;
             }
         }
@@ -642,5 +661,5 @@
         
         /* (non-Javadoc)
-         * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+         * @see HttpServlet#service(HttpServletRequest, HttpServletResponse)
          */
         @Override
@@ -653,4 +672,14 @@
             System.out.println("send ok response");
         }
+
+        /* (non-Javadoc)
+         * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+         */
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException
+        {
+            resp.setHeader("X-AutoQUEST-OrderingId", Long.toString(idGenerator.getNextId()));
+        }
         
         
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitor.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitor.java	(revision 1990)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitor.java	(revision 1991)
@@ -22,7 +22,8 @@
  * <p>
  * The HTTP monitor starts a web server ({@link HttpMonitorServer}) that receives exchanges
- * of the HTTP proxy. These exchanges are logged using the {@link HttpMonitorLogManager}. The
- * class assures that on shutdown e.g. caused by CTRL-C the server and the log manager are
- * stopped correctly.
+ * of the HTTP proxy. In addition, it provides via get a unique ordering id for requests and
+ * responses that can be used by the proxies when creating the exchanges. The exchanges are
+ * logged using the {@link HttpMonitorLogManager}. The class assures that on shutdown e.g. caused
+ * by CTRL-C the server and the log manager are stopped correctly.
  * </p>
  * 
@@ -50,4 +51,9 @@
      */
     private HttpMonitorLogManager logManager;
+
+    /**
+     * the id generator used for getting new unique ids
+     */
+    private IdGenerator idGenerator;
 
     /**
@@ -92,8 +98,11 @@
         
         try {
+            idGenerator = new SimpleIdGenerator();
+            idGenerator.init();
+
             logManager = new HttpMonitorLogManager(logFileBaseDir);
             logManager.init();
         
-            Servlet servlet = new HttpMonitorServlet(logManager);
+            Servlet servlet = new HttpMonitorServlet(logManager, idGenerator);
             server = new HttpMonitorServer(port, servlet);
             server.init();
@@ -118,4 +127,5 @@
         try {
             Runtime.getRuntime().addShutdownHook(shutdownHook);
+            idGenerator.start();
             logManager.start();
             server.start();
@@ -139,7 +149,9 @@
         server.stop();
         logManager.stop();
+        idGenerator.stop();
         
         server = null;
         logManager = null;
+        idGenerator = null;
     }
 
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorServer.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorServer.java	(revision 1990)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorServer.java	(revision 1991)
@@ -55,5 +55,5 @@
      *
      * @param port    the port to listen on
-     * @param servlet teh servlet to be deployed
+     * @param servlet the servlet to be deployed
      */
     public HttpMonitorServer(int port, Servlet servlet) {
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorServlet.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorServlet.java	(revision 1990)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorServlet.java	(revision 1991)
@@ -33,5 +33,8 @@
  * the servlet deployed in the web server that receives all recorded exchanges from the proxy. The
  * exchanges are parsed and forwarded to the provided exchange handler. If an exchange can not
- * be parsed it is discarded. Exchanges are only received via the POST HTTP method.
+ * be parsed it is discarded. Exchanges are only received via the POST HTTP method. Via the GET
+ * method, the servlet provides unique ordering ids as a header parameter in the response. The
+ * header parameter is named "X-AutoQUEST-OrderingId". For creating the ids it uses a provided id
+ * generator.
  * </p>
  * 
@@ -47,14 +50,22 @@
      */
     private transient HttpMonitorExchangeHandler exchangeHandler;
+    
+    /**
+     * the id generator used to return new unique ids.
+     */
+    private transient IdGenerator idGenerator;
 
     /**
      * <p>
      * initializes the servlet with the exchange handler to which all exchanges shall be forwarded
+     * and the id generator to be used for returning new ids
      * </p>
      *
      * @param exchangeHandler the exchange handler that shall receive all exchanges
+     * @param idGenerator     the id generator used to generate new ids
      */
-    HttpMonitorServlet(HttpMonitorExchangeHandler exchangeHandler) {
+    HttpMonitorServlet(HttpMonitorExchangeHandler exchangeHandler, IdGenerator idGenerator) {
         this.exchangeHandler = exchangeHandler;
+        this.idGenerator = idGenerator;
     }
 
@@ -87,4 +98,18 @@
         }
     }
+
+    /**
+     * this implements handling of doGet. For this servlet this means that we return a unique
+     * ordering id which can be used by proxies as ordering ids for requests and responses.
+     * 
+     * (non-Javadoc) (non-Javadoc)
+     * @see HttpServlet#doGet(HttpServletRequest, HttpServletResponse)
+     */
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse response)
+        throws ServletException, IOException
+    {
+        response.setHeader("X-AutoQUEST-OrderingId", Long.toString(idGenerator.getNextId()));
+    }
     
 }
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/IdGenerator.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/IdGenerator.java	(revision 1991)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/IdGenerator.java	(revision 1991)
@@ -0,0 +1,38 @@
+//   Copyright 2012 Georg-August-Universität Göttingen, Germany
+//
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//       http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+
+package de.ugoe.cs.autoquest.httpmonitor;
+
+/**
+ * <p>
+ * This is the default interface for an id generator that generates different ids on each new call
+ * of {@link #getNextId()};
+ * </p>
+ * 
+ * @author Patrick Harms
+ */
+public interface IdGenerator extends HttpMonitorComponent {
+
+    /**
+     * <p>
+     * upon each call, this method returns a new id. The ids are returned so that they can be
+     * ordered. This means, a new id is always larger than the previous one. But it is not
+     * required, that the next id is larger by one than the previous one.
+     * </p>
+     *
+     * @return the next unique id.
+     */
+    long getNextId();
+
+}
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/SimpleIdGenerator.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/SimpleIdGenerator.java	(revision 1991)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/SimpleIdGenerator.java	(revision 1991)
@@ -0,0 +1,70 @@
+//   Copyright 2012 Georg-August-Universität Göttingen, Germany
+//
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//       http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+
+package de.ugoe.cs.autoquest.httpmonitor;
+
+/**
+ * <p>
+ * This is a simple id generator that uses the timestamps as id. If {@link #getNextId()} is called
+ * twice in the same millisecond, than just the next millisecond is used.
+ * </p>
+ * 
+ * @author Patrick Harms
+ */
+public class SimpleIdGenerator implements IdGenerator {
+    
+    /** */
+    private long lastId;
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#init()
+     */
+    @Override
+    public void init() throws IllegalStateException, HttpMonitorException {
+        lastId = System.currentTimeMillis();
+    }
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#start()
+     */
+    @Override
+    public void start() throws IllegalStateException, HttpMonitorException {
+        // nothing to do
+    }
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#stop()
+     */
+    @Override
+    public void stop() {
+        // nothing to do
+    }
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.IdGenerator#getNextId()
+     */
+    @Override
+    public synchronized long getNextId() {
+        long newId = System.currentTimeMillis();
+        
+        if (newId <= lastId) {
+            newId = lastId + 1;
+        }
+        
+        lastId = newId;
+        
+        return newId;
+    }
+
+}
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/ExchangeListener.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/ExchangeListener.java	(revision 1990)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/ExchangeListener.java	(revision 1991)
@@ -27,4 +27,5 @@
 
 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorExchangeHandler;
+import de.ugoe.cs.autoquest.httpmonitor.IdGenerator;
 import de.ugoe.cs.autoquest.plugin.http.logdata.Address;
 import de.ugoe.cs.autoquest.plugin.http.logdata.Content;
@@ -46,6 +47,8 @@
  * recording an exchange can not be done in one step. This is due to the fact, that the proxy
  * servlet notifies different processing states for requests and response. An exchange listener
- * records all these event. On the occurrence of the final event, it compiles an
- * {@link HttpExchange} and forwards it to the exchange handler.
+ * records all these events. On the occurrence of the final event, it compiles an
+ * {@link HttpExchange} and forwards it to the exchange handler. When receiving the first event
+ * of the request, it also determines a respective ordering id. The same applies for the response.
+ * The ordering ids are retrieved from a provided id generator.
  * </p>
  * 
@@ -63,8 +66,22 @@
     /**
      * <p>
+     * the id generator used to generate ordering ids for requests and responses
+     * </p>
+     */
+    private IdGenerator idGenerator;
+    
+    /**
+     * <p>
      * the request of compiled exchange
      * </p>
      */
     private HttpServletRequest request;
+    
+    /**
+     * <p>
+     * the ordering id for the request
+     * </p>
+     */
+    private long requestOrderingId;
 
     /**
@@ -81,4 +98,11 @@
      */
     private HttpServletResponse response;
+    
+    /**
+     * <p>
+     * the ordering id for the response
+     * </p>
+     */
+    private long responseOrderingId;
 
     /**
@@ -99,10 +123,13 @@
      * <p>
      * initialized the exchange listener with the exchange handler to forward compiled exchanges to
+     * and the id generator to be used for generating ordering ids for requests and responses
      * </p>
      * 
      * @param exchangeHandler the exchange handler to forward compiled exchanges to
-     */
-    ExchangeListener(HttpMonitorExchangeHandler exchangeHandler) {
+     * @param idGenerator     the id generator to used for generating ordering ids
+     */
+    ExchangeListener(HttpMonitorExchangeHandler exchangeHandler, IdGenerator idGenerator) {
         this.exchangeHandler = exchangeHandler;
+        this.idGenerator = idGenerator;
     }
 
@@ -123,4 +150,5 @@
         lastUpdate = System.currentTimeMillis();
         this.request = request;
+        this.requestOrderingId = idGenerator.getNextId();
     }
 
@@ -159,4 +187,5 @@
         lastUpdate = System.currentTimeMillis();
         this.response = response;
+        this.responseOrderingId = idGenerator.getNextId();
     }
     
@@ -239,6 +268,6 @@
         exchange.setReceiver(address);
         
-        exchange.setRequest(map(request, eventObjectFactory));
-        exchange.setResponse(map(response, eventObjectFactory));
+        exchange.setRequest(map(request, requestOrderingId, eventObjectFactory));
+        exchange.setResponse(map(response, responseOrderingId, eventObjectFactory));
         
         exchangeHandler.handleHttpExchange(exchange);
@@ -250,6 +279,10 @@
      * </p>
      */
-    private HttpRequest map(HttpServletRequest request, ObjectFactory eventObjectFactory) {
+    private HttpRequest map(HttpServletRequest request,
+                            long               requestOrderingId,
+                            ObjectFactory      eventObjectFactory)
+    {
         HttpRequest eventRequest = eventObjectFactory.createHttpRequest();
+        eventRequest.setOrderingId(requestOrderingId);
         eventRequest.setMethod(Method.fromValue(request.getMethod()));
         eventRequest.setProtocol(Protocol.fromValue(request.getProtocol()));
@@ -311,8 +344,12 @@
      * </p>
      */
-    private HttpResponse map(HttpServletResponse response, ObjectFactory eventObjectFactory) {
+    private HttpResponse map(HttpServletResponse response,
+                             long                responseOrderingId,
+                             ObjectFactory       eventObjectFactory)
+    {
         HttpResponse eventResponse = eventObjectFactory.createHttpResponse();
         
         eventResponse.setStatus(BigInteger.valueOf(response.getStatus()));
+        eventResponse.setOrderingId(responseOrderingId);
 
         Headers headers = eventObjectFactory.createHeaders();
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/ExchangeListenerManager.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/ExchangeListenerManager.java	(revision 1990)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/ExchangeListenerManager.java	(revision 1991)
@@ -30,4 +30,5 @@
 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorException;
 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorExchangeHandler;
+import de.ugoe.cs.autoquest.httpmonitor.IdGenerator;
 import de.ugoe.cs.autoquest.plugin.http.logdata.Status;
 import de.ugoe.cs.util.console.Console;
@@ -60,4 +61,11 @@
     /**
      * <p>
+     * the id generator used to generate ordering ids for requests and responses
+     * </p>
+     */
+    private IdGenerator idGenerator;
+    
+    /**
+     * <p>
      * the mapping of requests handled by the proxy to the respective exchange listeners
      * </p>
@@ -79,7 +87,9 @@
      * 
      * @param exchangeHandler the exchange handler to be forwarded to the exchange listeners
-     */
-    ExchangeListenerManager(HttpMonitorExchangeHandler exchangeHandler) {
+     * @param idGenerator     the id generator to used for generating ordering ids
+     */
+    ExchangeListenerManager(HttpMonitorExchangeHandler exchangeHandler, IdGenerator idGenerator) {
         this.exchangeHandler = exchangeHandler;
+        this.idGenerator = idGenerator;
     }
 
@@ -219,5 +229,5 @@
                 if (listener == null) {
                     Console.traceln(Level.FINEST, "creating exchange listener for " + request);
-                    listener = new ExchangeListener(exchangeHandler); 
+                    listener = new ExchangeListener(exchangeHandler, idGenerator); 
                     listeners.put(request, listener);
                 }
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteConnection.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteConnection.java	(revision 1991)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteConnection.java	(revision 1991)
@@ -0,0 +1,212 @@
+//   Copyright 2012 Georg-August-Universität Göttingen, Germany
+//
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//       http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+
+package de.ugoe.cs.autoquest.httpmonitor.proxy;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.client.api.Request;
+import org.eclipse.jetty.client.api.Response.CompleteListener;
+import org.eclipse.jetty.client.api.Result;
+import org.eclipse.jetty.util.thread.QueuedThreadPool;
+
+import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent;
+import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorException;
+import de.ugoe.cs.util.console.Console;
+
+/**
+ * <p>
+ * This is a base class that combines common implementations required for connecting to a central
+ * HTTP monitoring server. The class allows for sending HTTP requests to the central server and
+ * waiting for the asynchronous response.
+ * </p>
+ * 
+ * @author Patrick Harms
+ */
+public abstract class HttpMonitorRemoteConnection implements CompleteListener, HttpMonitorComponent
+{
+    
+    /**
+     * <p>
+     * the HTTP client used internally to send data to the central server
+     * </p>
+     */
+    private HttpClient httpClient;
+    
+    /**
+     * <p>
+     * the host name of the central server
+     * </p>
+     */
+    private String httpMonitorServer;
+    
+    /**
+     * <p>
+     * the port of the central server
+     * </p>
+     */
+    private int httpMonitorPort;
+
+    /**
+     * <p>
+     * a map of requests send to the central server and the corresponding result.
+     * Initially, the result mapped to a request is null until the result is received.
+     * </p>
+     */
+    private Map<Request, Result> openRequests = new HashMap<>();
+    
+    /**
+     * <p>
+     * initializes the exchange handler with the host and port of the central server
+     * </p>
+     *
+     * @param httpMonitorServer the host name of the central server
+     * @param httpMonitorPort   the port of the central server
+     */
+    public HttpMonitorRemoteConnection(String httpMonitorServer, int httpMonitorPort) {
+        this.httpMonitorServer = httpMonitorServer;
+        this.httpMonitorPort = httpMonitorPort;
+    }
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#init()
+     */
+    @Override
+    public void init() throws IllegalStateException, HttpMonitorException {
+        httpClient = createHttpClient();
+    }
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#start()
+     */
+    @Override
+    public void start() throws IllegalStateException, HttpMonitorException {
+        try {
+            httpClient.start();
+            httpClient.getContentDecoderFactories().clear();
+        }
+        catch (Exception e) {
+            throw new HttpMonitorException("could not start client for HTTP-Monitor", e);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#stop()
+     */
+    @Override
+    public void stop() {
+        if (httpClient != null) {
+            try {
+                httpClient.stop();
+            }
+            catch (Exception e) {
+                Console.traceln(Level.WARNING, "could not stop client for HTTP-Monitor");
+                Console.logException(e);
+            }
+        }
+        
+        httpClient = null;
+    }
+
+    /**
+     * <p>
+     * creates a new request that can be used by subclasses to send something to the central server
+     * </p>
+     *
+     * @return as described
+     */
+    protected Request newRequest() {
+        return httpClient.newRequest(httpMonitorServer, httpMonitorPort);
+    }
+
+    /**
+     * <p>
+     * used to send a request to the central server. The request is stored internally to be able
+     * to wait for the result.
+     * </p>
+     *
+     * @param httpMonitorRequest the request to be sent to the central server
+     */
+    protected synchronized void sendRequest(Request httpMonitorRequest) {
+        openRequests.put(httpMonitorRequest, null);
+        httpMonitorRequest.send(this);
+    }
+
+    /**
+     * <p>
+     * used to synchronously wait for the result of a given request.
+     * </p>
+     *
+     * @param httpMonitorRequest the request for which the result shall be waited for
+     * 
+     * @return the result of the request or null, if no result was received after 30 seconds
+     */
+    protected synchronized Result getResult(Request httpMonitorRequest) {
+
+        try {
+            // wait for the result of the request to be added to the map asynchronously
+            int count = 30;
+            while (openRequests.containsKey(httpMonitorRequest) &&
+                   (openRequests.get(httpMonitorRequest) == null))
+            {
+                this.wait(1000);
+                
+                if (--count == 0) {
+                    // after 30 seconds, cancel the sending of the request
+                    openRequests.remove(httpMonitorRequest);
+                    break;
+                }
+            }
+        }
+        catch (InterruptedException e) {
+            // ignore, as this may only happen on system shutdown
+        }
+
+        return openRequests.get(httpMonitorRequest);
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jetty.client.api.Response.CompleteListener#onComplete(Result)
+     */
+    @Override
+    public synchronized void onComplete(Result result) {
+        openRequests.put(result.getRequest(), result);
+        this.notify();
+    }
+
+    /**
+     * <p>
+     * convenience method to create an initialize the utilized HTTP client
+     * </p>
+     */
+    private HttpClient createHttpClient() {
+        HttpClient client = new HttpClient();
+        
+        QueuedThreadPool executor = new QueuedThreadPool(10);
+        executor.setName("HttpMonitorClients");
+        client.setExecutor(executor);
+
+        client.setMaxConnectionsPerDestination(10000);
+        client.setIdleTimeout(30000);
+        client.setConnectTimeout(30000);
+        client.setStopTimeout(30000);
+        client.setRequestBufferSize(1024*1024);
+        client.setResponseBufferSize(1024*1024);
+        
+        return client;
+    }
+}
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteExchangeHandler.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteExchangeHandler.java	(revision 1990)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteExchangeHandler.java	(revision 1991)
@@ -17,6 +17,4 @@
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.util.HashSet;
-import java.util.Set;
 import java.util.logging.Level;
 
@@ -25,16 +23,11 @@
 import javax.xml.bind.Marshaller;
 
-import org.eclipse.jetty.client.HttpClient;
 import org.eclipse.jetty.client.api.Request;
-import org.eclipse.jetty.client.api.Response.CompleteListener;
 import org.eclipse.jetty.client.api.Result;
 import org.eclipse.jetty.client.util.OutputStreamContentProvider;
 import org.eclipse.jetty.http.HttpMethod;
 import org.eclipse.jetty.http.HttpVersion;
-import org.eclipse.jetty.util.thread.QueuedThreadPool;
 
 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitor;
-import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent;
-import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorException;
 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorExchangeHandler;
 import de.ugoe.cs.autoquest.plugin.http.logdata.HttpExchange;
@@ -48,5 +41,5 @@
  * request/response. It then creates an HTTP request to the central monitor and sends it there.
  * It is initialized with the name of the server and the port on which the central monitor runs.
- * If the exchanges can not be forwarded to the central server, they are discarded.
+ * If the exchanges cannot be forwarded to the central server, they are discarded.
  * </p>
  * 
@@ -54,34 +47,7 @@
  */
 public class HttpMonitorRemoteExchangeHandler
-    implements CompleteListener, HttpMonitorExchangeHandler, HttpMonitorComponent
+    extends HttpMonitorRemoteConnection
+    implements HttpMonitorExchangeHandler
 {
-
-    /**
-     * <p>
-     * the HTTP client used internally to send data to the central server
-     * </p>
-     */
-    private HttpClient httpClient;
-    
-    /**
-     * <p>
-     * the host name of the central server
-     * </p>
-     */
-    private String httpMonitorServer;
-    
-    /**
-     * <p>
-     * the port of the central server
-     * </p>
-     */
-    private int httpMonitorPort;
-
-    /**
-     * <p>
-     * a set of requests send to the central server for which the response was not received yet
-     * </p>
-     */
-    private Set<Request> openRequests = new HashSet<Request>();
     
     /**
@@ -94,46 +60,5 @@
      */
     public HttpMonitorRemoteExchangeHandler(String httpMonitorServer, int httpMonitorPort) {
-        this.httpMonitorServer = httpMonitorServer;
-        this.httpMonitorPort = httpMonitorPort;
-    }
-
-    /* (non-Javadoc)
-     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#init()
-     */
-    @Override
-    public void init() throws IllegalStateException, HttpMonitorException {
-        httpClient = createHttpClient();
-    }
-
-    /* (non-Javadoc)
-     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#start()
-     */
-    @Override
-    public void start() throws IllegalStateException, HttpMonitorException {
-        try {
-            httpClient.start();
-            httpClient.getContentDecoderFactories().clear();
-        }
-        catch (Exception e) {
-            throw new HttpMonitorException("could not start client for HTTP-Monitor", e);
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#stop()
-     */
-    @Override
-    public void stop() {
-        if (httpClient != null) {
-            try {
-                httpClient.stop();
-            }
-            catch (Exception e) {
-                Console.traceln(Level.WARNING, "could not stop client for HTTP-Monitor");
-                Console.logException(e);
-            }
-        }
-        
-        httpClient = null;
+        super(httpMonitorServer, httpMonitorPort);
     }
 
@@ -144,5 +69,5 @@
     public synchronized void handleHttpExchange(HttpExchange httpExchange) {
         // send the exchange to the server and wait for completion
-        Request httpMonitorRequest = httpClient.newRequest(httpMonitorServer, httpMonitorPort);
+        Request httpMonitorRequest = super.newRequest();
         httpMonitorRequest.method(HttpMethod.POST);
         httpMonitorRequest.version(HttpVersion.HTTP_1_1);
@@ -151,6 +76,5 @@
         httpMonitorRequest.content(out);
         
-        openRequests.add(httpMonitorRequest);
-        httpMonitorRequest.send(this);
+        super.sendRequest(httpMonitorRequest);
 
         try {
@@ -173,28 +97,8 @@
             Console.logException(e);
         }
-
-        try {
-            // wait for the request to be removed from the list asynchronously
-            int count = 30;
-            while (openRequests.contains(httpMonitorRequest)) {
-                this.wait(1000);
-                
-                if (--count == 0) {
-                    // after 30 seconds, cancel the sending of the loggin request
-                    openRequests.remove(httpMonitorRequest);
-                    break;
-                }
-            }
-        }
-        catch (InterruptedException e) {
-            // ignore, as this may only happen on system shutdown
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.eclipse.jetty.client.api.Response.CompleteListener#onComplete(Result)
-     */
-    @Override
-    public synchronized void onComplete(Result result) {
+        
+        // wait to ensure that the request was received
+        Result result = super.getResult(httpMonitorRequest);
+        
         if (result.isFailed()) {
             Console.traceln
@@ -202,29 +106,4 @@
             Console.logException((Exception) result.getFailure());
         }
-        
-        openRequests.remove(result.getRequest());
-        this.notify();
-    }
-
-    /**
-     * <p>
-     * convenience method to create an initialize the utilized HTTP client
-     * </p>
-     */
-    private HttpClient createHttpClient() {
-        HttpClient client = new HttpClient();
-        
-        QueuedThreadPool executor = new QueuedThreadPool(10);
-        executor.setName("HttpMonitorClients");
-        client.setExecutor(executor);
-
-        client.setMaxConnectionsPerDestination(10000);
-        client.setIdleTimeout(30000);
-        client.setConnectTimeout(30000);
-        client.setStopTimeout(30000);
-        client.setRequestBufferSize(1024*1024);
-        client.setResponseBufferSize(1024*1024);
-        
-        return client;
     }
 }
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteIdGenerator.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteIdGenerator.java	(revision 1991)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteIdGenerator.java	(revision 1991)
@@ -0,0 +1,122 @@
+//   Copyright 2012 Georg-August-Universität Göttingen, Germany
+//
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//       http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+
+package de.ugoe.cs.autoquest.httpmonitor.proxy;
+
+import java.util.logging.Level;
+
+import org.eclipse.jetty.client.api.Request;
+import org.eclipse.jetty.client.api.Result;
+import org.eclipse.jetty.client.api.Response.CompleteListener;
+import org.eclipse.jetty.http.HttpMethod;
+import org.eclipse.jetty.http.HttpVersion;
+
+import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent;
+import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorException;
+import de.ugoe.cs.autoquest.httpmonitor.IdGenerator;
+import de.ugoe.cs.autoquest.httpmonitor.SimpleIdGenerator;
+import de.ugoe.cs.util.console.Console;
+
+/**
+ * <p>
+ * if a central monitoring server is used by the proxy, then this id generator is a connection to
+ * the server to receive centrally unique ordering ids from the central server. If the central
+ * server cannot be reached, this id generated uses a fallback internal {@link SimpleIdGenerator}.
+ * </p>
+ * 
+ * @author Patrick Harms
+ */
+public class HttpMonitorRemoteIdGenerator
+    extends HttpMonitorRemoteConnection
+    implements CompleteListener, IdGenerator, HttpMonitorComponent
+{
+    /** the fall back id generator used internally if the server is not reachable*/
+    private IdGenerator fallBackIdGenerator = new SimpleIdGenerator();
+    
+    /**
+     * <p>
+     * initializes the id generator with the host and port of the central server from which to
+     * retrieve the ids
+     * </p>
+     *
+     * @param httpMonitorServer the host name of the central server
+     * @param httpMonitorPort   the port of the central server
+     */
+    public HttpMonitorRemoteIdGenerator(String httpMonitorServer, int httpMonitorPort) {
+        super(httpMonitorServer, httpMonitorPort);
+    }
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.proxy.HttpMonitorRemoteConnection#init()
+     */
+    @Override
+    public void init() throws IllegalStateException, HttpMonitorException {
+        fallBackIdGenerator.init();
+        super.init();
+    }
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.proxy.HttpMonitorRemoteConnection#start()
+     */
+    @Override
+    public void start() throws IllegalStateException, HttpMonitorException {
+        fallBackIdGenerator.start();
+        super.start();
+    }
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.proxy.HttpMonitorRemoteConnection#stop()
+     */
+    @Override
+    public void stop() {
+        super.stop();
+        fallBackIdGenerator.stop();
+    }
+
+    /* (non-Javadoc)
+     * @see de.ugoe.cs.autoquest.httpmonitor.IdGenerator#getNextId()
+     */
+    @Override
+    public synchronized long getNextId() {
+        Request httpMonitorRequest = super.newRequest();
+        httpMonitorRequest.method(HttpMethod.GET);
+        httpMonitorRequest.version(HttpVersion.HTTP_1_1);
+        super.sendRequest(httpMonitorRequest);
+
+        Result result = super.getResult(httpMonitorRequest);
+        
+        if (result.isFailed()) {
+            Console.traceln
+                (Level.WARNING, "could not retrieve next id correctly: " + result.getFailure());
+            Console.logException((Exception) result.getFailure());
+            
+            Console.traceln(Level.WARNING, "using fallback, i.e., internal id generator");
+            return fallBackIdGenerator.getNextId();
+        }
+        else {
+            try {
+                return result.getResponse().getHeaders().getLongField("X-AutoQUEST-OrderingId");
+            }
+            catch (NumberFormatException e) {
+                Console.traceln(Level.WARNING, "could not retrieve next id correctly: " + e);
+                Console.logException(e);
+                
+                Console.traceln(Level.WARNING, "using fallback, i.e., internal id generator");
+                return fallBackIdGenerator.getNextId();
+            }
+        }
+        
+    }
+
+}
Index: /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitoringProxy.java
===================================================================
--- /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitoringProxy.java	(revision 1990)
+++ /trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitoringProxy.java	(revision 1991)
@@ -22,6 +22,8 @@
 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorLogManager;
 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorServer;
+import de.ugoe.cs.autoquest.httpmonitor.IdGenerator;
 import de.ugoe.cs.autoquest.httpmonitor.Runner;
 import de.ugoe.cs.autoquest.httpmonitor.ShutdownHook;
+import de.ugoe.cs.autoquest.httpmonitor.SimpleIdGenerator;
 import de.ugoe.cs.util.console.Console;
 
@@ -29,8 +31,11 @@
  * <p>
  * The HTTP monitory proxy monitor starts a web server ({@link HttpMonitorServer}) that receives
- * proxies HTTP messages and response. Each exchange of a request and a response is forwarded to
+ * proxied HTTP messages and response. Each exchange of a request and a response is forwarded to
  * an exchange handler. The exchange handler is either a local log manager
  * ({@link HttpMonitorLogManager}) or a connection to an external and central HTTP monitor via
- * an {@link HttpMonitorRemoteExchangeHandler}. The class ensures that on shutdown e.g. caused
+ * an {@link HttpMonitorRemoteExchangeHandler}. It also holds a reference to an id generator. If
+ * the exchanges are handled locally, then also a local {@link SimpleIdGenerator} is used. If
+ * the exchanges are send to a central HTTP monitor, then this monitor is used as id generator via
+ * an {@link HttpMonitorRemoteIdGenerator}. The class ensures that on shutdown e.g. caused
  * by CTRL-C the server and all other requied components are stopped correctly.
  * </p>
@@ -59,4 +64,9 @@
      */
     private HttpMonitorExchangeHandler exchangeHandler;
+    
+    /**
+     *  the id generator used to generate order ids for the requests and responses
+     */
+    private IdGenerator idGenerator;
     
     /**
@@ -170,8 +180,11 @@
             exchangeHandler =
                 new HttpMonitorRemoteExchangeHandler(httpMonitorServer, httpMonitorPort);
+            
+            idGenerator = new HttpMonitorRemoteIdGenerator(httpMonitorServer, httpMonitorPort);
         }
         else {
             Console.println("storing logs locally into directory " + logFileBaseDir);
             exchangeHandler = new HttpMonitorLogManager(logFileBaseDir);
+            idGenerator = new SimpleIdGenerator();
         }
     }
@@ -187,6 +200,7 @@
         
         exchangeHandler.init();
-        
-        exchangeListenerManager = new ExchangeListenerManager(exchangeHandler);
+        idGenerator.init();
+        
+        exchangeListenerManager = new ExchangeListenerManager(exchangeHandler, idGenerator);
         exchangeListenerManager.init();
         
@@ -205,5 +219,7 @@
     @Override
     public synchronized void start() {
-        if ((exchangeHandler == null) || (exchangeListenerManager == null) || (server == null)) {
+        if ((exchangeHandler == null) || (idGenerator == null) ||
+            (exchangeListenerManager == null) || (server == null))
+        {
             throw new IllegalStateException("not initialized.");
         }
@@ -212,4 +228,5 @@
             Runtime.getRuntime().addShutdownHook(shutdownHook);
             exchangeHandler.start();
+            idGenerator.start();
             exchangeListenerManager.start();
             server.start();
@@ -226,5 +243,7 @@
     @Override
     public synchronized void stop() {
-        if ((exchangeHandler == null) || (exchangeListenerManager == null) || (server == null)) {
+        if ((exchangeHandler == null) || (idGenerator == null) ||
+            (exchangeListenerManager == null) || (server == null))
+        {
             throw new IllegalStateException("not initialized.");
         }
@@ -233,8 +252,10 @@
         server.stop();
         exchangeListenerManager.stop();
+        idGenerator.stop();
         exchangeHandler.stop();
         
         server = null;
         exchangeListenerManager = null;
+        idGenerator = null;
         exchangeHandler = null;
     }
