Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.extractor » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   13    * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   14    * License for the specific language governing permissions and limitations
   15    * under the License.
   16    *
   17    */
   18   
   19   package org.apache.jmeter.extractor;
   20   
   21   import org.apache.jmeter.processor.PostProcessor;
   22   import org.apache.jmeter.samplers.SampleResult;
   23   import org.apache.jmeter.testbeans.TestBean;
   24   import org.apache.jmeter.threads.JMeterContext;
   25   import org.apache.jmeter.threads.JMeterContextService;
   26   import org.apache.jmeter.threads.JMeterVariables;
   27   import org.apache.jmeter.util.BeanShellInterpreter;
   28   import org.apache.jmeter.util.BeanShellTestElement;
   29   import org.apache.jorphan.logging.LoggingManager;
   30   import org.apache.jorphan.util.JMeterException;
   31   import org.apache.log.Logger;
   32   
   33   public class BeanShellPostProcessor extends BeanShellTestElement
   34       implements Cloneable, PostProcessor, TestBean
   35   {
   36       private static final Logger log = LoggingManager.getLoggerForClass();
   37   
   38       private static final long serialVersionUID = 4;
   39   
   40       // can be specified in jmeter.properties
   41       private static final String INIT_FILE = "beanshell.postprocessor.init"; //$NON-NLS-1$
   42   
   43       protected String getInitFileProperty() {
   44           return INIT_FILE;
   45       }
   46   
   47        public void process() {
   48           JMeterContext jmctx = JMeterContextService.getContext();
   49   
   50           SampleResult prev = jmctx.getPreviousResult();
   51           final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
   52           if (prev == null || bshInterpreter == null) {
   53               log.error("BeanShell not found");
   54               return;
   55           }
   56   
   57           JMeterVariables vars = jmctx.getVariables();
   58           try {
   59               // Add variables for access to context and variables
   60               bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$
   61               bshInterpreter.set("vars", vars);//$NON-NLS-1$
   62               bshInterpreter.set("prev", prev);//$NON-NLS-1$
   63               bshInterpreter.set("data", prev.getResponseData());//$NON-NLS-1$
   64               processFileOrScript(bshInterpreter);
   65           } catch (JMeterException e) {
   66               log.warn("Problem in BeanShell script "+e);
   67           }
   68       }
   69   }

Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.extractor » [javadoc | source]