Ignore:
Timestamp:
07/15/14 13:45:31 (10 years ago)
Author:
pharms
Message:
  • bugfix and test for correct query handling
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteExchangeHandler.java

    r1561 r1614  
    142142     */ 
    143143    @Override 
    144     public void handleHttpExchange(HttpExchange httpExchange) { 
     144    public synchronized void handleHttpExchange(HttpExchange httpExchange) { 
    145145        // send the exchange to the server and wait for completion 
    146         synchronized (openRequests) { 
    147             Request httpMonitorRequest = httpClient.newRequest(httpMonitorServer, httpMonitorPort); 
    148             httpMonitorRequest.method(HttpMethod.POST); 
    149             httpMonitorRequest.version(HttpVersion.HTTP_1_1); 
    150  
    151             OutputStreamContentProvider out = new OutputStreamContentProvider(); 
    152             httpMonitorRequest.content(out); 
    153             httpMonitorRequest.send(this); 
    154  
    155             try { 
    156                 JAXBContext jaxbContext = 
    157                         JAXBContext.newInstance(HttpExchange.class.getPackage().getName()); 
    158                 Marshaller marshaller = jaxbContext.createMarshaller(); 
    159  
    160                 OutputStreamWriter writer = new OutputStreamWriter(out.getOutputStream(), "UTF-8"); 
    161                 marshaller.marshal(new ObjectFactory().createHttpExchange(httpExchange), writer); 
    162  
    163                 out.getOutputStream().close(); 
    164             } 
    165             catch (JAXBException e) { 
    166                 Console.printerrln("could not convert request and response to XML string: " + e); 
    167                 Console.logException(e); 
    168             } 
    169             catch (IOException e) { 
    170                 Console.printerrln 
     146        Request httpMonitorRequest = httpClient.newRequest(httpMonitorServer, httpMonitorPort); 
     147        httpMonitorRequest.method(HttpMethod.POST); 
     148        httpMonitorRequest.version(HttpVersion.HTTP_1_1); 
     149 
     150        OutputStreamContentProvider out = new OutputStreamContentProvider(); 
     151        httpMonitorRequest.content(out); 
     152         
     153        openRequests.add(httpMonitorRequest); 
     154        httpMonitorRequest.send(this); 
     155 
     156        try { 
     157            JAXBContext jaxbContext = 
     158                JAXBContext.newInstance(HttpExchange.class.getPackage().getName()); 
     159            Marshaller marshaller = jaxbContext.createMarshaller(); 
     160 
     161            OutputStreamWriter writer = new OutputStreamWriter(out.getOutputStream(), "UTF-8"); 
     162            marshaller.marshal(new ObjectFactory().createHttpExchange(httpExchange), writer); 
     163 
     164            out.getOutputStream().close(); 
     165        } 
     166        catch (JAXBException e) { 
     167            Console.printerrln("could not convert request and response to XML string: " + e); 
     168            Console.logException(e); 
     169        } 
     170        catch (IOException e) { 
     171            Console.printerrln 
    171172                ("could not close the stream for sending data to the HTML monitor: " + e); 
    172                 Console.logException(e); 
    173             } 
    174              
    175             openRequests.add(httpMonitorRequest); 
    176              
    177             try { 
    178                 // wait for the request to be removed fromt the list asynchronously 
    179                 while (openRequests.contains(httpMonitorRequest)) { 
    180                     openRequests.wait(); 
     173            Console.logException(e); 
     174        } 
     175 
     176        try { 
     177            // wait for the request to be removed from the list asynchronously 
     178            int count = 30; 
     179            while (openRequests.contains(httpMonitorRequest)) { 
     180                this.wait(1000); 
     181                 
     182                if (--count == 0) { 
     183                    // after 30 seconds, cancel the sending of the loggin request 
     184                    openRequests.remove(httpMonitorRequest); 
     185                    break; 
    181186                } 
    182187            } 
    183             catch (InterruptedException e) { 
    184                 // ignore, as this may only happen on system shutdown 
    185             } 
     188        } 
     189        catch (InterruptedException e) { 
     190            // ignore, as this may only happen on system shutdown 
    186191        } 
    187192    } 
     
    191196     */ 
    192197    @Override 
    193     public void onComplete(Result result) { 
     198    public synchronized void onComplete(Result result) { 
    194199        if (result.isFailed()) { 
    195200            Console.traceln 
     
    198203        } 
    199204         
    200         synchronized (openRequests) { 
    201             openRequests.remove(result.getRequest()); 
    202             openRequests.notify(); 
    203         } 
     205        openRequests.remove(result.getRequest()); 
     206        this.notify(); 
    204207    } 
    205208 
Note: See TracChangeset for help on using the changeset viewer.