Please refer to the following code and comments:
package kg.apc.jmeter.samplers;import java.awt.borderlayout;import java.awt.gridbagconstraints; Import java.awt.gridbaglayout;import javax.swing.jbutton;import javax.swing.jcheckbox;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JPanel;import Javax.swing.jtextarea;import javax.swing.jtextfield;import kg.apc.jmeter.jmeterpluginsutils;import kg.apc.jmeter.gui.BrowseAction;import kg.apc.jmeter.gui.GuiBuilderHelper;import Org.apache.jmeter.samplers.gui.abstractsamplergui;import org.apache.jmeter.testelement.testelement;import org.apache.jorphan.logging.loggingmanager;import org.apache.log.logger;/** * * @ author apc */public class tlsrawsamplergui extends abstractsamplergui { private static final logger Log = loggingmanager.getloggerForclass (); private jtextfield hostname; private jtextfield port; private jtextfield tlsversion; private jtextfield cipherlist; private jtextfield clientcert; private JTextField clientCertPassword; private jtextarea requestdata; /** * */ public tlsrawsamplergui () { init (); initfields (); } @Override public String Getstaticlabel () { return "Tls raw request" ; } &nBsp; /** * mirror data from TestElement to GUI */ @Override public void configure (testelement element) { super.configure (Element); log.info ( Element.tostring ()); if (element instanceof Tlsrawsampler) { tlsrawsampler rawSampler = (Tlsrawsampler) element; hostname.settext (Rawsampler.gethostname ()); port.settext (Rawsampler.getport ()); tlsversion.seTtext (Rawsampler.gettlsversion ()); Cipherlist.settext (Rawsampler.getcipherlist ()); clientcert.settext (Rawsampler.getclientcert ()); clientcertpassword.settext (Rawsampler.getclientcertpassword ()); requestdata.settext (Rawsampler.getdata ()); } } @Override public testelement createtestelement () { tlsrawsampler sampler = new tlsrawsampler (); modifytestelement (sampler); sampler.setcomment ("TLS sampler comment. "); return sampler; } /** * mirror data from gui to testelement */ @Override public void modifytestelement (Testelement sampler) { Super.configuretestelement (Sampler); if (sampler Instanceof tlsrawsampler) { tlsrawsampler rawsampler = (Tlsrawsampler) sampler; rawsampler.sethostname (Hostname.gettext ()); rawsampler.setport (Port.gettext ()); Rawsampler.settlsversion (Tlsversion.gettext ()); rawsampler.setcipherlist (Cipherlist.gettext ()); rawsampler.setclientcert (Clientcert.gettext (). Trim ()); rawsampler.setclientcertpassword (Clientcertpassword.gettext (). Trim () ); rawsampler.setdata (TransformCRLF ( Requestdata.gettext ())); } } /** * first replace removes old \r\n * second eliminates orphan \r * third make all newlines - old and new like \r\n */&nBsp; private string transformcrlf (STRING STR) { return str.replace ("\ r \ n", "\ n"). Replace ("\ r", ""). Replace ("\ n", " \ r \ n "); } @Override public void cleargui () { super.cleargui (); initfields (); } @Override public string getlabelresource () { return this.getclass (). Getsimplename (); } private void init () { setlayout (new BorderLayout (0 , 5)); setborder (Makeborder ()); add (JmetErpluginsutils.addhelplinktopanel (Maketitlepanel (), "Tls request"), borderlayout.north); jpanel mainpanel = new jpanel (new GridBagLayout ()); gridbagconstraints labelconstraints = new gridbagconstraints (); labelconstraints.anchor = gridbagconstraints.first_line_end; gridbagconstraints editconstraints = new gridbagconstraints (); editConstraints.anchor = GridBagConstraints.FIRST_LINE_START; editConstraints.weightx = 1.0; editConstraints.fill = GridBagConstraints.HORIZONTAL; addtopanel (mainpanel, lAbelconstraints, 0, 1, new jlabel ("hostname: ", jlabel.right)); addtopanel (mainpanel, editconstraints, 1, 1, hostname = new jtextfield ()); addtopanel (Mainpanel, labelconstraints, 0, 2, new jlabel (" port: ", jlabel.right)); addtopanel (mainPanel, Editconstraints, 1, 2, port = new jtextfield ()); editconstraints.insets = new java.awt.insets (2, 0, 0, 0); labelconstraints.insets = new java.awt.insets (2 , 0, 0, 0); addtopanel (mainPanel, labelconstraints, 0, 3,&Nbsp;new jlabel ("tls version: ", jlabel.right)); addtopanel (mainpanel, editconstraints, 1, 3, tlsversion = new JTextField ( addtopanel); Mainpanel, labelconstraints, 0, 4, new jlabel ("cipher list: ", jlabel.right)); addtopanel (mainpanel, editconstraints, 1, 4, cipherlist = new jtextfield ()); addtopanel (Mainpanel, labelconstraints, 0, 5, new jlabel ("Client Certificate PKCS File: ", jlabel.right)); addtopanel (mainpanel, editconstraints, 1, 5, clientcert = new JTextField ());    &NBsp; addtopanel (mainPanel, Labelconstraints, 0, 6, new jlabel ("Client certificate pkcs password", jlabel.right)); addtopanel (mainPanel, Editconstraints, 1, 6, clientcertpassword = new jtextfield ()); addtopanel (mainpanel, labelconstraints, 0, 7, new jlabel ("request data: ", jlabel.right)); editconstraints.fill = gridbagconstraints.both; Requestdata = new jtextarea (); addtopanel ( Mainpanel, editconstraints, 1, 7, guibuilderhelper.gettextareascrollpanecontainer ( REQUESTDATA, 20)); editconstraints.insets = new java.awt.insets (4, 0, 0, 0); labelconstraints.insets = new java.awt.insets (4, 0, 0, 0); jpanel container = new JPanel (New borderlayout ()); container.add (mainPanel, Borderlayout.north); add (Container, borderlayout.center); } private void addtopanel (JPanel panel, Gridbagconstraints constraints, int col, int row, jcomponent component) { constraints.gridx = col; constraints.gridy = row; panel.add (Component, constraints); } private void initfields () { hostname.settext ("${hostname}"); tlsversion.settext ("TLSv1.2"); cipherlist.settext (" "); clientcert.settext (" C:\\pkcs "); clientcertpassword.settext ("Passw0rd"); requestdata.settext ("get / http/1.0\r\n" + "host: localhost\r\n" + "connection: close\r\n" + "\ r \ n"); }}
Finally, we implemented the following interface:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5D/B2/wKioL1UjgCSBq_D9AANvzeWzb28342.jpg "title=" Snap2.jpg "alt=" Wkiol1ujgcsbq_d9aanvzewzb28342.jpg "/>
Writing the JMeter extension (2) writing the corresponding GUI for sampler code