Search in sources :

Example 11 with CookieManager

use of org.apache.jmeter.protocol.http.control.CookieManager in project jmeter by apache.

the class AjpSampler method getHeaderSize.

private int getHeaderSize(String method, URL url) {
    HeaderManager headers = getHeaderManager();
    CookieManager cookies = getCookieManager();
    AuthManager auth = getAuthManager();
    // Host always
    int hsz = 1;
    if (method.equals(HTTPConstants.POST)) {
        HTTPFileArg[] hfa = getHTTPFiles();
        if (hfa.length > 0) {
            hsz += 3;
        } else {
            hsz += 2;
        }
    }
    if (headers != null) {
        hsz += headers.size();
    }
    if (cookies != null) {
        hsz += cookies.getCookieCount();
    }
    if (auth != null) {
        String authHeader = auth.getAuthHeaderForURL(url);
        if (authHeader != null) {
            ++hsz;
        }
    }
    return hsz;
}
Also used : AuthManager(org.apache.jmeter.protocol.http.control.AuthManager) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) CookieManager(org.apache.jmeter.protocol.http.control.CookieManager) HeaderManager(org.apache.jmeter.protocol.http.control.HeaderManager)

Example 12 with CookieManager

use of org.apache.jmeter.protocol.http.control.CookieManager in project jmeter by apache.

the class CookiePanel method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    String action = e.getActionCommand();
    if (action.equals(DELETE_COMMAND)) {
        if (tableModel.getRowCount() > 0) {
            // If a table cell is being edited, we must cancel the editing
            // before deleting the row.
            GuiUtils.cancelEditing(cookieTable);
            if (cookieTable.getRowCount() > 0) {
                int rowSelected = cookieTable.getSelectedRow();
                if (rowSelected < 0) {
                    rowSelected = 0;
                }
                tableModel.removeRow(rowSelected);
                tableModel.fireTableDataChanged();
                // Disable the DELETE and SAVE buttons if no rows remaining
                // after delete.
                configureButtonsState();
                if (tableModel.getRowCount() > 0) {
                    // Table still contains one or more rows, so highlight
                    // (select) the appropriate one.
                    int rowToSelect = rowSelected;
                    if (rowSelected >= tableModel.getRowCount()) {
                        rowToSelect = rowSelected - 1;
                    }
                    cookieTable.setRowSelectionInterval(rowToSelect, rowToSelect);
                }
            }
        }
    } else if (action.equals(ADD_COMMAND)) {
        // If a table cell is being edited, we should accept the current
        // value and stop the editing before adding a new row.
        GuiUtils.stopTableEditing(cookieTable);
        tableModel.addNewRow();
        tableModel.fireTableDataChanged();
        configureButtonsState();
        // Highlight (select) the appropriate row.
        int rowToSelect = tableModel.getRowCount() - 1;
        cookieTable.setRowSelectionInterval(rowToSelect, rowToSelect);
    } else if (action.equals(LOAD_COMMAND)) {
        try {
            //$NON-NLS-1$
            final String[] _txt = { ".txt" };
            final JFileChooser chooser = FileDialoger.promptToOpenFile(_txt);
            if (chooser != null) {
                CookieManager manager = new CookieManager();
                manager.addFile(chooser.getSelectedFile().getAbsolutePath());
                for (int i = 0; i < manager.getCookieCount(); i++) {
                    addCookieToTable(manager.get(i));
                }
                tableModel.fireTableDataChanged();
                configureButtonsState();
            }
        } catch (IOException ex) {
            log.error("", ex);
        }
    } else if (action.equals(SAVE_COMMAND)) {
        try {
            //$NON-NLS-1$
            final JFileChooser chooser = FileDialoger.promptToSaveFile("cookies.txt");
            if (chooser != null) {
                ((CookieManager) createTestElement()).save(chooser.getSelectedFile().getAbsolutePath());
            }
        } catch (IOException ex) {
            JMeterUtils.reportErrorToUser(ex.getMessage(), "Error saving cookies");
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException) CookieManager(org.apache.jmeter.protocol.http.control.CookieManager)

Example 13 with CookieManager

use of org.apache.jmeter.protocol.http.control.CookieManager in project jmeter by apache.

the class CookiePanel method configure.

@Override
public void configure(TestElement el) {
    super.configure(el);
    CookieManager cookieManager = (CookieManager) el;
    populateTable(cookieManager);
    clearEachIteration.setSelected((cookieManager).getClearEachIteration());
    // must set policy after setting handler (which may change the policy)
    policy.setText(cookieManager.getPolicy());
}
Also used : CookieManager(org.apache.jmeter.protocol.http.control.CookieManager)

Aggregations

CookieManager (org.apache.jmeter.protocol.http.control.CookieManager)13 Test (org.junit.Test)3 IOException (java.io.IOException)2 Cookie (org.apache.jmeter.protocol.http.control.Cookie)2 HTTPSampler (org.apache.jmeter.protocol.http.sampler.HTTPSampler)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 JFileChooser (javax.swing.JFileChooser)1 AuthManager (org.apache.jmeter.protocol.http.control.AuthManager)1 HeaderManager (org.apache.jmeter.protocol.http.control.HeaderManager)1 LinkExtractorParseException (org.apache.jmeter.protocol.http.parser.LinkExtractorParseException)1 LinkExtractorParser (org.apache.jmeter.protocol.http.parser.LinkExtractorParser)1