Hello,

In attachment, a proposal patch to change position of new "Proxy Server" panel to the end of page. More user-friendly (I think)
(see screenshots)

And change the proxy server title panel from "Proxy Server" to "Request via Proxy Server"

Milamber

Le 24/08/2009 22:38, s...@apache.org a ecrit :
Author: sebb
Date: Mon Aug 24 22:38:33 2009
New Revision: 807418

URL: http://svn.apache.org/viewvc?rev=807418&view=rev
Log:
Allow Proxy Server to be specified on HTTP Sampler GUI and HTTP Config GUI

Modified:
    
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
    
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
    
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
    
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
    jakarta/jmeter/trunk/xdocs/changes.xml

Modified: 
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=807418&r1=807417&r2=807418&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties 
(original)
+++ 
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties 
Mon Aug 24 22:38:33 2009
@@ -893,6 +893,7 @@
 view_results_title=View Results
 view_results_tree_title=View Results Tree
 warning=Warning!
+web_proxy_server_title=Proxy Server
 web_request=HTTP Request
 web_server=Web Server
 web_server_client=Client implementation:

Modified: 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java?rev=807418&r1=807417&r2=807418&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
 Mon Aug 24 22:38:33 2009
@@ -60,6 +60,14 @@
private JTextField port; + private JTextField proxyHost;
+
+    private JTextField proxyPort;
+
+    private JTextField proxyUser;
+
+    private JTextField proxyPass;
+
     private JTextField connectTimeOut;
private JTextField responseTimeOut;
@@ -104,6 +112,10 @@
         }
         path.setText(""); // $NON-NLS-1$
         port.setText(""); // $NON-NLS-1$
+        proxyHost.setText(""); // $NON-NLS-1$
+        proxyPort.setText(""); // $NON-NLS-1$
+        proxyUser.setText(""); // $NON-NLS-1$
+        proxyPass.setText(""); // $NON-NLS-1$
         connectTimeOut.setText(""); // $NON-NLS-1$
         responseTimeOut.setText(""); // $NON-NLS-1$
         protocol.setText(""); // $NON-NLS-1$
@@ -133,6 +145,10 @@
         element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, 
args));
         element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText());
         element.setProperty(HTTPSamplerBase.PORT, port.getText());
+        element.setProperty(HTTPSamplerBase.PROXYHOST, proxyHost.getText(),"");
+        element.setProperty(HTTPSamplerBase.PROXYPORT, proxyPort.getText(),"");
+        element.setProperty(HTTPSamplerBase.PROXYUSER, proxyUser.getText(),"");
+        element.setProperty(HTTPSamplerBase.PROXYPASS, proxyPass.getText(),"");
         element.setProperty(HTTPSamplerBase.CONNECT_TIMEOUT, 
connectTimeOut.getText());
         element.setProperty(HTTPSamplerBase.RESPONSE_TIMEOUT, 
responseTimeOut.getText());
         element.setProperty(HTTPSamplerBase.PROTOCOL, protocol.getText());
@@ -166,6 +182,10 @@
         } else {
             port.setText(portString);
         }
+        proxyHost.setText(el.getPropertyAsString(HTTPSamplerBase.PROXYHOST));
+        proxyPort.setText(el.getPropertyAsString(HTTPSamplerBase.PROXYPORT));
+        proxyUser.setText(el.getPropertyAsString(HTTPSamplerBase.PROXYUSER));
+        proxyPass.setText(el.getPropertyAsString(HTTPSamplerBase.PROXYPASS));
         
connectTimeOut.setText(el.getPropertyAsString(HTTPSamplerBase.CONNECT_TIMEOUT));
         
responseTimeOut.setText(el.getPropertyAsString(HTTPSamplerBase.RESPONSE_TIMEOUT));
         protocol.setText(el.getPropertyAsString(HTTPSamplerBase.PROTOCOL));
@@ -223,12 +243,29 @@
         final JPanel reqPanel = getResponseTimeOutPanel();
         timeOut.add(connPanel);
         timeOut.add(reqPanel);
- - + JPanel webServerTimeoutPanel = new VerticalPanel();
         webServerTimeoutPanel.add(webServerPanel, BorderLayout.CENTER);
         webServerTimeoutPanel.add(timeOut, BorderLayout.EAST);
