jsalvata    2003/11/30 15:21:06

  Modified:    src/protocol/http/org/apache/jmeter/protocol/http/proxy
                        Proxy.java ProxyControl.java
  Log:
  Partial solution to record results during proxy recording: now
  the proxy notifies listeners of the samples it runs.
  
  PR: 6730 [partial]
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.15      +6 -5      
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java
  
  Index: Proxy.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/proxy/Proxy.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Proxy.java        18 Nov 2003 18:26:55 -0000      1.14
  +++ Proxy.java        30 Nov 2003 23:21:06 -0000      1.15
  @@ -64,6 +64,7 @@
   
   import org.apache.jmeter.protocol.http.control.HeaderManager;
   import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
  +import org.apache.jmeter.samplers.SampleResult;
   import org.apache.jmeter.testelement.TestElement;
   import org.apache.jorphan.logging.LoggingManager;
   import org.apache.log.Logger;
  @@ -133,7 +134,7 @@
       public void run()
       {
           HttpRequestHdr request = new HttpRequestHdr();
  -        byte[] serverResponse = new byte[0];
  +        SampleResult result = null;
           HeaderManager headers = null;
   
           HTTPSampler sampler = new HTTPSampler();
  @@ -152,9 +153,9 @@
               headers = request.getHeaderManager();
               sampler.setHeaderManager(headers);
   
  -            serverResponse = sampler.sample().getResponseData();
  +            result = sampler.sample();
               writeToClient(
  -                serverResponse,
  +                result.getResponseData(),
                   new BufferedOutputStream(clientSocket.getOutputStream()));
               /*
                * We don't want to store any cookies in the generated test plan
  @@ -178,7 +179,7 @@
                                     new TestElement[] { 
                                        captureHttpHeaders ? headers : null 
                                        },
  -                                  serverResponse);
  +                                  result);
               try
               {
                   clientSocket.close();
  
  
  
  1.35      +48 -2     
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java
  
  Index: ProxyControl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- ProxyControl.java 29 Nov 2003 15:43:18 -0000      1.34
  +++ ProxyControl.java 30 Nov 2003 23:21:06 -0000      1.35
  @@ -81,6 +81,9 @@
   import org.apache.jmeter.protocol.http.control.HeaderManager;
   import org.apache.jmeter.protocol.http.control.RecordingController;
   import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
  +import org.apache.jmeter.samplers.SampleEvent;
  +import org.apache.jmeter.samplers.SampleListener;
  +import org.apache.jmeter.samplers.SampleResult;
   import org.apache.jmeter.testelement.TestElement;
   import org.apache.jmeter.testelement.property.BooleanProperty;
   import org.apache.jmeter.testelement.property.CollectionProperty;
  @@ -275,11 +278,12 @@
       public void deliverSampler(
           HTTPSampler sampler,
           TestElement[] subConfigs,
  -        byte[] serverResponse)
  +        SampleResult result)
       {
           if (filterUrl(sampler))
           {
               placeConfigElement(sampler, subConfigs);
  +            notifyListeners(new SampleEvent(result,sampler.getName()));
           }
       }
   
  @@ -600,6 +604,48 @@
                   "Invalid variables included for replacement into recorded "
                       + "sample",
                   e);
  +        }
  +    }
  +    
  +    /**
  +     * This will notify sample listeners of the sampling that just occured
  +     * -- so that we have a means to record the server's responses as we go.
  +     * <p>
  +     * Only listeners which are directly within the RecordingControllers or
  +     * ThreadGroups where recording is happening will be notified.
  +     * 
  +     * @param event sampling event to be delivered
  +     */
  +    private void notifyListeners(SampleEvent event) {
  +        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
  +        List nodes = treeModel.getNodesOfType(RecordingController.class);
  +        if (nodes.size() == 0)
  +        {
  +            nodes = treeModel.getNodesOfType(ThreadGroup.class);
  +        }
  +        Iterator iter = nodes.iterator();
  +        while (iter.hasNext())
  +        {
  +            JMeterTreeNode node = (JMeterTreeNode) iter.next();
  +
  +            if (!node.isEnabled())
  +            {
  +                continue;
  +            }
  +            else
  +            {
  +                Enumeration enum = node.children();
  +                while (enum.hasMoreElements())
  +                {
  +                    JMeterTreeNode subNode =
  +                        (JMeterTreeNode) enum.nextElement();
  +                    TestElement testElement =
  +                        (TestElement) subNode.createTestElement();
  +                    if (testElement instanceof SampleListener) {
  +                        ((SampleListener)testElement).sampleOccurred(event);
  +                    }
  +                }
  +            }
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to