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

import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URLConnection;


/**
 * @author Administrator
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 */
public class SoapSampler extends HTTPSampler 
{
	public static final String XML_DATA = "HTTPSamper.xml_data";
	
	public void setXmlData(String data)
	{
		setProperty(XML_DATA,data);
	}
	
	public String getXmlData()
	{
		return getPropertyAsString(XML_DATA);
	}

		/****************************************
	 * Send POST data from <code>Entry</code> to the open connection.
	 *
	 *@param connection       <code>URLConnection</code> of where POST data should
	 *      be sent
	 *@param url              contains the query string for POST
	 *@exception IOException  if an I/O exception occurs
	 ***************************************/
	public void sendPostData(URLConnection connection)
			 throws IOException
	{
		((HttpURLConnection)connection).setRequestMethod("POST");
		connection.setRequestProperty("Content-length", "" + getXmlData().length());
		connection.setRequestProperty("Content-type", "text/xml");
		connection.setDoOutput(true);
		PrintWriter out = new PrintWriter(connection.getOutputStream());
		out.print(getXmlData());
		out.close();
	}
}

@@ -178,148 +178,96 @@
 %0A * 
-@author Administrator%0A *%0A * To change this generated comment edit the template variable %22typecomment%22:%0A * Window%3EPreferences%3EJava%3ETemplates.
+Sampler to handle SOAP Requests%0A *%0A *%0A * @author Jordi Salvat i Alabart%0A * @version $Id$
 %0A */
@@ -311,17 +311,16 @@
 PSampler
- 
 %0A%7B%0A%09publ
@@ -376,17 +376,16 @@
 _data%22;%0A
-%09
 %0A%09public
@@ -450,17 +450,16 @@
 ta);%0A%09%7D%0A
-%09
 %0A%09public
@@ -527,16 +527,646 @@
 );%0A%09%7D%0A%0A%09
+/****************************************%0A%09 * Set the HTTP request headers in preparation to open the connection%0A%09 * and sending the POST data:%0A%09 *%0A%09 *@param connection       %3Ccode%3EURLConnection%3C/code%3E to set headers on%0A%09 *@exception IOException  if an I/O exception occurs%0A%09 ***************************************/%0A%09public void setHeaders(URLConnection connection)%0A%09  %09%09throws IOException%0A%09%7B%0A%09%09((HttpURLConnection)connection).setRequestMethod(%22POST%22);%0A%09%09connection.setRequestProperty(%22Content-length%22, %22%22 + getXmlData().length());%0A%09%09connection.setRequestProperty(%22Content-type%22, %22text/xml%22);%0A%09%09connection.setDoOutput(true);%0A%09%7D%0A%0A
 %09/******
@@ -1609,240 +1609,8 @@
 %0A%09%7B%0A
-%09%09((HttpURLConnection)connection).setRequestMethod(%22POST%22);%0A%09%09connection.setRequestProperty(%22Content-length%22, %22%22 + getXmlData().length());%0A%09%09connection.setRequestProperty(%22Content-type%22, %22text/xml%22);%0A%09%09connection.setDoOutput(true);%0A
 %09%09Pr
@@ -1719,8 +1719,9 @@
 );%0A%09%7D%0A%7D%0A
+%0A

fix for bug 14145 - thank you jordi