/*
 * Copyright 2004-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. 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.
 *  
 */

/*
 * Created on Sep 14, 2004
 *
 */
package org.apache.jmeter.protocol.http.util;

import java.net.URL;

import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult;
import org.apache.jmeter.samplers.SampleSaveConfiguration;
import org.apache.jmeter.save.converters.SampleResultConverter;

import com.thoughtworks.xstream.alias.ClassMapper;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

/**
 * @author mstover
 * 
 */
public class HTTPResultConverter extends SampleResultConverter
{

   /**
    * @param arg0
    * @param arg1
    */
   public HTTPResultConverter(ClassMapper arg0, String arg1)
   {
      super(arg0, arg1);
   }

   /*
    * (non-Javadoc)
    * 
    * @see com.thoughtworks.xstream.converters.Converter#canConvert(java.lang.Class)
    */
   public boolean canConvert(Class arg0)
   {
      return HTTPSampleResult.class.equals(arg0);
   }

   /*
    * (non-Javadoc)
    * 
    * @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object,
    *      com.thoughtworks.xstream.io.HierarchicalStreamWriter,
    *      com.thoughtworks.xstream.converters.MarshallingContext)
    */
   public void marshal(Object obj, HierarchicalStreamWriter writer,
         MarshallingContext context)
   {
      HTTPSampleResult res = (HTTPSampleResult) obj;
      SampleSaveConfiguration save = res.getSaveConfig();
      setAttributes(writer, context, res, save);
      saveAssertions(writer, context, res, save);
      saveSubResults(writer, context, res, save);
      saveResponseHeaders(writer, context, res, save);
      saveRequestHeaders(writer, context, res, save);
      saveResponseData(writer, context, res, save);
      saveSamplerData(writer, context, res, save);
   }

   /*
    * (non-Javadoc)
    * 
    * @see org.apache.jmeter.save.converters.SampleResultConverter#saveSamplerData(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
    *      org.apache.jmeter.samplers.SampleResult,
    *      org.apache.jmeter.samplers.SampleSaveConfiguration)
    */
   protected void saveSamplerData(HierarchicalStreamWriter writer,
         MarshallingContext context, HTTPSampleResult res,
         SampleSaveConfiguration save)
   {
      if (save.saveSamplerData(res))
      {
         writeString(writer, "cookies", res.getCookies());
         writeString(writer, "method", res.getHTTPMethod());
         writeString(writer, "queryString", res.getQueryString());
         writeString(writer, "redirectLocation", res.getRedirectLocation());
         writeItem(res.getURL(), context, writer);
      }
   }

   /*
    * (non-Javadoc)
    * 
    * @see com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader,
    *      com.thoughtworks.xstream.converters.UnmarshallingContext)
    */
   public Object unmarshal(HierarchicalStreamReader reader,
         UnmarshallingContext context)
   {
      HTTPSampleResult res = (HTTPSampleResult) createCollection(context
            .getRequiredType());
      retrieveAttributes(reader, context, res);
      while (reader.hasMoreChildren())
      {
         reader.moveDown();
         Object subItem = readItem(reader, context, res);
         if (!retrieveItem(reader, context, res, subItem))
         {
            retrieveHTTPItem(reader, context, res, subItem);
         }
         reader.moveUp();
      }
      return res;
   }

   protected void retrieveHTTPItem(HierarchicalStreamReader reader,
         UnmarshallingContext context, HTTPSampleResult res, Object subItem)
   {
      if (subItem instanceof URL)
      {
         res.setURL((URL) subItem);
      }
      else if (reader.getNodeName().equals("cookies"))
      {
         res.setCookies((String) subItem);
      }
      else if (reader.getNodeName().equals("method"))
      {
         res.setHTTPMethod((String) subItem);
      }
      else if (reader.getNodeName().equals("queryString"))
      {
         res.setQueryString((String) subItem);
      }
      else if (reader.getNodeName().equals("redirectLocation"))
      {
         res.setRedirectLocation((String) subItem);
      }
   }
}
@@ -1312,16 +1312,201 @@
 rter%0A%7B%0A%0A
+    /**%0A     * Returns the converter version; used to check for possible%0A     * incompatibilities%0A     */%0A    public static String getVersion()%0A    %7B%0A       return %22$Revision$%22;%0A    %7D%0A%0A
    /**%0A 

Add version info