-        return webServerTimeoutPanel;
+ + JPanel proxyServer = new HorizontalPanel();
+        proxyServer.add(getProxyHostPanel(), BorderLayout.CENTER);
+        proxyServer.add(getProxyPortPanel(), BorderLayout.EAST);
+ + JPanel proxyLogin = new HorizontalPanel();
+        proxyLogin.add(getProxyUserPanel());
+        proxyLogin.add(getProxyPassPanel());
+ + JPanel proxyServerPanel = new HorizontalPanel();
+        
proxyServerPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
+                JMeterUtils.getResString("web_proxy_server_title"))); // 
$NON-NLS-1$
+        proxyServerPanel.add(proxyServer, BorderLayout.CENTER);
+        proxyServerPanel.add(proxyLogin, BorderLayout.EAST);
+ + JPanel bigPanel = new VerticalPanel();
+        bigPanel.add(webServerTimeoutPanel);
+        bigPanel.add(proxyServerPanel);
+        return bigPanel;
     }
private JPanel getPortPanel() {
@@ -244,6 +281,19 @@
         return panel;
     }
+ private JPanel getProxyPortPanel() {
+        proxyPort = new JTextField(4);
+
+        JLabel label = new 
JLabel(JMeterUtils.getResString("web_server_port")); // $NON-NLS-1$
+        label.setLabelFor(proxyPort);
+
+        JPanel panel = new JPanel(new BorderLayout(5, 0));
+        panel.add(label, BorderLayout.WEST);
+        panel.add(proxyPort, BorderLayout.CENTER);
+
+        return panel;
+    }
+
     private JPanel getConnectTimeOutPanel() {
         connectTimeOut = new JTextField(4);
@@ -282,6 +332,42 @@
         return panel;
     }
