/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.apache.jmeter.protocol.http.sampler;

import java.net.URL;

import org.apache.jmeter.samplers.SampleResult;
//import org.apache.jorphan.logging.LoggingManager;
//import org.apache.log.Logger;

/**
 * This is a specialisation of the SampleResult class for the HTTP protocol.
 * 
 * @author <a href="mailto:jsalvata@apache.org">Jordi Salvat i Alabart</a>
 * @version $Revision$ updated on $Date$
 */
public class HTTPSampleResult extends SampleResult {
	//private static final Logger log = LoggingManager.getLoggerForClass();

	public HTTPSampleResult() {
		super();
	}

	public HTTPSampleResult(long elapsed) {
		super(elapsed, true);
	}

	/**
	 * Construct a 'parent' result for an already-existing result, essentially
	 * cloning it
	 * 
	 * @param res
	 *            existing sample result
	 */
	public HTTPSampleResult(HTTPSampleResult res) {
		super(res);
		method=res.method;
		setURL(res.getURL());
		cookies=res.cookies;
        queryString=res.queryString;
        redirectLocation=res.redirectLocation;
	}

	private String method;

	public void setHTTPMethod(String method) {
		this.method = method;
	}

	public String getHTTPMethod() {
		return method;
	}

	private String redirectLocation;

	public void setRedirectLocation(String redirectLocation) {
		this.redirectLocation = redirectLocation;
	}

	public String getRedirectLocation() {
		return redirectLocation;
	}

	/**
	 * Determine whether this result is a redirect.
	 * 
	 * @return true iif res is an HTTP redirect response
	 */
	public boolean isRedirect() {
		final String[] REDIRECT_CODES = { "301", "302", "303" }; // NOT 304!
		String code = getResponseCode();
		for (int i = 0; i < REDIRECT_CODES.length; i++) {
			if (REDIRECT_CODES[i].equals(code))
				return true;
		}
		return false;
	}

	/*
	 * (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(method);
		URL u = super.getURL();
		if (u != null) {
			sb.append(' ');
			sb.append(u.toString());
            sb.append("\n");
			if (HTTPSamplerBase.POST.equals(method)) {
                sb.append("\nPOST data:\n");
				sb.append(queryString);
                sb.append("\n");
            }
            if (cookies.length()>0){
                sb.append("\nCookie Data:\n");
    			sb.append(cookies);
            } else {
                sb.append("\n[no cookies]");
            }
            sb.append("\n");
		}
		return sb.toString();
	}

	private String cookies = ""; // never null

	/**
	 * @return cookies as a string
	 */
	public String getCookies() {
		return cookies;
	}

	/**
	 * @param string
	 *            representing the cookies
	 */
	public void setCookies(String string) {
        if (string == null) {
            cookies="";// $NON-NLS-1$
        } else {
    		cookies = string;
        }
	}

	private String queryString = ""; // never null

	/**
	 * Fetch the query string
	 * 
	 * @return the query string
	 */
	public String getQueryString() {
		return queryString;
	}

	/**
	 * Save the query string
	 * 
	 * @param string
	 *            the query string
	 */
	public void setQueryString(String string) {
        if (string == null ) {
            queryString="";// $NON-NLS-1$
        } else {
    		queryString = string;
        }
	}
    
}

@@ -921,92 +921,8 @@
 ult;
-%0A//import org.apache.jorphan.logging.LoggingManager;%0A//import org.apache.log.Logger;
 %0A%0A/*
@@ -1007,17 +1007,16 @@
 %0A * %0A * 
-@
 author %3C
@@ -1082,49 +1082,8 @@
 /a%3E%0A
- * @version $Revision$ updated on $Date$%0A
  */%0A
@@ -1139,19 +1139,18 @@
 t %7B%0A
+%0A
 %09
-//
 private 
 stat
@@ -1149,69 +1149,151 @@
 ate 
-static final Logger log = LoggingManager.getLoggerForClass();
+String cookies = %22%22; // never null%0A%0A%09private String method;%0A%0A%09private String redirectLocation;%0A%0A%09private String queryString = %22%22; // never null
 %0A%0A%09p
@@ -1650,32 +1650,8 @@
 od;%0A
-%09%09setURL(res.getURL());%0A
 %09%09co
@@ -1761,33 +1761,8 @@
 %09%7D%0A%0A
-%09private String method;%0A%0A
 %09pub
@@ -1887,43 +1887,8 @@
 %09%7D%0A%0A
-%09private String redirectLocation;%0A%0A
 %09pub
@@ -3249,53 +3249,8 @@
 %09%7D%0A%0A
-%09private String cookies = %22%22; // never null%0A%0A
 %09/**
@@ -3575,57 +3575,8 @@
 %09%7D%0A%0A
-%09private String queryString = %22%22; // never null%0A%0A
 %09/**

Move update of parent fields to parent; tidy