You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2005/10/25 03:10:55 UTC
svn commit: r328218 - in
/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler:
HTTPSampleResult.java HTTPSampler.java HTTPSampler2.java
Author: sebb
Date: Mon Oct 24 18:10:46 2005
New Revision: 328218
URL: http://svn.apache.org/viewcvs?rev=328218&view=rev
Log:
Tidy up Request Data output; fix NPE in HTTPSampler2
Modified:
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
Modified: jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java?rev=328218&r1=328217&r2=328218&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java Mon Oct 24 18:10:46 2005
@@ -1,6 +1,5 @@
-// $Header$
/*
- * Copyright 2003-2004 The Apache Software Foundation.
+ * Copyright 2003-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,9 +49,11 @@
*/
public HTTPSampleResult(HTTPSampleResult res) {
super(res);
- setHTTPMethod(res.getHTTPMethod());
+ method=res.method;
setURL(res.getURL());
- setCookies(res.getCookies());
+ cookies=res.cookies;
+ queryString=res.queryString;
+ redirectLocation=res.redirectLocation;
}
private String method;
@@ -92,22 +93,26 @@
/*
* (non-Javadoc)
+ * Overrides version in Sampler data to provide more details
*
* @see org.apache.jmeter.samplers.SampleResult#getSamplerData()
*/
public String getSamplerData() {
StringBuffer sb = new StringBuffer();
- sb.append(getHTTPMethod());
+ sb.append(method);
URL u = super.getURL();
if (u != null) {
sb.append(' ');
sb.append(u.toString());
- if ("POST".equals(getHTTPMethod())) {
- sb.append(getQueryString());
+ if ("POST".equals(method)) {
+ sb.append(queryString);
}
sb.append("\n");
- sb.append(getRequestHeaders());
- sb.append(getCookies());
+ if (cookies.length()>0){
+ sb.append("\nCookie Data:\n");
+ sb.append(cookies);
+ sb.append("\n");
+ }
}
return sb.toString();
}
@@ -126,7 +131,11 @@
* representing the cookies
*/
public void setCookies(String string) {
- cookies = string;
+ if (string == null) {
+ cookies="";
+ } else {
+ cookies = string;
+ }
}
private String queryString = ""; // never null
@@ -147,7 +156,11 @@
* the query string
*/
public void setQueryString(String string) {
- queryString = string;
+ if (string == null ) {
+ queryString="";
+ } else {
+ queryString = string;
+ }
}
}
Modified: jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java?rev=328218&r1=328217&r2=328218&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java Mon Oct 24 18:10:46 2005
@@ -151,29 +151,17 @@
conn.setRequestMethod(method);
String hdrs = setConnectionHeaders(conn, u, getHeaderManager());
String cookies = setConnectionCookie(conn, u, getCookieManager());
- if (res != null) {
- StringBuffer sb = new StringBuffer();
- if (method.equals(POST)) {
- String q = this.getQueryString();
- sb.append("\nQuery data:\n");
- sb.append(q);
- res.setQueryString(sb.toString());
- }
- if (cookies != null) {
- StringBuffer temp = new StringBuffer("\nCookie Data:\n");
- temp.append(cookies);
- temp.append('\n');
- res.setCookies(temp.toString());
- sb.append(temp);
- }
- res.setSamplerData(sb.toString());
- // TODO rather than stuff all the information in here,
- // pick it up from the individual fields later
- res.setURL(u);
- res.setHTTPMethod(method);
- res.setRequestHeaders(hdrs);
- }
+ if (res != null) {
+ res.setURL(u);
+ res.setHTTPMethod(method);
+ res.setRequestHeaders(hdrs);
+ res.setCookies(cookies);
+ if (method.equals(POST)) {
+ res.setQueryString(getQueryString());
+ }
+ }
+
setConnectionAuthorization(conn, u, getAuthManager());
if (method.equals(POST)) {
setPostHeaders(conn);
Modified: jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java?rev=328218&r1=328217&r2=328218&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java Mon Oct 24 18:10:46 2005
@@ -258,28 +258,13 @@
//System.out.println("setupConnection: cookies = " + cookies);
if (res != null) {
- StringBuffer sb = new StringBuffer();
- if (method.equals(POST)) {
- String q = this.getQueryString();
- res.setQueryString(q);
- sb.append("Query data:\n");
- sb.append(q);
- sb.append('\n');
- }
- if (cookies != null) {
- res.setCookies(cookies);
- sb.append("\nCookie Data:\n");
- sb.append(cookies);
- sb.append('\n');
- }
- res.setSamplerData(sb.toString());
- // TODO rather than stuff all the information in here,
- // pick it up from the individual fields later
-
- res.setURL(u);
- res.setHTTPMethod(method);
- res.setRequestHeaders(hdrs);
- res.setQueryString(getQueryString());
+ res.setURL(u);
+ res.setHTTPMethod(method);
+ res.setRequestHeaders(hdrs);
+ res.setCookies(cookies);
+ if (method.equals(POST)) {
+ res.setQueryString(getQueryString());
+ }
}
setConnectionAuthorization(httpMethod, u, getAuthManager());
@@ -355,24 +340,26 @@
// TODO recode to use HTTPClient matches methods or similar
String cookieHeader = ""; // $NON-NLS-1$
- String host = "." + u.getHost(); // $NON-NLS-1$
-
- for (int i = cookieManager.getCookies().size() - 1; i >= 0; i--) {
- Cookie cookie = (Cookie) cookieManager.getCookies().get(i).getObjectValue();
- long exp = cookie.getExpires();
- long now = System.currentTimeMillis() / 1000 ;
- if (cookie == null)
- continue;
- if ( host.endsWith(cookie.getDomain())
- && u.getFile().startsWith(cookie.getPath())
- && (exp == 0 || exp > now)) {
- org.apache.commons.httpclient.Cookie newCookie
- = new org.apache.commons.httpclient.Cookie(cookie.getDomain(), cookie.getName(),
- cookie.getValue(), cookie.getPath(), null, false);
- httpState.addCookie(newCookie);
- cookieHeader += cookie.getName() + "=" + cookie.getValue(); // $NON-NLS-1$
- }
- }
+ if (cookieManager!=null){
+ String host = "." + u.getHost(); // $NON-NLS-1$
+
+ for (int i = cookieManager.getCookies().size() - 1; i >= 0; i--) {
+ Cookie cookie = (Cookie) cookieManager.getCookies().get(i).getObjectValue();
+ long exp = cookie.getExpires();
+ long now = System.currentTimeMillis() / 1000 ;
+ if (cookie == null)
+ continue;
+ if ( host.endsWith(cookie.getDomain())
+ && u.getFile().startsWith(cookie.getPath())
+ && (exp == 0 || exp > now)) {
+ org.apache.commons.httpclient.Cookie newCookie
+ = new org.apache.commons.httpclient.Cookie(cookie.getDomain(), cookie.getName(),
+ cookie.getValue(), cookie.getPath(), null, false);
+ httpState.addCookie(newCookie);
+ cookieHeader += cookie.getName() + "=" + cookie.getValue(); // $NON-NLS-1$
+ }
+ }
+ }
return cookieHeader;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org