+ private JPanel getProxyHostPanel() {
+        proxyHost = new JTextField(20);
+
+        JLabel label = new 
JLabel(JMeterUtils.getResString("web_server_domain")); // $NON-NLS-1$
+        label.setLabelFor(proxyHost);
+
+        JPanel panel = new JPanel(new BorderLayout(5, 0));
+        panel.add(label, BorderLayout.WEST);
+        panel.add(proxyHost, BorderLayout.CENTER);
+        return panel;
+    }
+
+    private JPanel getProxyUserPanel() {
+        proxyUser = new JTextField(5);
+
+        JLabel label = new JLabel(JMeterUtils.getResString("username")); // 
$NON-NLS-1$
+        label.setLabelFor(proxyUser);
+
+        JPanel panel = new JPanel(new BorderLayout(5, 0));
+        panel.add(label, BorderLayout.WEST);
+        panel.add(proxyUser, BorderLayout.CENTER);
+        return panel;
+    }
+
+    private JPanel getProxyPassPanel() {
+        proxyPass = new JTextField(5);
+
+        JLabel label = new JLabel(JMeterUtils.getResString("password")); // 
$NON-NLS-1$
+        label.setLabelFor(proxyPass);
+
+        JPanel panel = new JPanel(new BorderLayout(5, 0));
+        panel.add(label, BorderLayout.WEST);
+        panel.add(proxyPass, BorderLayout.CENTER);
+        return panel;
+    }
+
     /**
      * This method defines the Panel for the HTTP path, 'Follow Redirects'
      * 'Use KeepAlive', and 'Use multipart for HTTP POST' elements.

Modified: 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java?rev=807418&r1=807417&r2=807418&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
 Mon Aug 24 22:38:33 2009
@@ -23,6 +23,8 @@
import java.net.BindException;
 import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
 import java.net.URL;
 import java.net.URLConnection;
@@ -148,7 +150,22 @@
             }
         }
- HttpURLConnection conn = (HttpURLConnection) u.openConnection();
+        final HttpURLConnection conn;
+        final String proxyHost = getProxyHost();
+        final int proxyPort = getProxyPortInt();
+        if (proxyHost.length() > 0 && proxyPort > 0){
+            Proxy proxy = new Proxy(Proxy.Type.HTTP, new 
InetSocketAddress(proxyHost, proxyPort));
+            //TODO - how to define proxy authentication for a single 
connection?
+            // It's not clear if this is possible
+//            String user = getProxyUser();
+//            if (user.length() > 0){
+//                Authenticator auth = new ProxyAuthenticator(user, 
getProxyPass());
+//            }
+            conn = (HttpURLConnection) u.openConnection(proxy);
+        } else {
+            conn = (HttpURLConnection) u.openConnection();
+        }
+
         // Update follow redirects setting just for this connection
         conn.setInstanceFollowRedirects(getAutoRedirects());
@@ -435,6 +452,7 @@
         res.setMonitor(isMonitor());
res.setSampleLabel(urlStr); + res.sampleStart(); // Count the retries as well in the time
         try {
             // Sampling proper - establish the connection and read the 
response:
@@ -446,7 +464,7 @@
                     conn = setupConnection(url, method, res);
                     // Attempt the connection:
                     savedConn = conn;
-                    conn.connect();
+ conn.connect(); break;
                 } catch (BindException e) {
                     if (retry >= MAX_CONN_RETRIES) {

Modified: 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java?rev=807418&r1=807417&r2=807418&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
 Mon Aug 24 22:38:33 2009
@@ -99,22 +99,22 @@
private static final boolean canSetPreEmptive; // OK to set pre-emptive auth? - static final String PROXY_HOST =
+    private static final String PROXY_HOST =
         System.getProperty("http.proxyHost",""); // $NON-NLS-1$
private static final String NONPROXY_HOSTS =
         System.getProperty("http.nonProxyHosts",""); // $NON-NLS-1$
- static final int PROXY_PORT =
+    private static final int PROXY_PORT =
         Integer.parseInt(System.getProperty("http.proxyPort","0")); // 
$NON-NLS-1$
// Have proxy details been provided?
     private static final boolean PROXY_DEFINED = PROXY_HOST.length() > 0 && 
PROXY_PORT > 0;
- static final String PROXY_USER =
+    private static final String PROXY_USER =
         JMeterUtils.getPropDefault(JMeter.HTTP_PROXY_USER,""); // $NON-NLS-1$
- static final String PROXY_PASS =
+    private static final String PROXY_PASS =
         JMeterUtils.getPropDefault(JMeter.HTTP_PROXY_PASS,""); // $NON-NLS-1$
private static final String PROXY_DOMAIN =
@@ -538,15 +538,26 @@
             hc.setLocalAddress(localAddress);
         }
- boolean useProxy = PROXY_DEFINED && !isNonProxy(host);
-        if (useProxy) {
-            if (log.isDebugEnabled()){
-                log.debug("Setting proxy: "+PROXY_HOST+":"+PROXY_PORT);
+        boolean useStaticProxy = PROXY_DEFINED && !isNonProxy(host);
+        boolean useDynamicProxy = false;
+ + final String proxyHost = getProxyHost();
+        final int proxyPort = getProxyPortInt();
+        if (proxyHost.length() > 0 && proxyPort > 0){
+            hc.setProxy(proxyHost, proxyPort);
+            useStaticProxy = false; // Dynamic proxy overrules static proxy
+            useDynamicProxy = true;
+        } else {
+            if (useStaticProxy) {
+                if (log.isDebugEnabled()){
+                    log.debug("Setting proxy: "+PROXY_HOST+":"+PROXY_PORT);
+                }
+                hc.setProxy(PROXY_HOST, PROXY_PORT);
             }
-            hc.setProxy(PROXY_HOST, PROXY_PORT);
         }
Map<HostConfiguration, HttpClient> map = httpClients.get();
+        // N.B. HostConfiguration.equals() includes proxy settings in the 
compare.
         HttpClient httpClient = map.get(hc);
if ( httpClient == null )
@@ -557,22 +568,36 @@
             }
             httpClient.setHostConfiguration(hc);
             map.put(hc, httpClient);
-            // These items don't change, so only need to be done once
-            if (useProxy) {
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("Reusing the HttpClient: 
@"+System.identityHashCode(httpClient));
+            }
+        }
+
+        // Set up any required Proxy credentials
+        if (useDynamicProxy){
+            String user = getProxyUser();
+            if (user.length() > 0){
+                httpClient.getState().setProxyCredentials(
+                        new 
AuthScope(proxyHost,proxyPort,null,AuthScope.ANY_SCHEME),
+                        new 
NTCredentials(user,getProxyPass(),localHost,PROXY_DOMAIN)
+ ); + } else { + httpClient.getState().clearProxyCredentials(); + }
+        } else {
+            if (useStaticProxy) {
                 if (PROXY_USER.length() > 0){
                     httpClient.getState().setProxyCredentials(
                         new 
AuthScope(PROXY_HOST,PROXY_PORT,null,AuthScope.ANY_SCHEME),
                         new 
NTCredentials(PROXY_USER,PROXY_PASS,localHost,PROXY_DOMAIN)
                     );
                 }
-            }
-
-        } else {
-            if (log.isDebugEnabled()) {
-                log.debug("Reusing the HttpClient: 
@"+System.identityHashCode(httpClient));
+            } else {
+                httpClient.getState().clearProxyCredentials();
             }
         }
-
+ int rto = getResponseTimeout();
         if (rto > 0){
             httpMethod.getParams().setSoTimeout(rto);

Modified: 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java?rev=807418&r1=807417&r2=807418&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java
 Mon Aug 24 22:38:33 2009
@@ -94,6 +94,14 @@
public static final String PORT = "HTTPSampler.port"; // $NON-NLS-1$ + public static final String PROXYHOST = "HTTPSampler.proxyHost"; // $NON-NLS-1$
+
+    public static final String PROXYPORT = "HTTPSampler.proxyPort"; // 
$NON-NLS-1$
+
+    public static final String PROXYUSER = "HTTPSampler.proxyUser"; // 
$NON-NLS-1$
+
+    public static final String PROXYPASS = "HTTPSampler.proxyPass"; // 
$NON-NLS-1$
+
     public static final String CONNECT_TIMEOUT = 
"HTTPSampler.connect_timeout"; // $NON-NLS-1$
public static final String RESPONSE_TIMEOUT = "HTTPSampler.response_timeout"; // $NON-NLS-1$
@@ -720,6 +728,22 @@
         return getPropertyAsInt(RESPONSE_TIMEOUT, 0);
     }
+ public String getProxyHost() {
+        return getPropertyAsString(PROXYHOST);
+    }
+
+    public int getProxyPortInt() {
+        return getPropertyAsInt(PROXYPORT, 0);
+    }
+
+    public String getProxyUser() {
+        return getPropertyAsString(PROXYUSER);
+    }
+
+    public String getProxyPass() {
+        return getPropertyAsString(PROXYPASS);
+    }
+
     public void setArguments(Arguments value) {
         setProperty(new TestElementProperty(ARGUMENTS, value));
     }

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=807418&r1=807417&r2=807418&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Mon Aug 24 22:38:33 2009
@@ -109,6 +109,7 @@
 <h3>HTTP Samplers</h3>
 <ul>
 <li>Bug 47622 - enable recording of HTTPS sessions</li>
+<li>Allow Proxy Server to be specified on HTTP Sampler GUI and HTTP Config 
GUI</li>
 </ul>
<h3>Other samplers</h3>



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org



Index: /src/core/org/apache/jmeter/resources/messages.properties
===================================================================
--- /src/core/org/apache/jmeter/resources/messages.properties	(revision 819077)
+++ /src/core/org/apache/jmeter/resources/messages.properties	(working copy)
@@ -906,7 +906,7 @@
 view_results_title=View Results
 view_results_tree_title=View Results Tree
 warning=Warning!
-web_proxy_server_title=Proxy Server
+web_proxy_server_title=Request via Proxy Server
 web_request=HTTP Request
 web_server=Web Server
 web_server_client=Client implementation:
Index: /src/protocol/http/org/apache/jmeter/protocol/http/config/gui/MultipartUrlConfigGui.java
===================================================================
--- /src/protocol/http/org/apache/jmeter/protocol/http/config/gui/MultipartUrlConfigGui.java	(revision 818668)
+++ /src/protocol/http/org/apache/jmeter/protocol/http/config/gui/MultipartUrlConfigGui.java	(working copy)
@@ -80,6 +80,7 @@
 
         this.add(getWebServerTimeoutPanel(), BorderLayout.NORTH);
         this.add(webRequestPanel, BorderLayout.CENTER);
+        this.add(getProxyServerPanel(), BorderLayout.SOUTH);
     }
 
     private JPanel getHTTPFileArgsPanel() {
Index: /src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
===================================================================
--- /src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java	(revision 818668)
+++ /src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java	(working copy)
@@ -219,6 +219,7 @@
 
         this.add(getWebServerTimeoutPanel(), BorderLayout.NORTH);
         this.add(webRequestPanel, BorderLayout.CENTER);
+        this.add(getProxyServerPanel(), BorderLayout.SOUTH);
     }
 
     /**
@@ -247,7 +248,10 @@
         JPanel webServerTimeoutPanel = new VerticalPanel();
         webServerTimeoutPanel.add(webServerPanel, BorderLayout.CENTER);
         webServerTimeoutPanel.add(timeOut, BorderLayout.EAST);
-        
+        return webServerTimeoutPanel;
+    }
+    
+    protected JPanel getProxyServerPanel() {
         JPanel proxyServer = new HorizontalPanel();
         proxyServer.add(getProxyHostPanel(), BorderLayout.CENTER);
         proxyServer.add(getProxyPortPanel(), BorderLayout.EAST);
@@ -261,11 +265,7 @@
                 JMeterUtils.getResString("web_proxy_server_title"))); // $NON-NLS-1$
         proxyServerPanel.add(proxyServer, BorderLayout.CENTER);
         proxyServerPanel.add(proxyLogin, BorderLayout.EAST);
-        
-        JPanel bigPanel = new VerticalPanel();
-        bigPanel.add(webServerTimeoutPanel);
-        bigPanel.add(proxyServerPanel);
-        return bigPanel;
+        return proxyServerPanel;
     }
 
     private JPanel getPortPanel() {


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org

Reply via email to