woolfel 2004/01/23 18:13:57
Modified: src/protocol/http/org/apache/jmeter/protocol/http/sampler
WebServiceSampler.java
Log:
this fixes bug 25741
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25741
dealing with encoding issues. the sampler now treats files differently
than messages pasted into the text area. if external files are used,
document builder uses input stream to create the document; otherwise
it uses the string content.
peter lin
Revision Changes Path
1.11 +58 -39
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/WebServiceSampler.java
Index: WebServiceSampler.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/WebServiceSampler.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- WebServiceSampler.java 15 Jan 2004 03:51:52 -0000 1.10
+++ WebServiceSampler.java 24 Jan 2004 02:13:57 -0000 1.11
@@ -56,11 +56,13 @@
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Random;
+import org.xml.sax.*;
import org.apache.jorphan.io.TextFile;
@@ -76,7 +78,6 @@
import org.apache.soap.transport.http.SOAPHTTPConnection;
import javax.xml.parsers.*;
import org.w3c.dom.Document;
-import org.xml.sax.*;
/**
* Sampler to handle Web Service requests. It uses Apache SOAP drivers to
@@ -145,6 +146,8 @@
*/
protected static DocumentBuilder XDB = null;
+ protected String FILE_CONTENTS = null;
+
/**
* Set the path where XML messages are stored for random selection.
*/
@@ -192,18 +195,19 @@
* run efficiently.
* @return String contents of the file
*/
- private String retrieveRuntimeXmlData()
+ private File retrieveRuntimeXmlData()
{
String file = getRandomFileName();
if (file.length() > 0)
{
- TextFile contents = new TextFile(file);
- if (contents.exists())
- {
- return contents.getText();
- }
+ if (this.getReadResponse()){
+ TextFile tfile = new TextFile(file);
+ FILE_CONTENTS = tfile.getText();
+ }
+ return new File(file);
+ } else {
+ return null;
}
- return getXmlData();
}
/**
@@ -425,33 +429,39 @@
*/
protected Document openDocument(String key)
{
- String xmlData = retrieveRuntimeXmlData();
- if (xmlData != null && xmlData.length() > 0)
- {
- Document doc = null;
- try
- {
- if (XDB == null)
- {
- XDB = XMLParserUtils.getXMLDocBuilder();
- }
- doc = XDB.parse(new InputSource(new StringReader(xmlData)));
- // cache the document
- if (this.getPropertyAsBoolean(MEMORY_CACHE))
- {
- DOMPool.putDocument(key, doc);
- }
- }
- catch (Exception ex)
- {
- // ex.printStackTrace();
- }
- return doc;
- }
- else
- {
- return null;
- }
+ if (XDB == null)
+ {
+ XDB = XMLParserUtils.getXMLDocBuilder();
+ }
+ Document doc = null;
+ // if either a file or path location is given,
+ // get the file object.
+ if (getXmlFile().length() > 0 || getXmlPathLoc().length() > 0){
+ try {
+ doc = XDB.parse(new
FileInputStream(retrieveRuntimeXmlData()));
+ } catch (Exception e){
+ // there should be a file, if not fail silently
+ }
+ } else {
+ FILE_CONTENTS = getXmlData();
+ if (FILE_CONTENTS != null && FILE_CONTENTS.length() > 0)
+ {
+ try
+ {
+ doc = XDB.parse(
+ new InputSource(new
StringReader(FILE_CONTENTS)));
+ }
+ catch (Exception ex)
+ {
+ // ex.printStackTrace();
+ }
+ }
+ }
+ if (this.getPropertyAsBoolean(MEMORY_CACHE))
+ {
+ DOMPool.putDocument(key, doc);
+ }
+ return doc;
}
/**
@@ -487,8 +497,9 @@
{
try
{
- Envelope msgEnv = Envelope.unmarshall(createDocument());
-
+ org.w3c.dom.Element rdoc = createDocument();
+ Envelope msgEnv = Envelope.unmarshall(rdoc);
+
// send the message
Message msg = new Message();
RESULT.sampleStart();
@@ -546,12 +557,20 @@
.getBytes());
}
RESULT.setSuccessful(true);
+ // 1-22-04 updated the sampler so that when read
+ // response is set, it also sets SamplerData with
+ // the XML message, so users can see what was
+ // sent. if read response is not checked, it will
+ // not set sampler data with the request message.
+ // peter lin.
RESULT.setSamplerData(
getUrl().getProtocol()
+ "://"
+ getUrl().getHost()
+ "/"
- + getUrl().getFile());
+ + getUrl().getFile()
+ + "\n"
+ + FILE_CONTENTS);
RESULT.setDataEncoding(
st.getResponseSOAPContext().getContentType());
// setting this is just a formality, since
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]