Author: pmouawad
Date: Sat Dec 26 23:06:17 2015
New Revision: 1721771
URL: http://svn.apache.org/viewvc?rev=1721771&view=rev
Log:
Bug 57804 - HTTP Request doesn't reuse cached SSL context when using Client
Certificates in HTTPS
Bugzilla Id: 57804
Modified:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
jmeter/trunk/xdocs/changes.xml
Modified:
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1721771&r1=1721770&r2=1721771&view=diff
==============================================================================
---
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
(original)
+++
jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
Sat Dec 26 23:06:17 2015
@@ -72,6 +72,7 @@ import org.apache.http.client.methods.Ht
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
+import org.apache.http.client.protocol.ClientContext;
import org.apache.http.client.protocol.ResponseContentEncoding;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
@@ -120,6 +121,7 @@ import org.apache.jmeter.services.FileSe
import org.apache.jmeter.testelement.property.CollectionProperty;
import org.apache.jmeter.testelement.property.JMeterProperty;
import org.apache.jmeter.testelement.property.PropertyIterator;
+import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.util.JsseSSLManager;
import org.apache.jmeter.util.SSLManager;
@@ -201,6 +203,8 @@ public class HTTPHC4Impl extends HTTPHCA
*/
private static final HttpParams DEFAULT_HTTP_PARAMS;
+ private static final String USER_TOKEN = "__jmeter.USER_TOKEN__";
//$NON-NLS-1$
+
static {
log.info("HTTP request retry count = "+RETRY_COUNT);
@@ -313,6 +317,7 @@ public class HTTPHC4Impl extends HTTPHCA
}
HttpContext localContext = new BasicHttpContext();
+ setupClientContextBeforeSample(localContext);
res.sampleStart();
@@ -332,6 +337,7 @@ public class HTTPHC4Impl extends HTTPHCA
// Needs to be done after execute to pick up all the headers
final HttpRequest request = (HttpRequest)
localContext.getAttribute(ExecutionContext.HTTP_REQUEST);
+ extractClientContextAfterSample(localContext);
// We've finished with the request, so we can add the LocalAddress
to it for display
final InetAddress localAddr = (InetAddress)
httpRequest.getParams().getParameter(ConnRoutePNames.LOCAL_ADDRESS);
if (localAddr != null) {
@@ -434,6 +440,45 @@ public class HTTPHC4Impl extends HTTPHCA
}
/**
+ * Store in JMeter Variables the UserToken so that the SSL context is
reused
+ * See https://bz.apache.org/bugzilla/show_bug.cgi?id=57804
+ * @param localContext {@link HttpContext}
+ */
+ private final void extractClientContextAfterSample(HttpContext
localContext) {
+ Object userToken = localContext.getAttribute(ClientContext.USER_TOKEN);
+ if(userToken != null) {
+ if(log.isDebugEnabled()) {
+ log.debug("Extracted from HttpContext user
token:"+userToken+", storing it as JMeter variable:"+USER_TOKEN);
+ }
+
JMeterContextService.getContext().getVariables().putObject(USER_TOKEN,
userToken);
+ }
+ }
+
+ /**
+ * Configure the UserToken so that the SSL context is reused
+ * See https://bz.apache.org/bugzilla/show_bug.cgi?id=57804
+ * @param localContext {@link HttpContext}
+ */
+ private final void setupClientContextBeforeSample(HttpContext
localContext) {
+ Object userToken =
JMeterContextService.getContext().getVariables().getObject(USER_TOKEN);
+ if(userToken != null) {
+ if(log.isDebugEnabled()) {
+ log.debug("Found user token:"+userToken+" as JMeter
variable:"+USER_TOKEN+", storing it in HttpContext");
+ }
+ localContext.setAttribute(ClientContext.USER_TOKEN, userToken);
+ } else {
+ // It would be better to create a ClientSessionManager that would
compute this value
+ // for now it can be Thread.currentThread().getName() but must be
changed when we would change
+ // the Thread per User model
+ String userId = Thread.currentThread().getName();
+ if(log.isDebugEnabled()) {
+ log.debug("Storing in HttpContext the user token:"+userId);
+ }
+ localContext.setAttribute(ClientContext.USER_TOKEN, userId);
+ }
+ }
+
+ /**
* Calls {@link #sendPostData(HttpPost)} if method is <code>POST</code> and
* {@link #sendEntityData(HttpEntityEnclosingRequestBase)} if method is
* <code>PUT</code> or <code>PATCH</code>
Modified: jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1721771&r1=1721770&r2=1721771&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Dec 26 23:06:17 2015
@@ -190,6 +190,7 @@ Summary
<li><bug>58137</bug>JMeter fails to download embedded URLS that contain
illegal characters in URL (it does not escape them).</li>
<li><bug>58201</bug>Make usage of port in the host header more consistent
across the different http samplers.</li>
<li><bug>58453</bug>HTTP Test Script Recorder : NullPointerException when
disabling Capture HTTP Headers </li>
+ <li><bug>57804</bug>HTTP Request doesn't reuse cached SSL context when
using Client Certificates in HTTPS (only fixed for HttpClient4
implementation)</li>
</ul>
<h3>Other Samplers</h3>