View | Details | Raw Unified | Return to bug 57305
Collapse All | Expand All

(-)a/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java (-10 / +42 lines)
Lines 301-306 public class ProxyControl extends GenericController { Link Here
301
301
302
    private String keyPassword;
302
    private String keyPassword;
303
303
304
    private JMeterTreeModel nonGuiTreeModel;
305
304
    public ProxyControl() {
306
    public ProxyControl() {
305
        setPort(DEFAULT_PORT);
307
        setPort(DEFAULT_PORT);
306
        setExcludeList(new HashSet<String>());
308
        setExcludeList(new HashSet<String>());
Lines 308-313 public class ProxyControl extends GenericController { Link Here
308
        setCaptureHttpHeaders(true); // maintain original behaviour
310
        setCaptureHttpHeaders(true); // maintain original behaviour
309
    }
311
    }
310
312
313
    /**
314
     * Set a {@link JMeterTreeModel} to be used by the ProxyControl, when used
315
     * in a non-GUI environment, where the {@link JMeterTreeModel} can't be
316
     * acquired through {@link GuiPackage#getTreeModel()}
317
     *
318
     * @param treeModel
319
     *            the {@link JMeterTreeModel} to be used, or {@code null} when
320
     *            the GUI model should be used
321
     */
322
    public void setNonGuiTreeModel(JMeterTreeModel treeModel) {
323
        this.nonGuiTreeModel = treeModel;
324
    }
325
311
    public void setPort(int port) {
326
    public void setPort(int port) {
312
        this.setProperty(new IntegerProperty(PORT, port));
327
        this.setProperty(new IntegerProperty(PORT, port));
313
    }
328
    }
Lines 475-480 public class ProxyControl extends GenericController { Link Here
475
        return getPropertyAsString(CONTENT_TYPE_INCLUDE);
490
        return getPropertyAsString(CONTENT_TYPE_INCLUDE);
476
    }
491
    }
477
492
493
    /**
494
     * @return the {@link JMeterTreeModel} used when run in non-GUI mode, or {@code null} when run in GUI mode
495
     */
496
    public JMeterTreeModel getNonGuiTreeModel() {
497
        return nonGuiTreeModel;
498
    }
499
478
    public void addConfigElement(ConfigElement config) {
500
    public void addConfigElement(ConfigElement config) {
479
        // NOOP
501
        // NOOP
480
    }
502
    }
Lines 493-499 public class ProxyControl extends GenericController { Link Here
493
        try {
515
        try {
494
            server = new Daemon(getPort(), this);
516
            server = new Daemon(getPort(), this);
495
            server.start();
517
            server.start();
496
            GuiPackage.getInstance().register(server);
518
            if (GuiPackage.getInstance() != null) {
519
                GuiPackage.getInstance().register(server);
520
            }
497
        } catch (IOException e) {
521
        } catch (IOException e) {
498
            log.error("Could not create Proxy daemon", e);
522
            log.error("Could not create Proxy daemon", e);
499
            throw e;
523
            throw e;
Lines 682-688 public class ProxyControl extends GenericController { Link Here
682
    public void stopProxy() {
706
    public void stopProxy() {
683
        if (server != null) {
707
        if (server != null) {
684
            server.stopServer();
708
            server.stopServer();
685
            GuiPackage.getInstance().unregister(server);
709
            if (GuiPackage.getInstance() != null) {
710
                GuiPackage.getInstance().unregister(server);
711
            }
686
            try {
712
            try {
687
                server.join(1000); // wait for server to stop
713
                server.join(1000); // wait for server to stop
688
            } catch (InterruptedException e) {
714
            } catch (InterruptedException e) {
Lines 819-825 public class ProxyControl extends GenericController { Link Here
819
     * @param target {@link JMeterTreeNode}
845
     * @param target {@link JMeterTreeNode}
820
     */
846
     */
821
    private void setAuthorization(Authorization authorization, JMeterTreeNode target) {
847
    private void setAuthorization(Authorization authorization, JMeterTreeNode target) {
822
        JMeterTreeModel jmeterTreeModel = GuiPackage.getInstance().getTreeModel();
848
        JMeterTreeModel jmeterTreeModel = getJmeterTreeModel();
823
        List<JMeterTreeNode> authManagerNodes = jmeterTreeModel.getNodesOfType(AuthManager.class);
849
        List<JMeterTreeNode> authManagerNodes = jmeterTreeModel.getNodesOfType(AuthManager.class);
824
        if (authManagerNodes.size() == 0) {
850
        if (authManagerNodes.size() == 0) {
825
            try {
851
            try {
Lines 835-840 public class ProxyControl extends GenericController { Link Here
835
        }
861
        }
836
    }
862
    }
837
863
864
    private JMeterTreeModel getJmeterTreeModel() {
865
        if (this.nonGuiTreeModel == null) {
866
            return GuiPackage.getInstance().getTreeModel();
867
        }
868
        return this.nonGuiTreeModel;
869
    }
870
838
    /**
871
    /**
839
     * Helper method to add a Response Assertion
872
     * Helper method to add a Response Assertion
840
     * Called from AWT Event thread
873
     * Called from AWT Event thread
Lines 980-986 public class ProxyControl extends GenericController { Link Here
980
     *         <code>null</code> if none was found.
1013
     *         <code>null</code> if none was found.
981
     */
1014
     */
982
    private JMeterTreeNode findFirstNodeOfType(Class<?> type) {
1015
    private JMeterTreeNode findFirstNodeOfType(Class<?> type) {
983
        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
1016
        JMeterTreeModel treeModel = getJmeterTreeModel();
984
        List<JMeterTreeNode> nodes = treeModel.getNodesOfType(type);
1017
        List<JMeterTreeNode> nodes = treeModel.getNodesOfType(type);
985
        for (JMeterTreeNode node : nodes) {
1018
        for (JMeterTreeNode node : nodes) {
986
            if (node.isEnabled()) {
1019
            if (node.isEnabled()) {
Lines 1046-1052 public class ProxyControl extends GenericController { Link Here
1046
     */
1079
     */
1047
    // TODO - could be converted to generic class?
1080
    // TODO - could be converted to generic class?
1048
    private Collection<?> findApplicableElements(JMeterTreeNode myTarget, Class<? extends TestElement> myClass, boolean ascending) {
1081
    private Collection<?> findApplicableElements(JMeterTreeNode myTarget, Class<? extends TestElement> myClass, boolean ascending) {
1049
        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
1082
        JMeterTreeModel treeModel = getJmeterTreeModel();
1050
        LinkedList<TestElement> elements = new LinkedList<>();
1083
        LinkedList<TestElement> elements = new LinkedList<>();
1051
1084
1052
        // Look for elements directly within the HTTP proxy:
1085
        // Look for elements directly within the HTTP proxy:
Lines 1104-1110 public class ProxyControl extends GenericController { Link Here
1104
    private void placeSampler(final HTTPSamplerBase sampler, final TestElement[] testElements,
1137
    private void placeSampler(final HTTPSamplerBase sampler, final TestElement[] testElements,
1105
            JMeterTreeNode myTarget) {
1138
            JMeterTreeNode myTarget) {
1106
        try {
1139
        try {
1107
            final JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
1140
            final JMeterTreeModel treeModel = getJmeterTreeModel();
1108
1141
1109
            boolean firstInBatch = false;
1142
            boolean firstInBatch = false;
1110
            long now = System.currentTimeMillis();
1143
            long now = System.currentTimeMillis();
Lines 1326-1332 public class ProxyControl extends GenericController { Link Here
1326
     *            sampling event to be delivered
1359
     *            sampling event to be delivered
1327
     */
1360
     */
1328
    private void notifySampleListeners(SampleEvent event) {
1361
    private void notifySampleListeners(SampleEvent event) {
1329
        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
1362
        JMeterTreeModel treeModel = getJmeterTreeModel();
1330
        JMeterTreeNode myNode = treeModel.getNodeOf(this);
1363
        JMeterTreeNode myNode = treeModel.getNodeOf(this);
1331
        Enumeration<JMeterTreeNode> kids = myNode.children();
1364
        Enumeration<JMeterTreeNode> kids = myNode.children();
1332
        while (kids.hasMoreElements()) {
1365
        while (kids.hasMoreElements()) {
Lines 1345-1351 public class ProxyControl extends GenericController { Link Here
1345
     * (here meaning the proxy recording) has started.
1378
     * (here meaning the proxy recording) has started.
1346
     */
1379
     */
1347
    private void notifyTestListenersOfStart() {
1380
    private void notifyTestListenersOfStart() {
1348
        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
1381
        JMeterTreeModel treeModel = getJmeterTreeModel();
1349
        JMeterTreeNode myNode = treeModel.getNodeOf(this);
1382
        JMeterTreeNode myNode = treeModel.getNodeOf(this);
1350
        Enumeration<JMeterTreeNode> kids = myNode.children();
1383
        Enumeration<JMeterTreeNode> kids = myNode.children();
1351
        while (kids.hasMoreElements()) {
1384
        while (kids.hasMoreElements()) {
Lines 1364-1370 public class ProxyControl extends GenericController { Link Here
1364
     * (here meaning the proxy recording) has ended.
1397
     * (here meaning the proxy recording) has ended.
1365
     */
1398
     */
1366
    private void notifyTestListenersOfEnd() {
1399
    private void notifyTestListenersOfEnd() {
1367
        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
1400
        JMeterTreeModel treeModel = getJmeterTreeModel();
1368
        JMeterTreeNode myNode = treeModel.getNodeOf(this);
1401
        JMeterTreeNode myNode = treeModel.getNodeOf(this);
1369
        Enumeration<JMeterTreeNode> kids = myNode.children();
1402
        Enumeration<JMeterTreeNode> kids = myNode.children();
1370
        while (kids.hasMoreElements()) {
1403
        while (kids.hasMoreElements()) {
1371
- 

Return to bug 57305