vmassol 01/10/20 06:22:11
Modified: docs/framework/xdocs changes.xml
src/framework/share/org/apache/cactus WebRequest.java
src/framework/share/org/apache/cactus/client
HttpClientHelper.java
src/sample/share/org/apache/cactus/sample/unit
TestServletTestCase2.java
Log:
added new method: WebRequest.setContentType(String) to specify the content type
(defaults to "application/x-www-form-urlencoded").
Revision Changes Path
1.58 +8 -0 jakarta-cactus/docs/framework/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/docs/framework/xdocs/changes.xml,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- changes.xml 2001/10/20 11:12:58 1.57
+++ changes.xml 2001/10/20 13:22:11 1.58
@@ -119,6 +119,14 @@
<release version="1.3 in CVS">
<action dev="VMA" type="add">
+ Added a new method : <code>WebRequest.setContentType(String)</code>
+ (if you don't specify anything it default to
+ "application/x-www-form-urlencoded"). This will set the
+ content type HTTP header for the request. You can get this value from
+ your server code by calling
+ <code>HttpServletRequest.getContentType()</code>.
+ </action>
+ <action dev="VMA" type="add">
Added new method : <code>WebRequest.setUserData(InputStream)</code> to
allow sending arbitrary data in the request body. Note that calling this
method will invalidate any parameters that were set to be sent in the
1.8 +25 -2
jakarta-cactus/src/framework/share/org/apache/cactus/WebRequest.java
Index: WebRequest.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/WebRequest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- WebRequest.java 2001/10/20 11:12:58 1.7
+++ WebRequest.java 2001/10/20 13:22:11 1.8
@@ -82,7 +82,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: WebRequest.java,v 1.7 2001/10/20 11:12:58 vmassol Exp $
+ * @version $Id: WebRequest.java,v 1.8 2001/10/20 13:22:11 vmassol Exp $
*/
public class WebRequest
{
@@ -132,6 +132,29 @@
private InputStream dataStream;
/**
+ * The content type to set in the http request
+ */
+ private String contentType = "application/x-www-form-urlencoded";
+
+ /**
+ * Sets the content type that will be set in the http request
+ *
+ * @param theContentType the content type
+ */
+ public void setContentType(String theContentType)
+ {
+ this.contentType = theContentType;
+ }
+
+ /**
+ * @return the content type that will be set in the http request
+ */
+ public String getContentType()
+ {
+ return this.contentType;
+ }
+
+ /**
* Allow the user to send arbitrary data in the request body
*
* @param theDataStream the stream on which the data are put by the user
@@ -566,7 +589,7 @@
addParameter(nameValue.substring(0, breakParam),
nameValue.substring(breakParam+1));
} else {
- throw new RuntimeException("Bad QueryString [" +
+ throw new RuntimeException("Bad QueryString [" +
theQueryString + "] NameValue pair: [" + nameValue + "]");
}
}
1.14 +6 -2
jakarta-cactus/src/framework/share/org/apache/cactus/client/HttpClientHelper.java
Index: HttpClientHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/client/HttpClientHelper.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- HttpClientHelper.java 2001/10/20 11:12:58 1.13
+++ HttpClientHelper.java 2001/10/20 13:22:11 1.14
@@ -70,7 +70,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: HttpClientHelper.java,v 1.13 2001/10/20 11:12:58 vmassol Exp $
+ * @version $Id: HttpClientHelper.java,v 1.14 2001/10/20 13:22:11 vmassol Exp $
*/
public class HttpClientHelper
{
@@ -142,6 +142,10 @@
connection.setUseCaches(false);
+ // Sets the content type
+ connection.setRequestProperty("Content-type",
+ theRequest.getContentType());
+
// Add the other header fields
addHeaders(theRequest, connection);
@@ -363,7 +367,7 @@
Header cookieHeader =
org.apache.commons.httpclient.Cookie.createCookieHeader(
HttpClientHelper.getDomain(theRequest, theConnection),
- HttpClientHelper.getPath(theRequest, theConnection),
+ HttpClientHelper.getPath(theRequest, theConnection),
httpclientCookies);
logger.debug("Cookie string = [" + cookieHeader.getValue() +
1.20 +6 -3
jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/TestServletTestCase2.java
Index: TestServletTestCase2.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/TestServletTestCase2.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- TestServletTestCase2.java 2001/10/20 11:12:58 1.19
+++ TestServletTestCase2.java 2001/10/20 13:22:11 1.20
@@ -77,7 +77,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: TestServletTestCase2.java,v 1.19 2001/10/20 11:12:58 vmassol Exp $
+ * @version $Id: TestServletTestCase2.java,v 1.20 2001/10/20 13:22:11 vmassol Exp $
*/
public class TestServletTestCase2 extends ServletTestCase
{
@@ -632,9 +632,10 @@
public void beginSendUserData(WebRequest theRequest)
{
ByteArrayInputStream bais = new ByteArrayInputStream(
- "some data to send in the body".getBytes());
+ "<data>some data to send in the body</data>".getBytes());
theRequest.setUserData(bais);
+ theRequest.setContentType("text/xml");
}
/**
@@ -650,7 +651,9 @@
body.append(buffer);
}
- assertEquals("some data to send in the body", body.toString());
+ assertEquals("<data>some data to send in the body</data>",
+ body.toString());
+ assertEquals("text/xml", request.getContentType());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]